Changes in trunk/wp-includes/rewrite.php [17226:15109]
- File:
-
- 1 edited
-
trunk/wp-includes/rewrite.php (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/rewrite.php
r17226 r15109 35 35 function add_rewrite_tag($tagname, $regex) { 36 36 //validation 37 if ( strlen($tagname) < 3 || $tagname [0] != '%' || $tagname[strlen($tagname)-1]!= '%' )37 if ( strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%' ) 38 38 return; 39 39 … … 206 206 * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/". 207 207 * 208 * Be sure to flush the rewrite rules (wp_rewrite->flush _rules()) when your plugin gets208 * Be sure to flush the rewrite rules (wp_rewrite->flush()) when your plugin gets 209 209 * activated (register_activation_hook()) and deactivated (register_deactivation_hook()) 210 210 * … … 268 268 if ( empty($rewrite) ) 269 269 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 270 275 271 276 // Get rid of the #anchor … … 295 300 // Chop off /path/to/blog 296 301 $home_path = parse_url(home_url()); 297 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '';302 $home_path = $home_path['path']; 298 303 $url = str_replace($home_path, '', $url); 299 304 } … … 303 308 304 309 $request = $url; 310 311 // Done with cleanup 305 312 306 313 // Look for matches. … … 331 338 // Do the query 332 339 $query = new WP_Query($query); 333 if ( !empty($query->posts) && $query->is_singular)340 if ( $query->is_single || $query->is_page ) 334 341 return $query->post->ID; 335 342 else … … 375 382 376 383 /** 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 /** 377 420 * Permalink author request base ( example.com/author/authorname ). 378 421 * … … 436 479 */ 437 480 var $comments_base = 'comments'; 438 439 /**440 * Pagination permalink base.441 *442 * @since 3.1.0443 * @access private444 * @var string445 */446 var $pagination_base = 'page';447 481 448 482 /** … … 571 605 * Endpoints permalinks 572 606 * 573 * @since 2.1.0607 * @since unknown 574 608 * @access private 575 609 * @var array … … 615 649 '%postname%', 616 650 '%post_id%', 651 '%category%', 652 '%tag%', 617 653 '%author%', 618 654 '%pagename%', … … 637 673 '([^/]+)', 638 674 '([0-9]+)', 675 '(.+?)', 676 '(.+?)', 639 677 '([^/]+)', 640 678 '([^/]+?)', … … 659 697 'name=', 660 698 'p=', 699 'category_name=', 700 'tag=', 661 701 'author_name=', 662 702 'pagename=', … … 980 1020 */ 981 1021 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; 983 1038 } 984 1039 … … 997 1052 */ 998 1053 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; 1000 1070 } 1001 1071 … … 1003 1073 * Retrieve extra permalink structure by name. 1004 1074 * 1005 * @since 2.5.01075 * @since unknown 1006 1076 * @access public 1007 1077 * … … 1210 1280 //build a regex to match the trackback and page/xx parts of URLs 1211 1281 $trackbackregex = 'trackback/?$'; 1212 $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';1282 $pageregex = 'page/?([0-9]{1,})/?$'; 1213 1283 $commentregex = 'comment-page-([0-9]{1,})/?$'; 1214 1284 … … 1535 1605 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); 1536 1606 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 1537 1615 // Authors 1538 1616 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS); … … 1544 1622 1545 1623 // Extra permastructs 1546 foreach ( $this->extra_permastructs as $permastruct name => $permastruct) {1624 foreach ( $this->extra_permastructs as $permastruct ) { 1547 1625 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])); 1549 1627 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)); 1557 1629 } 1558 1630 1559 1631 // Put them together. 1560 1632 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); 1562 1634 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); 1564 1636 1565 1637 do_action_ref_array('generate_rewrite_rules', array(&$this)); … … 1848 1920 * top. 1849 1921 * 1850 * @since 2.5.01922 * @since unknown 1851 1923 * @access public 1852 1924 * … … 1870 1942 * @since 2.0.1 1871 1943 * @access public 1872 * @param bool $hardWhether 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). 1873 1945 */ 1874 1946 function flush_rules($hard = true) { … … 1898 1970 if ( $this->using_index_permalinks() ) 1899 1971 $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); 1900 1975 unset($this->author_structure); 1901 1976 unset($this->date_structure); … … 1949 2024 */ 1950 2025 function set_category_base($category_base) { 1951 if ( $category_base != get_option('category_base')) {2026 if ( $category_base != $this->category_base ) { 1952 2027 update_option('category_base', $category_base); 1953 2028 $this->init(); … … 1968 2043 */ 1969 2044 function set_tag_base( $tag_base ) { 1970 if ( $tag_base != get_option( 'tag_base')) {2045 if ( $tag_base != $this->tag_base ) { 1971 2046 update_option( 'tag_base', $tag_base ); 1972 2047 $this->init();
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)