WordPress.org

Make WordPress Core

Ticket #19871: 19871.diff

File 19871.diff, 2.0 KB (added by duck_, 2 years ago)
  • wp-includes/rewrite.php

     
    2424/** 
    2525 * Add a new tag (like %postname%). 
    2626 * 
    27  * Warning: you must call this on init or earlier, otherwise the query var 
    28  * addition stuff won't work. 
     27 * The $query parameter is optional. If it is omitted you must ensure that 
     28 * you call this on, or before, the 'init' hook. This is because $query defaults 
     29 * to "$tagname=", and for this to work a new query var has to be added. 
    2930 * 
     31 * @see WP_Rewrite::add_rewrite_tag() 
    3032 * @since 2.1.0 
    3133 * 
    32  * @param string $tagname 
    33  * @param string $regex 
     34 * @param string $tagname Name of the new rewrite tag. 
     35 * @param string $regex Regular expression to substitute the tag for in rewrite rules. 
     36 * @param string $query String to append to the rewritten query. Must end in '='. Optional. 
    3437 */ 
    35 function add_rewrite_tag($tagname, $regex) { 
    36         //validation 
     38function add_rewrite_tag( $tagname, $regex, $query = '' ) { 
     39        // validate the tagname 
    3740        if ( strlen($tagname) < 3 || $tagname[0] != '%' || $tagname[strlen($tagname)-1] != '%' ) 
    3841                return; 
    3942 
    40         $qv = trim($tagname, '%'); 
     43        global $wp_rewrite, $wp; 
    4144 
    42         global $wp_rewrite, $wp; 
    43         $wp->add_query_var($qv); 
    44         $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '='); 
     45        if ( empty( $query ) ) { 
     46                $qv = trim( $tagname, '%' ); 
     47                $wp->add_query_var( $qv ); 
     48                $query = $qv . '='; 
     49        } 
     50 
     51        $wp_rewrite->add_rewrite_tag( $tagname, $regex, $query ); 
    4552} 
    4653 
    4754/** 
     
    11371144        } 
    11381145 
    11391146        /** 
    1140          * Append or update tag, pattern, and query for replacement. 
     1147         * Add or update existing rewrite tags (e.g. %postname%). 
    11411148         * 
    11421149         * If the tag already exists, replace the existing pattern and query for 
    11431150         * that tag, otherwise add the new tag, pattern, and query to the end of the 
    11441151         * arrays. 
    11451152         * 
    1146          * @internal What is the purpose of this function again? Need to finish long 
    1147          *           description. 
    1148          * 
    11491153         * @since 1.5.0 
    11501154         * @access public 
    11511155         *