Changes in trunk/wp-includes/rewrite.php [15109:17226]
- File:
-
- 1 edited
-
trunk/wp-includes/rewrite.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/rewrite.php
r15109 r17226 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 ()) when your plugin gets208 * Be sure to flush the rewrite rules (wp_rewrite->flush_rules()) 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 Jaquith272 // This fixes things like #anchors, ?query=strings, missing 'www.',273 // added 'www.', or added 'index.php/' that will mess up our WP_Query274 // and return a false negative275 270 276 271 // Get rid of the #anchor … … 300 295 // Chop off /path/to/blog 301 296 $home_path = parse_url(home_url()); 302 $home_path = $home_path['path'];297 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ; 303 298 $url = str_replace($home_path, '', $url); 304 299 } … … 308 303 309 304 $request = $url; 310 311 // Done with cleanup312 305 313 306 // Look for matches. … … 338 331 // Do the query 339 332 $query = new WP_Query($query); 340 if ( $query->is_single || $query->is_page)333 if ( !empty($query->posts) && $query->is_singular ) 341 334 return $query->post->ID; 342 335 else … … 382 375 383 376 /** 384 * Customized or default category permalink base ( example.com/xx/tagname ).377 * Permalink author request base ( example.com/author/authorname ). 385 378 * 386 379 * @since 1.5.0 … … 388 381 * @var string 389 382 */ 390 var $ category_base;391 392 /** 393 * Customized or default tag permalink base ( example.com/xx/tagname ).394 * 395 * @since 2.3.0383 var $author_base = 'author'; 384 385 /** 386 * Permalink request structure for author pages. 387 * 388 * @since 1.5.0 396 389 * @access private 397 390 * @var string 398 391 */ 399 var $ tag_base;400 401 /** 402 * Permalink request structure for categories.392 var $author_structure; 393 394 /** 395 * Permalink request structure for dates. 403 396 * 404 397 * @since 1.5.0 … … 406 399 * @var string 407 400 */ 408 var $ category_structure;409 410 /** 411 * Permalink request structure for tags.412 * 413 * @since 2.3.0401 var $date_structure; 402 403 /** 404 * Permalink request structure for pages. 405 * 406 * @since 1.5.0 414 407 * @access private 415 408 * @var string 416 409 */ 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 ). 421 414 * 422 415 * @since 1.5.0 … … 424 417 * @var string 425 418 */ 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. 430 423 * 431 424 * @since 1.5.0 … … 433 426 * @var string 434 427 */ 435 var $ author_structure;436 437 /** 438 * Permalink request structure for dates.428 var $search_structure; 429 430 /** 431 * Comments permalink base. 439 432 * 440 433 * @since 1.5.0 … … 442 435 * @var string 443 436 */ 444 var $ date_structure;445 446 /** 447 * P ermalink request structure for pages.448 * 449 * @since 1.5.0437 var $comments_base = 'comments'; 438 439 /** 440 * Pagination permalink base. 441 * 442 * @since 3.1.0 450 443 * @access private 451 444 * @var string 452 445 */ 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'; 481 447 482 448 /** … … 605 571 * Endpoints permalinks 606 572 * 607 * @since unknown573 * @since 2.1.0 608 574 * @access private 609 575 * @var array … … 649 615 '%postname%', 650 616 '%post_id%', 651 '%category%',652 '%tag%',653 617 '%author%', 654 618 '%pagename%', … … 673 637 '([^/]+)', 674 638 '([0-9]+)', 675 '(.+?)',676 '(.+?)',677 639 '([^/]+)', 678 640 '([^/]+?)', … … 697 659 'name=', 698 660 'p=', 699 'category_name=',700 'tag=',701 661 'author_name=', 702 662 'pagename=', … … 1020 980 */ 1021 981 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'); 1038 983 } 1039 984 … … 1052 997 */ 1053 998 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'); 1070 1000 } 1071 1001 … … 1073 1003 * Retrieve extra permalink structure by name. 1074 1004 * 1075 * @since unknown1005 * @since 2.5.0 1076 1006 * @access public 1077 1007 * … … 1280 1210 //build a regex to match the trackback and page/xx parts of URLs 1281 1211 $trackbackregex = 'trackback/?$'; 1282 $pageregex = 'page/?([0-9]{1,})/?$';1212 $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$'; 1283 1213 $commentregex = 'comment-page-([0-9]{1,})/?$'; 1284 1214 … … 1605 1535 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); 1606 1536 1607 // Categories1608 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);1609 $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);1610 1611 // Tags1612 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);1613 $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);1614 1615 1537 // Authors 1616 1538 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS); … … 1622 1544 1623 1545 // Extra permastructs 1624 foreach ( $this->extra_permastructs as $permastruct ) {1546 foreach ( $this->extra_permastructs as $permastructname => $permastruct ) { 1625 1547 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]); 1627 1549 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); 1629 1557 } 1630 1558 1631 1559 // Put them together. 1632 1560 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); 1634 1562 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); 1636 1564 1637 1565 do_action_ref_array('generate_rewrite_rules', array(&$this)); … … 1920 1848 * top. 1921 1849 * 1922 * @since unknown1850 * @since 2.5.0 1923 1851 * @access public 1924 1852 * … … 1942 1870 * @since 2.0.1 1943 1871 * @access public 1944 * @param $hard boolWhether 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). 1945 1873 */ 1946 1874 function flush_rules($hard = true) { … … 1970 1898 if ( $this->using_index_permalinks() ) 1971 1899 $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);1975 1900 unset($this->author_structure); 1976 1901 unset($this->date_structure); … … 2024 1949 */ 2025 1950 function set_category_base($category_base) { 2026 if ( $category_base != $this->category_base) {1951 if ( $category_base != get_option('category_base') ) { 2027 1952 update_option('category_base', $category_base); 2028 1953 $this->init(); … … 2043 1968 */ 2044 1969 function set_tag_base( $tag_base ) { 2045 if ( $tag_base != $this->tag_base) {1970 if ( $tag_base != get_option( 'tag_base') ) { 2046 1971 update_option( 'tag_base', $tag_base ); 2047 1972 $this->init();
Note: See TracChangeset
for help on using the changeset viewer.