Add the $query parameter to add_rewrite_tag() so that it matches WP_Rewrite::add_rewrite_tag(). Fixes #19871.

Also rename some other parameters so that they all match.


git-svn-id: http://svn.automattic.com/wordpress/trunk@19756 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
duck_ 2012-01-25 22:48:24 +00:00
parent 853fa27b53
commit e05c96316f
1 changed files with 32 additions and 26 deletions

View File

@ -22,26 +22,33 @@ function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
} }
/** /**
* Add a new tag (like %postname%). * Add a new rewrite tag (like %postname%).
* *
* Warning: you must call this on init or earlier, otherwise the query var * The $query parameter is optional. If it is omitted you must ensure that
* addition stuff won't work. * you call this on, or before, the 'init' hook. This is because $query defaults
* to "$tag=", and for this to work a new query var has to be added.
* *
* @see WP_Rewrite::add_rewrite_tag()
* @since 2.1.0 * @since 2.1.0
* *
* @param string $tagname * @param string $tag Name of the new rewrite tag.
* @param string $regex * @param string $regex Regular expression to substitute the tag for in rewrite rules.
* @param string $query String to append to the rewritten query. Must end in '='. Optional.
*/ */
function add_rewrite_tag($tagname, $regex) { function add_rewrite_tag( $tag, $regex, $query = '' ) {
//validation // validate the tag's name
if ( strlen($tagname) < 3 || $tagname[0] != '%' || $tagname[strlen($tagname)-1] != '%' ) if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' )
return; return;
$qv = trim($tagname, '%');
global $wp_rewrite, $wp; global $wp_rewrite, $wp;
$wp->add_query_var($qv);
$wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '='); if ( empty( $query ) ) {
$qv = trim( $tag, '%' );
$wp->add_query_var( $qv );
$query = $qv . '=';
}
$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
} }
/** /**
@ -1169,30 +1176,29 @@ class WP_Rewrite {
} }
/** /**
* Append or update tag, pattern, and query for replacement. * Add or update existing rewrite tags (e.g. %postname%).
* *
* If the tag already exists, replace the existing pattern and query for * If the tag already exists, replace the existing pattern and query for
* that tag, otherwise add the new tag, pattern, and query to the end of the * that tag, otherwise add the new tag.
* arrays.
*
* @internal What is the purpose of this function again? Need to finish long
* description.
* *
* @see WP_Rewrite::$rewritecode
* @see WP_Rewrite::$rewritereplace
* @see WP_Rewrite::$queryreplace
* @since 1.5.0 * @since 1.5.0
* @access public * @access public
* *
* @param string $tag Append tag to rewritecode property array. * @param string $tag Name of the rewrite tag to add or update.
* @param string $pattern Append pattern to rewritereplace property array. * @param string $regex Regular expression to substitute the tag for in rewrite rules.
* @param string $query Append query to queryreplace property array. * @param string $query String to append to the rewritten query. Must end in '='.
*/ */
function add_rewrite_tag($tag, $pattern, $query) { function add_rewrite_tag( $tag, $regex, $query ) {
$position = array_search($tag, $this->rewritecode); $position = array_search( $tag, $this->rewritecode );
if ( false !== $position && null !== $position ) { if ( false !== $position && null !== $position ) {
$this->rewritereplace[$position] = $pattern; $this->rewritereplace[ $position ] = $regex;
$this->queryreplace[$position] = $query; $this->queryreplace[ $position ] = $query;
} else { } else {
$this->rewritecode[] = $tag; $this->rewritecode[] = $tag;
$this->rewritereplace[] = $pattern; $this->rewritereplace[] = $regex;
$this->queryreplace[] = $query; $this->queryreplace[] = $query;
} }
} }