mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
Improve plugin hooks for rewrite manipulation. Allow pluggable template redirection.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
02f33a3426
commit
d352c9be64
@ -207,6 +207,8 @@ $wp_template_dir = get_template_directory();
|
||||
// Template redirection
|
||||
if ($pagenow == 'index.php') {
|
||||
if (! isset($wp_did_template_redirect)) {
|
||||
$wp_did_template_redirect = true;
|
||||
do_action('template_redirect', '');
|
||||
if (is_feed()) {
|
||||
$wp_did_template_redirect = true;
|
||||
include(dirname(__FILE__) . '/wp-feed.php');
|
||||
|
@ -704,9 +704,10 @@ class WP_Rewrite {
|
||||
var $category_structure;
|
||||
var $date_structure;
|
||||
var $front;
|
||||
var $prefix = '';
|
||||
var $root = '';
|
||||
var $index = 'index.php';
|
||||
var $matches = '';
|
||||
var $rules;
|
||||
var $rewritecode =
|
||||
array(
|
||||
'%year%',
|
||||
@ -876,7 +877,13 @@ class WP_Rewrite {
|
||||
return $this->category_structure;
|
||||
}
|
||||
|
||||
function generate_rewrite_rules($permalink_structure = '', $forcomments = false) {
|
||||
function add_rewrite_tag($tag, $pattern, $query) {
|
||||
$this->rewritecode[] = $tag;
|
||||
$this->rewritereplace[] = $pattern;
|
||||
$this->queryreplace[] = $query;
|
||||
}
|
||||
|
||||
function generate_rewrite_rules($permalink_structure = '', $page = true, $feed = true, $forcomments = false) {
|
||||
$feedregex2 = '(feed|rdf|rss|rss2|atom)/?$';
|
||||
$feedregex = 'feed/' . $feedregex2;
|
||||
|
||||
@ -933,7 +940,11 @@ class WP_Rewrite {
|
||||
$feedquery2 .= '&withcomments=1';
|
||||
}
|
||||
|
||||
$rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2, $pagematch => $pagequery);
|
||||
$rewrite = array();
|
||||
if ($feed)
|
||||
$rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
|
||||
if ($page)
|
||||
$rewrite = $rewrite + array($pagematch => $pagequery);
|
||||
|
||||
if ($num_toks) {
|
||||
$post = 0;
|
||||
@ -980,13 +991,13 @@ class WP_Rewrite {
|
||||
$date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct());
|
||||
|
||||
// Root
|
||||
$root_rewrite = $this->generate_rewrite_rules($this->prefix . '/');
|
||||
$root_rewrite = $this->generate_rewrite_rules($this->root . '/');
|
||||
|
||||
// Comments
|
||||
$comments_rewrite = $this->generate_rewrite_rules($this->prefix . 'comments', true);
|
||||
$comments_rewrite = $this->generate_rewrite_rules($this->root . 'comments',true, true, true);
|
||||
|
||||
// Search
|
||||
$search_structure = $this->prefix . "search/%search%";
|
||||
$search_structure = $this->root . "search/%search%";
|
||||
$search_rewrite = $this->generate_rewrite_rules($search_structure);
|
||||
|
||||
// Categories
|
||||
@ -1000,14 +1011,15 @@ class WP_Rewrite {
|
||||
$page_rewrite = $this->page_rewrite_rules();
|
||||
|
||||
// Deprecated style static pages
|
||||
$page_structure = $this->prefix . 'site/%pagename%';
|
||||
$page_structure = $this->root . 'site/%pagename%';
|
||||
$old_page_rewrite = $this->generate_rewrite_rules($page_structure);
|
||||
|
||||
// Put them together.
|
||||
$this->rewrite = $page_rewrite + $root_rewrite + $comments_rewrite + $old_page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
|
||||
$this->rules = $page_rewrite + $root_rewrite + $comments_rewrite + $old_page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
|
||||
|
||||
$this->rewrite = apply_filters('rewrite_rules_array', $this->rewrite);
|
||||
return $this->rewrite;
|
||||
do_action('generate_rewrite_rules', '');
|
||||
$this->rules = apply_filters('rewrite_rules_array', $this->rules);
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
function wp_rewrite_rules() {
|
||||
@ -1029,7 +1041,6 @@ class WP_Rewrite {
|
||||
$rules .= "RewriteBase $home_root\n";
|
||||
$this->matches = '';
|
||||
$rewrite = $this->rewrite_rules();
|
||||
|
||||
$num_rules = count($rewrite);
|
||||
$rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
|
||||
"RewriteCond %{REQUEST_FILENAME} -d\n" .
|
||||
@ -1061,9 +1072,9 @@ class WP_Rewrite {
|
||||
function init() {
|
||||
$this->permalink_structure = get_settings('permalink_structure');
|
||||
$this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));
|
||||
$this->prefix = '';
|
||||
$this->root = '';
|
||||
if ($this->using_index_permalinks()) {
|
||||
$this->prefix = $this->index . '/';
|
||||
$this->root = $this->index . '/';
|
||||
}
|
||||
$this->category_base = get_settings('category_base');
|
||||
unset($this->category_structure);
|
||||
|
@ -2056,4 +2056,13 @@ function add_query_arg() {
|
||||
function remove_query_arg($key, $query) {
|
||||
add_query_arg($key, '', $query);
|
||||
}
|
||||
|
||||
function load_template($file) {
|
||||
global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
|
||||
$wp_rewrite, $wpdb;
|
||||
|
||||
extract($wp_query->query_vars);
|
||||
|
||||
include($file);
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user