Ticket #35236: 35236.diff
File 35236.diff, 3.5 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-rewrite.php
diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php index 035bbc3..b1fcf0f 100644
class WP_Rewrite { 841 841 } 842 842 } 843 843 844 845 /** 846 * Removes an existing rewrite tag. 847 * 848 * @since 4.5.0 849 * @access public 850 * 851 * @see WP_Rewrite::$rewritecode 852 * @see WP_Rewrite::$rewritereplace 853 * @see WP_Rewrite::$queryreplace 854 * 855 * @param string $tag Name of the rewrite tag to remove. 856 */ 857 public function remove_rewrite_tag( $tag ) { 858 $position = array_search( $tag, $this->rewritecode ); 859 if ( false !== $position && null !== $position ) { 860 unset( $this->rewritecode[ $position ] ); 861 unset( $this->rewritereplace[ $position ] ); 862 unset( $this->queryreplace[ $position ] ); 863 } 864 } 865 844 866 /** 845 867 * Generates rewrite rules from a permalink structure. 846 868 * -
src/wp-includes/rewrite.php
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php index 7f3b2ed..4c0cb00 100644
function add_rewrite_tag( $tag, $regex, $query = '' ) { 173 173 } 174 174 175 175 /** 176 * Removes an existing rewrite tag (like %postname%). 177 * 178 * @since 4.5.0 179 * 180 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 181 * 182 * @param string $tag Name of the rewrite tag. 183 */ 184 function remove_rewrite_tag( $tag ) { 185 global $wp_rewrite; 186 $wp_rewrite->remove_rewrite_tag( $tag ); 187 } 188 189 /** 176 190 * Add permalink structure. 177 191 * 178 192 * @since 3.0.0 -
new file tests/phpunit/tests/rewrite/rewriteTags.php
diff --git tests/phpunit/tests/rewrite/rewriteTags.php tests/phpunit/tests/rewrite/rewriteTags.php new file mode 100644 index 0000000..400045a
- + 1 <?php 2 3 /** 4 * @group rewrite 5 */ 6 class Tests_Rewrite_Tags extends WP_UnitTestCase { 7 public function _invalid_rewrite_tags() { 8 return array( 9 array( 'foo', 'bar' ), 10 array( '%', 'bar' ), 11 array( '%a', 'bar' ), 12 array( 'a%', 'bar' ), 13 array( '%%', 'bar' ), 14 array( '', 'bar' ), 15 ); 16 } 17 18 /** 19 * @dataProvider _invalid_rewrite_tags 20 */ 21 public function test_add_rewrite_tag_invalid( $tag, $regex ) { 22 global $wp_rewrite; 23 24 add_rewrite_tag( $tag, $regex ); 25 $this->assertNotSame( $tag, array_pop( $wp_rewrite->rewritecode ) ); 26 } 27 28 public function test_add_rewrite_tag_empty_query() { 29 global $wp_rewrite; 30 31 add_rewrite_tag( '%foo%', 'bar' ); 32 $this->assertSame( '%foo%', array_pop( $wp_rewrite->rewritecode ) ); 33 $this->assertSame( 'bar', array_pop( $wp_rewrite->rewritereplace ) ); 34 $this->assertSame( 'foo=', array_pop( $wp_rewrite->queryreplace ) ); 35 } 36 37 public function test_add_rewrite_tag_custom_query() { 38 global $wp_rewrite; 39 40 add_rewrite_tag( '%foo%', 'bar', 'baz=' ); 41 $this->assertSame( '%foo%', array_pop( $wp_rewrite->rewritecode ) ); 42 $this->assertSame( 'bar', array_pop( $wp_rewrite->rewritereplace ) ); 43 $this->assertSame( 'baz=', array_pop( $wp_rewrite->queryreplace ) ); 44 } 45 46 public function test_remove_rewrite_tag() { 47 global $wp_rewrite; 48 49 add_rewrite_tag( '%foo%', 'bar', 'baz=' ); 50 $this->assertSame( '%foo%', array_pop( $wp_rewrite->rewritecode ) ); 51 $this->assertSame( 'bar', array_pop( $wp_rewrite->rewritereplace ) ); 52 $this->assertSame( 'baz=', array_pop( $wp_rewrite->queryreplace ) ); 53 54 remove_rewrite_tag( '%foo%' ); 55 $this->assertNotSame( '%foo%', array_pop( $wp_rewrite->rewritecode ) ); 56 $this->assertNotSame( 'bar', array_pop( $wp_rewrite->rewritereplace ) ); 57 $this->assertNotSame( 'baz=', array_pop( $wp_rewrite->queryreplace ) ); 58 } 59 }