summaryrefslogtreecommitdiffstats
path: root/wp-includes/rewrite.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/rewrite.php')
-rw-r--r--wp-includes/rewrite.php67
1 files changed, 55 insertions, 12 deletions
diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php
index 19d5224..bd5daf0 100644
--- a/wp-includes/rewrite.php
+++ b/wp-includes/rewrite.php
@@ -4,9 +4,9 @@
*******************************************************************************/
//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);
+ $wp_rewrite->add_rule($regex, $redirect, $after);
}
//Add a new tag (like %postname%)
@@ -46,11 +46,12 @@ define('EP_ROOT', 64 );
define('EP_COMMENTS', 128 );
define('EP_SEARCH', 256 );
define('EP_CATEGORIES', 512 );
-define('EP_AUTHORS', 1024);
-define('EP_PAGES', 2048);
+define('EP_TAGS', 1024 );
+define('EP_AUTHORS', 2048);
+define('EP_PAGES', 4096);
//pseudo-places
define('EP_NONE', 0 );
-define('EP_ALL', 4095);
+define('EP_ALL', 8191);
//and an endpoint, like /trackback/
function add_rewrite_endpoint($name, $places) {
@@ -62,7 +63,7 @@ function add_rewrite_endpoint($name, $places) {
// determine the post ID it represents.
function url_to_postid($url) {
global $wp_rewrite;
-
+
$url = apply_filters('url_to_postid', $url);
// First, check to see if there is a 'p=N' or 'page_id=N' to match against
@@ -161,7 +162,9 @@ class WP_Rewrite {
var $permalink_structure;
var $use_trailing_slashes;
var $category_base;
+ var $tag_base;
var $category_structure;
+ var $tag_structure;
var $author_base = 'author';
var $author_structure;
var $date_structure;
@@ -177,8 +180,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 =
@@ -192,6 +196,7 @@ class WP_Rewrite {
'%postname%',
'%post_id%',
'%category%',
+ '%tag%',
'%author%',
'%pagename%',
'%search%'
@@ -208,6 +213,7 @@ class WP_Rewrite {
'([^/]+)',
'([0-9]+)',
'(.+?)',
+ '(.+?)',
'([^/]+)',
'([^/]+)',
'(.+)'
@@ -224,6 +230,7 @@ class WP_Rewrite {
'name=',
'p=',
'category_name=',
+ 'tag=',
'author_name=',
'pagename=',
's='
@@ -389,6 +396,26 @@ class WP_Rewrite {
return $this->category_structure;
}
+ function get_tag_permastruct() {
+ if (isset($this->tag_structure)) {
+ return $this->tag_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->tag_structure = '';
+ return false;
+ }
+
+ if (empty($this->tag_base))
+ $this->tag_structure = $this->front . 'tag/';
+ else
+ $this->tag_structure = $this->tag_base . '/';
+
+ $this->tag_structure .= '%tag%';
+
+ return $this->tag_structure;
+ }
+
function get_author_permastruct() {
if (isset($this->author_structure)) {
return $this->author_structure;
@@ -745,6 +772,10 @@ class WP_Rewrite {
$category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
$category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
+ // Tags
+ $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
+ $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
+
// Authors
$author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
$author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
@@ -754,7 +785,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, $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);
@@ -841,14 +872,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;
}
}
@@ -880,7 +915,8 @@ class WP_Rewrite {
if ($this->using_index_permalinks()) {
$this->root = $this->index . '/';
}
- $this->category_base = get_option('category_base');
+ $this->category_base = get_option( 'category_base' );
+ $this->tag_base = get_option( 'tag_base' );
unset($this->category_structure);
unset($this->author_structure);
unset($this->date_structure);
@@ -905,6 +941,13 @@ class WP_Rewrite {
}
}
+ function set_tag_base( $tag_base ) {
+ if ( $tag_base != $this->tag_base ) {
+ update_option( 'tag_base', $tag_base );
+ $this->init();
+ }
+ }
+
function WP_Rewrite() {
$this->init();
}