Fix Games admin filter links
This commit is contained in:
@@ -75,15 +75,27 @@ function custom_event_rewrite_flush() {
|
|||||||
register_activation_hook(__FILE__, 'custom_event_rewrite_flush');
|
register_activation_hook(__FILE__, 'custom_event_rewrite_flush');
|
||||||
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
|
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
|
||||||
|
|
||||||
// Modify the query to handle custom permalinks and include future posts
|
// Modify the front-end single event query to allow scheduled events to resolve.
|
||||||
function custom_event_parse_request($query) {
|
function custom_event_parse_request( $query ) {
|
||||||
$post_type = sp_array_value( $query->query, 'post_type', null );
|
if ( ! $query instanceof WP_Query ) {
|
||||||
if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] === 'sp_event') {
|
return;
|
||||||
if (isset($query->query_vars['p'])) {
|
}
|
||||||
$query->set('post_type', 'sp_event');
|
|
||||||
$query->set('p', $query->query_vars['p']);
|
if ( is_admin() || ! $query->is_main_query() ) {
|
||||||
$query->set('post_status', array('publish', 'future'));
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if ( 'sp_event' !== $query->get( 'post_type' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_id = absint( $query->get( 'p' ) );
|
||||||
|
if ( $post_id <= 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->set( 'post_type', 'sp_event' );
|
||||||
|
$query->set( 'p', $post_id );
|
||||||
|
$query->set( 'post_status', array( 'publish', 'future' ) );
|
||||||
}
|
}
|
||||||
add_action('pre_get_posts', 'custom_event_parse_request');
|
add_action('pre_get_posts', 'custom_event_parse_request');
|
||||||
|
|||||||
81
tests/test-sp-event-permalink.php
Normal file
81
tests/test-sp-event-permalink.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tests for custom event permalink query behavior.
|
||||||
|
*
|
||||||
|
* @package Tonys_Sportspress_Enhancements
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event permalink query tests.
|
||||||
|
*/
|
||||||
|
class Test_SP_Event_Permalink extends WP_UnitTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preserve global main query references for each test.
|
||||||
|
*
|
||||||
|
* @var WP_Query
|
||||||
|
*/
|
||||||
|
private $original_wp_query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preserve global main query references for each test.
|
||||||
|
*
|
||||||
|
* @var WP_Query
|
||||||
|
*/
|
||||||
|
private $original_wp_the_query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up test case state.
|
||||||
|
*/
|
||||||
|
public function set_up(): void {
|
||||||
|
parent::set_up();
|
||||||
|
$this->original_wp_query = $GLOBALS['wp_query'];
|
||||||
|
$this->original_wp_the_query = $GLOBALS['wp_the_query'];
|
||||||
|
set_current_screen( 'front' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore global query references.
|
||||||
|
*/
|
||||||
|
public function tear_down(): void {
|
||||||
|
$GLOBALS['wp_query'] = $this->original_wp_query;
|
||||||
|
$GLOBALS['wp_the_query'] = $this->original_wp_the_query;
|
||||||
|
set_current_screen( 'front' );
|
||||||
|
parent::tear_down();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The admin event list query should not be altered by permalink handling.
|
||||||
|
*/
|
||||||
|
public function test_admin_event_queries_are_not_modified() {
|
||||||
|
set_current_screen( 'edit-sp_event' );
|
||||||
|
|
||||||
|
$query = new WP_Query();
|
||||||
|
$query->set( 'post_type', 'sp_event' );
|
||||||
|
$query->set( 'p', 123 );
|
||||||
|
$query->set( 'post_status', 'future' );
|
||||||
|
|
||||||
|
custom_event_parse_request( $query );
|
||||||
|
|
||||||
|
$this->assertSame( 'future', $query->get( 'post_status' ) );
|
||||||
|
$this->assertSame( 123, $query->get( 'p' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end single event requests should include future posts.
|
||||||
|
*/
|
||||||
|
public function test_frontend_single_event_queries_include_future_posts() {
|
||||||
|
$query = new WP_Query();
|
||||||
|
$query->set( 'post_type', 'sp_event' );
|
||||||
|
$query->set( 'p', 456 );
|
||||||
|
|
||||||
|
$GLOBALS['wp_query'] = $query;
|
||||||
|
$GLOBALS['wp_the_query'] = $query;
|
||||||
|
|
||||||
|
custom_event_parse_request( $query );
|
||||||
|
|
||||||
|
$this->assertSame( 'sp_event', $query->get( 'post_type' ) );
|
||||||
|
$this->assertSame( 456, $query->get( 'p' ) );
|
||||||
|
$this->assertSame( array( 'publish', 'future' ), $query->get( 'post_status' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user