Rewrite: Add a `remove_rewrite_tag()` helper function.

It can be used to properly remove registered rewrite tags. Adds unit tests.

Fixes #35236.
Built from https://develop.svn.wordpress.org/trunk@36217


git-svn-id: http://core.svn.wordpress.org/trunk@36184 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2016-01-07 09:39:27 +00:00
parent 668818e93d
commit f079f57357
3 changed files with 37 additions and 1 deletions

View File

@ -841,6 +841,28 @@ class WP_Rewrite {
} }
} }
/**
* Removes an existing rewrite tag.
*
* @since 4.5.0
* @access public
*
* @see WP_Rewrite::$rewritecode
* @see WP_Rewrite::$rewritereplace
* @see WP_Rewrite::$queryreplace
*
* @param string $tag Name of the rewrite tag to remove.
*/
public function remove_rewrite_tag( $tag ) {
$position = array_search( $tag, $this->rewritecode );
if ( false !== $position && null !== $position ) {
unset( $this->rewritecode[ $position ] );
unset( $this->rewritereplace[ $position ] );
unset( $this->queryreplace[ $position ] );
}
}
/** /**
* Generates rewrite rules from a permalink structure. * Generates rewrite rules from a permalink structure.
* *

View File

@ -172,6 +172,20 @@ function add_rewrite_tag( $tag, $regex, $query = '' ) {
$wp_rewrite->add_rewrite_tag( $tag, $regex, $query ); $wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
} }
/**
* Removes an existing rewrite tag (like %postname%).
*
* @since 4.5.0
*
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @param string $tag Name of the rewrite tag.
*/
function remove_rewrite_tag( $tag ) {
global $wp_rewrite;
$wp_rewrite->remove_rewrite_tag( $tag );
}
/** /**
* Add permalink structure. * Add permalink structure.
* *

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.5-alpha-36216'; $wp_version = '4.5-alpha-36217';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.