Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/rewrite.php

    r15109 r17226  
    3535function add_rewrite_tag($tagname, $regex) {
    3636    //validation
    37     if ( strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%' )
     37    if ( strlen($tagname) < 3 || $tagname[0] != '%' || $tagname[strlen($tagname)-1] != '%' )
    3838        return;
    3939
     
    206206 * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/".
    207207 *
    208  * Be sure to flush the rewrite rules (wp_rewrite->flush()) when your plugin gets
     208 * Be sure to flush the rewrite rules (wp_rewrite->flush_rules()) when your plugin gets
    209209 * activated (register_activation_hook()) and deactivated (register_deactivation_hook())
    210210 *
     
    268268    if ( empty($rewrite) )
    269269        return 0;
    270 
    271     // $url cleanup by Mark Jaquith
    272     // This fixes things like #anchors, ?query=strings, missing 'www.',
    273     // added 'www.', or added 'index.php/' that will mess up our WP_Query
    274     // and return a false negative
    275270
    276271    // Get rid of the #anchor
     
    300295        // Chop off /path/to/blog
    301296        $home_path = parse_url(home_url());
    302         $home_path = $home_path['path'];
     297        $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
    303298        $url = str_replace($home_path, '', $url);
    304299    }
     
    308303
    309304    $request = $url;
    310 
    311     // Done with cleanup
    312305
    313306    // Look for matches.
     
    338331            // Do the query
    339332            $query = new WP_Query($query);
    340             if ( $query->is_single || $query->is_page )
     333            if ( !empty($query->posts) && $query->is_singular )
    341334                return $query->post->ID;
    342335            else
     
    382375
    383376    /**
    384      * Customized or default category permalink base ( example.com/xx/tagname ).
     377     * Permalink author request base ( example.com/author/authorname ).
    385378     *
    386379     * @since 1.5.0
     
    388381     * @var string
    389382     */
    390     var $category_base;
    391 
    392     /**
    393      * Customized or default tag permalink base ( example.com/xx/tagname ).
    394      *
    395      * @since 2.3.0
     383    var $author_base = 'author';
     384
     385    /**
     386     * Permalink request structure for author pages.
     387     *
     388     * @since 1.5.0
    396389     * @access private
    397390     * @var string
    398391     */
    399     var $tag_base;
    400 
    401     /**
    402      * Permalink request structure for categories.
     392    var $author_structure;
     393
     394    /**
     395     * Permalink request structure for dates.
    403396     *
    404397     * @since 1.5.0
     
    406399     * @var string
    407400     */
    408     var $category_structure;
    409 
    410     /**
    411      * Permalink request structure for tags.
    412      *
    413      * @since 2.3.0
     401    var $date_structure;
     402
     403    /**
     404     * Permalink request structure for pages.
     405     *
     406     * @since 1.5.0
    414407     * @access private
    415408     * @var string
    416409     */
    417     var $tag_structure;
    418 
    419     /**
    420      * Permalink author request base ( example.com/author/authorname ).
     410    var $page_structure;
     411
     412    /**
     413     * Search permalink base ( example.com/search/query ).
    421414     *
    422415     * @since 1.5.0
     
    424417     * @var string
    425418     */
    426     var $author_base = 'author';
    427 
    428     /**
    429      * Permalink request structure for author pages.
     419    var $search_base = 'search';
     420
     421    /**
     422     * Permalink request structure for searches.
    430423     *
    431424     * @since 1.5.0
     
    433426     * @var string
    434427     */
    435     var $author_structure;
    436 
    437     /**
    438      * Permalink request structure for dates.
     428    var $search_structure;
     429
     430    /**
     431     * Comments permalink base.
    439432     *
    440433     * @since 1.5.0
     
    442435     * @var string
    443436     */
    444     var $date_structure;
    445 
    446     /**
    447      * Permalink request structure for pages.
    448      *
    449      * @since 1.5.0
     437    var $comments_base = 'comments';
     438
     439    /**
     440     * Pagination permalink base.
     441     *
     442     * @since 3.1.0
    450443     * @access private
    451444     * @var string
    452445     */
    453     var $page_structure;
    454 
    455     /**
    456      * Search permalink base ( example.com/search/query ).
    457      *
    458      * @since 1.5.0
    459      * @access private
    460      * @var string
    461      */
    462     var $search_base = 'search';
    463 
    464     /**
    465      * Permalink request structure for searches.
    466      *
    467      * @since 1.5.0
    468      * @access private
    469      * @var string
    470      */
    471     var $search_structure;
    472 
    473     /**
    474      * Comments permalink base.
    475      *
    476      * @since 1.5.0
    477      * @access private
    478      * @var string
    479      */
    480     var $comments_base = 'comments';
     446    var $pagination_base = 'page';
    481447
    482448    /**
     
    605571     * Endpoints permalinks
    606572     *
    607      * @since unknown
     573     * @since 2.1.0
    608574     * @access private
    609575     * @var array
     
    649615                    '%postname%',
    650616                    '%post_id%',
    651                     '%category%',
    652                     '%tag%',
    653617                    '%author%',
    654618                    '%pagename%',
     
    673637                    '([^/]+)',
    674638                    '([0-9]+)',
    675                     '(.+?)',
    676                     '(.+?)',
    677639                    '([^/]+)',
    678640                    '([^/]+?)',
     
    697659                    'name=',
    698660                    'p=',
    699                     'category_name=',
    700                     'tag=',
    701661                    'author_name=',
    702662                    'pagename=',
     
    1020980     */
    1021981    function get_category_permastruct() {
    1022         if ( isset($this->category_structure) )
    1023             return $this->category_structure;
    1024 
    1025         if ( empty($this->permalink_structure) ) {
    1026             $this->category_structure = '';
    1027             return false;
    1028         }
    1029 
    1030         if ( empty($this->category_base) )
    1031             $this->category_structure = trailingslashit( $this->front . 'category' );
    1032         else
    1033             $this->category_structure = trailingslashit( '/' . $this->root . $this->category_base );
    1034 
    1035         $this->category_structure .= '%category%';
    1036 
    1037         return $this->category_structure;
     982        return $this->get_extra_permastruct('category');
    1038983    }
    1039984
     
    1052997     */
    1053998    function get_tag_permastruct() {
    1054         if ( isset($this->tag_structure) )
    1055             return $this->tag_structure;
    1056 
    1057         if ( empty($this->permalink_structure) ) {
    1058             $this->tag_structure = '';
    1059             return false;
    1060         }
    1061 
    1062         if ( empty($this->tag_base) )
    1063             $this->tag_structure = trailingslashit( $this->front . 'tag' );
    1064         else
    1065             $this->tag_structure = trailingslashit( '/' . $this->root . $this->tag_base );
    1066 
    1067         $this->tag_structure .= '%tag%';
    1068 
    1069         return $this->tag_structure;
     999        return $this->get_extra_permastruct('post_tag');
    10701000    }
    10711001
     
    10731003     * Retrieve extra permalink structure by name.
    10741004     *
    1075      * @since unknown
     1005     * @since 2.5.0
    10761006     * @access public
    10771007     *
     
    12801210        //build a regex to match the trackback and page/xx parts of URLs
    12811211        $trackbackregex = 'trackback/?$';
    1282         $pageregex = 'page/?([0-9]{1,})/?$';
     1212        $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
    12831213        $commentregex = 'comment-page-([0-9]{1,})/?$';
    12841214
     
    16051535        $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
    16061536
    1607         // Categories
    1608         $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
    1609         $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
    1610 
    1611         // Tags
    1612         $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
    1613         $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
    1614 
    16151537        // Authors
    16161538        $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
     
    16221544
    16231545        // Extra permastructs
    1624         foreach ( $this->extra_permastructs as $permastruct ) {
     1546        foreach ( $this->extra_permastructs as $permastructname => $permastruct ) {
    16251547            if ( is_array($permastruct) )
    1626                 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct[0], $permastruct[1]));
     1548                $rules = $this->generate_rewrite_rules($permastruct[0], $permastruct[1]);
    16271549            else
    1628                 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE));
     1550                $rules = $this->generate_rewrite_rules($permastruct, EP_NONE);
     1551
     1552            $rules = apply_filters($permastructname . '_rewrite_rules', $rules);
     1553            if ( 'post_tag' == $permastructname )
     1554                $rules = apply_filters('tag_rewrite_rules', $rules);
     1555
     1556            $this->extra_rules_top = array_merge($this->extra_rules_top, $rules);
    16291557        }
    16301558
    16311559        // Put them together.
    16321560        if ( $this->use_verbose_page_rules )
    1633             $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
     1561            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
    16341562        else
    1635             $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
     1563            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
    16361564
    16371565        do_action_ref_array('generate_rewrite_rules', array(&$this));
     
    19201848     * top.
    19211849     *
    1922      * @since unknown
     1850     * @since 2.5.0
    19231851     * @access public
    19241852     *
     
    19421870     * @since 2.0.1
    19431871     * @access public
    1944      * @param $hard bool Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
     1872     * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
    19451873     */
    19461874    function flush_rules($hard = true) {
     
    19701898        if ( $this->using_index_permalinks() )
    19711899            $this->root = $this->index . '/';
    1972         $this->category_base = get_option( 'category_base' );
    1973         $this->tag_base = get_option( 'tag_base' );
    1974         unset($this->category_structure);
    19751900        unset($this->author_structure);
    19761901        unset($this->date_structure);
     
    20241949     */
    20251950    function set_category_base($category_base) {
    2026         if ( $category_base != $this->category_base ) {
     1951        if ( $category_base != get_option('category_base') ) {
    20271952            update_option('category_base', $category_base);
    20281953            $this->init();
     
    20431968     */
    20441969    function set_tag_base( $tag_base ) {
    2045         if ( $tag_base != $this->tag_base ) {
     1970        if ( $tag_base != get_option( 'tag_base') ) {
    20461971            update_option( 'tag_base', $tag_base );
    20471972            $this->init();
Note: See TracChangeset for help on using the changeset viewer.