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

git-svn-id: http://svn.automattic.com/wordpress/trunk@5769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-06-27 21:39:50 +00:00
parent 0e2d9ff004
commit c1adb3c7ad
1 changed files with 11 additions and 6 deletions

View File

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