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:
parent
0e2d9ff004
commit
c1adb3c7ad
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue