Ticket #25143: 25143.5.patch
File 25143.5.patch, 5.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/rewrite.php
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php index 45d28ce..9dea791 100644
define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEAR 246 246 * @see WP_Rewrite::add_endpoint() 247 247 * @global object $wp_rewrite 248 248 * 249 * @param string $name Name of the endpoint. 250 * @param int $places Endpoint mask describing the places the endpoint should be added. 251 * @param string $query_var Name of the corresponding query variable. Defaults to $name. 249 * @param string $name Name of the endpoint. 250 * @param int $places Endpoint mask describing the places the endpoint should be added. 251 * @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var 252 * for this endpoint. Defaults to the value of `$name`. 252 253 */ 253 function add_rewrite_endpoint( $name, $places, $query_var = null) {254 function add_rewrite_endpoint( $name, $places, $query_var = true ) { 254 255 global $wp_rewrite; 255 256 $wp_rewrite->add_endpoint( $name, $places, $query_var ); 256 257 } … … class WP_Rewrite { 1964 1965 * @see add_rewrite_endpoint() for full documentation. 1965 1966 * @uses WP::add_query_var() 1966 1967 * 1967 * @param string $name Name of the endpoint. 1968 * @param int $places Endpoint mask describing the places the endpoint should be added. 1969 * @param string $query_var Name of the corresponding query variable. Default is value of $name. 1968 * @param string $name Name of the endpoint. 1969 * @param int $places Endpoint mask describing the places the endpoint should be added. 1970 * @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering 1971 * a query_var for this endpoint. Defaults to the value of `$name`. 1970 1972 */ 1971 public function add_endpoint( $name, $places, $query_var = null) {1973 public function add_endpoint( $name, $places, $query_var = true ) { 1972 1974 global $wp; 1973 if ( null === $query_var ) { 1975 1976 // For backward compatibility, if `null` has explicitly been passed as `$query_var`, assume `true`. 1977 if ( true === $query_var || null === func_get_arg( 2 ) ) { 1974 1978 $query_var = $name; 1975 1979 } 1976 1980 $this->endpoints[] = array( $places, $name, $query_var ); 1977 $wp->add_query_var( $query_var ); 1981 1982 if ( $query_var ) { 1983 $wp->add_query_var( $query_var ); 1984 } 1978 1985 } 1979 1986 1980 1987 /** -
tests/phpunit/tests/rewrite.php
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php index 99aff86..0542e42 100644
class Tests_Rewrite extends WP_UnitTestCase { 121 121 122 122 restore_current_blog(); 123 123 } 124 125 /** 126 * @ticket 25143 127 */ 128 public function test_is_home_should_be_false_when_visiting_custom_endpoint_without_a_registered_query_var_and_page_on_front_is_set() { 129 130 $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 131 update_option( 'show_on_front', 'page' ); 132 update_option( 'page_on_front', $page_id ); 133 134 add_rewrite_endpoint( 'test', EP_ALL, false ); 135 flush_rewrite_rules(); 136 137 $this->go_to( home_url( '/test/1' ) ); 138 139 $this->assertQueryTrue( 'is_front_page', 'is_page', 'is_singular' ); 140 $this->assertFalse( is_home() ); 141 } 124 142 } -
new file tests/phpunit/tests/rewrite/addRewriteEndpoint.php
diff --git tests/phpunit/tests/rewrite/addRewriteEndpoint.php tests/phpunit/tests/rewrite/addRewriteEndpoint.php new file mode 100644 index 0000000..f083f05
- + 1 <?php 2 3 /** 4 * @group rewrite 5 * @ticket 25143 6 */ 7 class Tests_Rewrite_AddRewriteEndpoint extends WP_UnitTestCase { 8 private $qvs; 9 10 public function setUp() { 11 parent::setUp(); 12 $this->qvs = $GLOBALS['wp']->public_query_vars; 13 } 14 15 public function tearDown() { 16 $GLOBALS['wp']->public_query_vars = $this->qvs; 17 parent::tearDown(); 18 } 19 20 public function test_should_register_query_using_name_param_by_default() { 21 add_rewrite_endpoint( 'foo', EP_ALL ); 22 $this->assertContains( 'foo', $GLOBALS['wp']->public_query_vars ); 23 } 24 25 public function test_should_register_query_using_name_param_if_null_is_passed_as_query_var() { 26 add_rewrite_endpoint( 'foo', EP_ALL, null ); 27 $this->assertContains( 'foo', $GLOBALS['wp']->public_query_vars ); 28 } 29 30 public function test_should_register_query_using_query_var_param_if_not_null() { 31 add_rewrite_endpoint( 'foo', EP_ALL, 'bar' ); 32 $this->assertContains( 'bar', $GLOBALS['wp']->public_query_vars ); 33 } 34 35 /** 36 * @ticket 25143 37 */ 38 public function test_should_register_query_var_using_name_param_if_true_is_passed_as_query_var() { 39 add_rewrite_endpoint( 'foo', EP_ALL, true ); 40 $this->assertContains( 'foo', $GLOBALS['wp']->public_query_vars ); 41 } 42 43 /** 44 * @ticket 25143 45 */ 46 public function test_should_not_register_query_var_if_query_var_param_is_false() { 47 $qvs = $GLOBALS['wp']->public_query_vars; 48 add_rewrite_endpoint( 'foo', EP_ALL, false ); 49 $this->assertSame( $qvs, $GLOBALS['wp']->public_query_vars ); 50 } 51 }