Make WordPress Core

Changeset 1910


Ignore:
Timestamp:
12/04/2004 12:12:08 AM (20 years ago)
Author:
rboren
Message:

Improve plugin hooks for rewrite manipulation. Allow pluggable template redirection.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r1909 r1910  
    208208if ($pagenow == 'index.php') {
    209209    if (! isset($wp_did_template_redirect)) {
     210        $wp_did_template_redirect = true;
     211        do_action('template_redirect', '');
    210212        if (is_feed()) {
    211213            $wp_did_template_redirect = true;
  • trunk/wp-includes/classes.php

    r1908 r1910  
    705705    var $date_structure;
    706706    var $front;
    707     var $prefix = '';
     707    var $root = '';
    708708    var $index = 'index.php';
    709709    var $matches = '';
     710    var $rules;
    710711    var $rewritecode =
    711712        array(
     
    877878    }
    878879
    879     function generate_rewrite_rules($permalink_structure = '', $forcomments = false) {
     880    function add_rewrite_tag($tag, $pattern, $query) {
     881        $this->rewritecode[] = $tag;
     882        $this->rewritereplace[] = $pattern;
     883        $this->queryreplace[] = $query;
     884    }
     885
     886    function generate_rewrite_rules($permalink_structure = '', $page = true, $feed = true, $forcomments = false) {
    880887        $feedregex2 = '(feed|rdf|rss|rss2|atom)/?$';
    881888        $feedregex = 'feed/' . $feedregex2;
     
    933940                $feedquery2 .= '&withcomments=1';
    934941            }
    935                
    936             $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2, $pagematch => $pagequery);
     942
     943            $rewrite = array();
     944            if ($feed)
     945                $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
     946            if ($page)
     947                $rewrite = $rewrite + array($pagematch => $pagequery);
    937948
    938949            if ($num_toks) {
     
    981992       
    982993        // Root
    983         $root_rewrite = $this->generate_rewrite_rules($this->prefix . '/');
     994        $root_rewrite = $this->generate_rewrite_rules($this->root . '/');
    984995
    985996        // Comments
    986         $comments_rewrite = $this->generate_rewrite_rules($this->prefix . 'comments', true);
     997        $comments_rewrite = $this->generate_rewrite_rules($this->root . 'comments',true, true, true);
    987998
    988999        // Search
    989         $search_structure = $this->prefix . "search/%search%";
     1000        $search_structure = $this->root . "search/%search%";
    9901001        $search_rewrite = $this->generate_rewrite_rules($search_structure);
    9911002
     
    10011012
    10021013        // Deprecated style static pages
    1003         $page_structure = $this->prefix . 'site/%pagename%';
     1014        $page_structure = $this->root . 'site/%pagename%';
    10041015        $old_page_rewrite = $this->generate_rewrite_rules($page_structure);
    10051016
    10061017        // Put them together.
    1007         $this->rewrite = $page_rewrite + $root_rewrite + $comments_rewrite + $old_page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
    1008 
    1009         $this->rewrite = apply_filters('rewrite_rules_array', $this->rewrite);
    1010         return $this->rewrite;
     1018        $this->rules = $page_rewrite + $root_rewrite + $comments_rewrite + $old_page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
     1019
     1020        do_action('generate_rewrite_rules', '');
     1021        $this->rules = apply_filters('rewrite_rules_array', $this->rules);
     1022        return $this->rules;
    10111023    }
    10121024
     
    10301042        $this->matches = '';
    10311043        $rewrite = $this->rewrite_rules();
    1032 
    10331044        $num_rules = count($rewrite);
    10341045        $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
     
    10621073        $this->permalink_structure = get_settings('permalink_structure');
    10631074        $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));     
    1064         $this->prefix = '';
     1075        $this->root = '';
    10651076        if ($this->using_index_permalinks()) {
    1066             $this->prefix = $this->index . '/';
     1077            $this->root = $this->index . '/';
    10671078        }
    10681079        $this->category_base = get_settings('category_base');
  • trunk/wp-includes/functions.php

    r1908 r1910  
    20572057    add_query_arg($key, '', $query);
    20582058}
     2059
     2060function load_template($file) {
     2061    global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
     2062        $wp_rewrite, $wpdb;
     2063
     2064    extract($wp_query->query_vars);
     2065
     2066    include($file);
     2067}
    20592068?>
Note: See TracChangeset for help on using the changeset viewer.