Ticket #19871: 19871.2.diff
File 19871.2.diff, 3.2 KB (added by , 13 years ago) |
---|
-
wp-includes/rewrite.php
22 22 } 23 23 24 24 /** 25 * Add a new tag (like %postname%).25 * Add a new rewrite tag (like %postname%). 26 26 * 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 "$tag=", and for this to work a new query var has to be added. 29 30 * 31 * @see WP_Rewrite::add_rewrite_tag() 30 32 * @since 2.1.0 31 33 * 32 * @param string $tagname 33 * @param string $regex 34 * @param string $tag 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. 34 37 */ 35 function add_rewrite_tag( $tagname, $regex) {36 // validation37 if ( strlen( $tagname) < 3 || $tagname[0] != '%' || $tagname[strlen($tagname)-1] != '%' )38 function add_rewrite_tag( $tag, $regex, $query = '' ) { 39 // validate the tag's name 40 if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) 38 41 return; 39 42 40 $qv = trim($tagname, '%');43 global $wp_rewrite, $wp; 41 44 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( $tag, '%' ); 47 $wp->add_query_var( $qv ); 48 $query = $qv . '='; 49 } 50 51 $wp_rewrite->add_rewrite_tag( $tag, $regex, $query ); 45 52 } 46 53 47 54 /** … … 1137 1141 } 1138 1142 1139 1143 /** 1140 * A ppend or update tag, pattern, and query for replacement.1144 * Add or update existing rewrite tags (e.g. %postname%). 1141 1145 * 1142 1146 * If the tag already exists, replace the existing pattern and query for 1143 1147 * that tag, otherwise add the new tag, pattern, and query to the end of the 1144 1148 * arrays. 1145 1149 * 1146 * @internal What is the purpose of this function again? Need to finish long1147 * description.1148 *1149 1150 * @since 1.5.0 1150 1151 * @access public 1151 1152 * 1152 * @param string $tag Append tag to rewritecode property array.1153 * @param string $ pattern Append pattern to rewritereplace property array.1154 * @param string $query Append query to queryreplace property array.1153 * @param string $tag Name of the rewrite tag to add or update. 1154 * @param string $regex Regular expression to substitute the tag for in rewrite rules. 1155 * @param string $query String to append to the rewritten query. Must end in '='. 1155 1156 */ 1156 function add_rewrite_tag( $tag, $pattern, $query) {1157 $position = array_search( $tag, $this->rewritecode);1157 function add_rewrite_tag( $tag, $regex, $query ) { 1158 $position = array_search( $tag, $this->rewritecode ); 1158 1159 if ( false !== $position && null !== $position ) { 1159 $this->rewritereplace[ $position] = $pattern;1160 $this->queryreplace[ $position] = $query;1160 $this->rewritereplace[ $position ] = $regex; 1161 $this->queryreplace[ $position ] = $query; 1161 1162 } else { 1162 1163 $this->rewritecode[] = $tag; 1163 $this->rewritereplace[] = $ pattern;1164 $this->rewritereplace[] = $regex; 1164 1165 $this->queryreplace[] = $query; 1165 1166 } 1166 1167 }