From f079f573576a60c0b8476a64d6cc2ca137fe166f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 7 Jan 2016 09:39:27 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-rewrite.php | 22 ++++++++++++++++++++++ wp-includes/rewrite.php | 14 ++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php index e6f768fed1..1107aa9d37 100644 --- a/wp-includes/class-wp-rewrite.php +++ b/wp-includes/class-wp-rewrite.php @@ -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. * diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index fe6b99adb7..c43abe8de9 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -172,6 +172,20 @@ function 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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index e4f293e578..314ddd6a86 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.