Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17226 r15109  
    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_rules()) when your plugin gets
     208 * Be sure to flush the rewrite rules (wp_rewrite->flush()) 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
    270275
    271276        // Get rid of the #anchor
     
    295300                // Chop off /path/to/blog
    296301                $home_path = parse_url(home_url());
    297                 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
     302                $home_path = $home_path['path'];
    298303                $url = str_replace($home_path, '', $url);
    299304        }
     
    303308
    304309        $request = $url;
     310
     311        // Done with cleanup
    305312
    306313        // Look for matches.
     
    331338                        // Do the query
    332339                        $query = new WP_Query($query);
    333                         if ( !empty($query->posts) && $query->is_singular )
     340                        if ( $query->is_single || $query->is_page )
    334341                                return $query->post->ID;
    335342                        else
     
    375382
    376383        /**
     384         * Customized or default category permalink base ( example.com/xx/tagname ).
     385         *
     386         * @since 1.5.0
     387         * @access private
     388         * @var string
     389         */
     390        var $category_base;
     391
     392        /**
     393         * Customized or default tag permalink base ( example.com/xx/tagname ).
     394         *
     395         * @since 2.3.0
     396         * @access private
     397         * @var string
     398         */
     399        var $tag_base;
     400
     401        /**
     402         * Permalink request structure for categories.
     403         *
     404         * @since 1.5.0
     405         * @access private
     406         * @var string
     407         */
     408        var $category_structure;
     409
     410        /**
     411         * Permalink request structure for tags.
     412         *
     413         * @since 2.3.0
     414         * @access private
     415         * @var string
     416         */
     417        var $tag_structure;
     418
     419        /**
    377420         * Permalink author request base ( example.com/author/authorname ).
    378421         *
     
    436479         */
    437480        var $comments_base = 'comments';
    438 
    439         /**
    440          * Pagination permalink base.
    441          *
    442          * @since 3.1.0
    443          * @access private
    444          * @var string
    445          */
    446         var $pagination_base = 'page';
    447481
    448482        /**
     
    571605         * Endpoints permalinks
    572606         *
    573          * @since 2.1.0
     607         * @since unknown
    574608         * @access private
    575609         * @var array
     
    615649                                        '%postname%',
    616650                                        '%post_id%',
     651                                        '%category%',
     652                                        '%tag%',
    617653                                        '%author%',
    618654                                        '%pagename%',
     
    637673                                        '([^/]+)',
    638674                                        '([0-9]+)',
     675                                        '(.+?)',
     676                                        '(.+?)',
    639677                                        '([^/]+)',
    640678                                        '([^/]+?)',
     
    659697                                        'name=',
    660698                                        'p=',
     699                                        'category_name=',
     700                                        'tag=',
    661701                                        'author_name=',
    662702                                        'pagename=',
     
    9801020         */
    9811021        function get_category_permastruct() {
    982                 return $this->get_extra_permastruct('category');
     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;
    9831038        }
    9841039
     
    9971052         */
    9981053        function get_tag_permastruct() {
    999                 return $this->get_extra_permastruct('post_tag');
     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;
    10001070        }
    10011071
     
    10031073         * Retrieve extra permalink structure by name.
    10041074         *
    1005          * @since 2.5.0
     1075         * @since unknown
    10061076         * @access public
    10071077         *
     
    12101280                //build a regex to match the trackback and page/xx parts of URLs
    12111281                $trackbackregex = 'trackback/?$';
    1212                 $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
     1282                $pageregex = 'page/?([0-9]{1,})/?$';
    12131283                $commentregex = 'comment-page-([0-9]{1,})/?$';
    12141284
     
    15351605                $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
    15361606
     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
    15371615                // Authors
    15381616                $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
     
    15441622
    15451623                // Extra permastructs
    1546                 foreach ( $this->extra_permastructs as $permastructname => $permastruct ) {
     1624                foreach ( $this->extra_permastructs as $permastruct ) {
    15471625                        if ( is_array($permastruct) )
    1548                                 $rules = $this->generate_rewrite_rules($permastruct[0], $permastruct[1]);
     1626                                $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct[0], $permastruct[1]));
    15491627                        else
    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);
     1628                                $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE));
    15571629                }
    15581630
    15591631                // Put them together.
    15601632                if ( $this->use_verbose_page_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);
     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);
    15621634                else
    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);
     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);
    15641636
    15651637                do_action_ref_array('generate_rewrite_rules', array(&$this));
     
    18481920         * top.
    18491921         *
    1850          * @since 2.5.0
     1922         * @since unknown
    18511923         * @access public
    18521924         *
     
    18701942         * @since 2.0.1
    18711943         * @access public
    1872          * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
     1944         * @param $hard bool Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
    18731945         */
    18741946        function flush_rules($hard = true) {
     
    18981970                if ( $this->using_index_permalinks() )
    18991971                        $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);
    19001975                unset($this->author_structure);
    19011976                unset($this->date_structure);
     
    19492024         */
    19502025        function set_category_base($category_base) {
    1951                 if ( $category_base != get_option('category_base') ) {
     2026                if ( $category_base != $this->category_base ) {
    19522027                        update_option('category_base', $category_base);
    19532028                        $this->init();
     
    19682043         */
    19692044        function set_tag_base( $tag_base ) {
    1970                 if ( $tag_base != get_option( 'tag_base') ) {
     2045                if ( $tag_base != $this->tag_base ) {
    19712046                        update_option( 'tag_base', $tag_base );
    19722047                        $this->init();
Note: See TracChangeset for help on using the changeset viewer.