Allow rules to be added to the top of the rule stack.

git-svn-id: https://develop.svn.wordpress.org/trunk@5769 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-06-27 21:39:50 +00:00
parent bf00906f7a
commit aa85dfe187
1 changed files with 11 additions and 6 deletions

View File

@ -4,7 +4,7 @@
*******************************************************************************/
//Add a straight rewrite rule
function add_rewrite_rule($regex, $redirect) {
function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
global $wp_rewrite;
$wp_rewrite->add_rule($regex, $redirect);
}
@ -171,8 +171,9 @@ class WP_Rewrite {
var $index = 'index.php';
var $matches = '';
var $rules;
var $extra_rules; //those not generated by the class, see add_rewrite_rule()
var $non_wp_rules; //rules that don't redirect to WP's index.php
var $extra_rules = array(); //those not generated by the class, see add_rewrite_rule()
var $extra_rules_top = array(); //those not generated by the class, see add_rewrite_rule()
var $non_wp_rules = array(); //rules that don't redirect to WP's index.php
var $endpoints;
var $use_verbose_rules = false;
var $rewritecode =
@ -775,7 +776,7 @@ class WP_Rewrite {
$page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
// Put them together.
$this->rules = array_merge($robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
do_action_ref_array('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules);
@ -862,14 +863,18 @@ class WP_Rewrite {
}
//Add a straight rewrite rule
function add_rule($regex, $redirect) {
function add_rule($regex, $redirect, $after = 'bottom') {
//get everything up to the first ?
$index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
$front = substr($redirect, 0, $index);
if ($front != $this->index) { //it doesn't redirect to WP's index.php
$this->add_external_rule($regex, $redirect);
} else {
$this->extra_rules[$regex] = $redirect;
if ( 'bottom' == $after)
$this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect));
else
$this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect));
//$this->extra_rules[$regex] = $redirect;
}
}