Changeset 42343 for trunk/src/wp-includes/rewrite.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rewrite.php
r41786 r42343 12 12 * @since 2.1.0 13 13 */ 14 define( 'EP_NONE', 0);14 define( 'EP_NONE', 0 ); 15 15 16 16 /** … … 19 19 * @since 2.1.0 20 20 */ 21 define( 'EP_PERMALINK', 1);21 define( 'EP_PERMALINK', 1 ); 22 22 23 23 /** … … 26 26 * @since 2.1.0 27 27 */ 28 define( 'EP_ATTACHMENT', 2);28 define( 'EP_ATTACHMENT', 2 ); 29 29 30 30 /** … … 33 33 * @since 2.1.0 34 34 */ 35 define( 'EP_DATE', 4);35 define( 'EP_DATE', 4 ); 36 36 37 37 /** … … 40 40 * @since 2.1.0 41 41 */ 42 define( 'EP_YEAR', 8);42 define( 'EP_YEAR', 8 ); 43 43 44 44 /** … … 47 47 * @since 2.1.0 48 48 */ 49 define( 'EP_MONTH', 16);49 define( 'EP_MONTH', 16 ); 50 50 51 51 /** … … 54 54 * @since 2.1.0 55 55 */ 56 define( 'EP_DAY', 32);56 define( 'EP_DAY', 32 ); 57 57 58 58 /** … … 61 61 * @since 2.1.0 62 62 */ 63 define( 'EP_ROOT', 64);63 define( 'EP_ROOT', 64 ); 64 64 65 65 /** … … 68 68 * @since 2.1.0 69 69 */ 70 define( 'EP_COMMENTS', 128);70 define( 'EP_COMMENTS', 128 ); 71 71 72 72 /** … … 75 75 * @since 2.1.0 76 76 */ 77 define( 'EP_SEARCH', 256);77 define( 'EP_SEARCH', 256 ); 78 78 79 79 /** … … 82 82 * @since 2.1.0 83 83 */ 84 define( 'EP_CATEGORIES', 512);84 define( 'EP_CATEGORIES', 512 ); 85 85 86 86 /** … … 89 89 * @since 2.3.0 90 90 */ 91 define( 'EP_TAGS', 1024);91 define( 'EP_TAGS', 1024 ); 92 92 93 93 /** … … 96 96 * @since 2.1.0 97 97 */ 98 define( 'EP_AUTHORS', 2048);98 define( 'EP_AUTHORS', 2048 ); 99 99 100 100 /** … … 103 103 * @since 2.1.0 104 104 */ 105 define( 'EP_PAGES', 4096);105 define( 'EP_PAGES', 4096 ); 106 106 107 107 /** … … 159 159 function add_rewrite_tag( $tag, $regex, $query = '' ) { 160 160 // validate the tag's name 161 if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen( $tag) - 1 ] != '%' )161 if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen( $tag ) - 1 ] != '%' ) { 162 162 return; 163 } 163 164 164 165 global $wp_rewrite, $wp; … … 204 205 205 206 // Back-compat for the old parameters: $with_front and $ep_mask. 206 if ( ! is_array( $args ) ) 207 if ( ! is_array( $args ) ) { 207 208 $args = array( 'with_front' => $args ); 208 if ( func_num_args() == 4 ) 209 } 210 if ( func_num_args() == 4 ) { 209 211 $args['ep_mask'] = func_get_arg( 3 ); 212 } 210 213 211 214 $wp_rewrite->add_permastruct( $name, $struct, $args ); … … 267 270 * 268 271 * @param bool $hard Whether to update .htaccess (hard flush) or just update 269 * 272 * rewrite_rules transient (soft flush). Default is true (hard). 270 273 */ 271 274 function flush_rewrite_rules( $hard = true ) { … … 323 326 */ 324 327 function _wp_filter_taxonomy_base( $base ) { 325 if ( ! empty( $base ) ) {328 if ( ! empty( $base ) ) { 326 329 $base = preg_replace( '|^/index\.php/|', '', $base ); 327 330 $base = trim( $base, '/' ); … … 481 484 482 485 // First, check to see if there is a 'p=N' or 'page_id=N' to match against 483 if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ){484 $id = absint( $values[2]);485 if ( $id ) 486 if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { 487 $id = absint( $values[2] ); 488 if ( $id ) { 486 489 return $id; 490 } 487 491 } 488 492 489 493 // Get rid of the #anchor 490 $url_split = explode( '#', $url);491 $url = $url_split[0];494 $url_split = explode( '#', $url ); 495 $url = $url_split[0]; 492 496 493 497 // Get rid of URL ?query=string 494 $url_split = explode( '?', $url);495 $url = $url_split[0];498 $url_split = explode( '?', $url ); 499 $url = $url_split[0]; 496 500 497 501 // Set the correct URL scheme. 498 502 $scheme = parse_url( home_url(), PHP_URL_SCHEME ); 499 $url = set_url_scheme( $url, $scheme );503 $url = set_url_scheme( $url, $scheme ); 500 504 501 505 // Add 'www.' if it is absent and should be there 502 if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) 503 $url = str_replace('://', '://www.', $url); 506 if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { 507 $url = str_replace( '://', '://www.', $url ); 508 } 504 509 505 510 // Strip 'www.' if it is present and shouldn't be 506 if ( false === strpos(home_url(), '://www.') ) 507 $url = str_replace('://www.', '://', $url); 511 if ( false === strpos( home_url(), '://www.' ) ) { 512 $url = str_replace( '://www.', '://', $url ); 513 } 508 514 509 515 if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { … … 519 525 520 526 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options 521 if ( empty( $rewrite) )527 if ( empty( $rewrite ) ) { 522 528 return 0; 529 } 523 530 524 531 // Strip 'index.php/' if we're not using path info permalinks 525 if ( ! $wp_rewrite->using_index_permalinks() )532 if ( ! $wp_rewrite->using_index_permalinks() ) { 526 533 $url = str_replace( $wp_rewrite->index . '/', '', $url ); 534 } 527 535 528 536 if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) { 529 537 // Chop off http://domain.com/[path] 530 $url = str_replace( home_url(), '', $url);538 $url = str_replace( home_url(), '', $url ); 531 539 } else { 532 540 // Chop off /path/to/blog 533 541 $home_path = parse_url( home_url( '/' ) ); 534 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' 535 $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );542 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : ''; 543 $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) ); 536 544 } 537 545 538 546 // Trim leading and lagging slashes 539 $url = trim( $url, '/');540 541 $request = $url;547 $url = trim( $url, '/' ); 548 549 $request = $url; 542 550 $post_type_query_vars = array(); 543 551 544 foreach ( get_post_types( array() 545 if ( ! empty( $t->query_var ) ) 552 foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) { 553 if ( ! empty( $t->query_var ) ) { 546 554 $post_type_query_vars[ $t->query_var ] = $post_type; 555 } 547 556 } 548 557 549 558 // Look for matches. 550 559 $request_match = $request; 551 foreach ( (array) $rewrite as $match => $query) {560 foreach ( (array) $rewrite as $match => $query ) { 552 561 553 562 // If the requesting file is the anchor of the match, prepend it 554 563 // to the path info. 555 if ( ! empty($url) && ($url != $request) && (strpos($match, $url) === 0) )564 if ( ! empty( $url ) && ( $url != $request ) && ( strpos( $match, $url ) === 0 ) ) { 556 565 $request_match = $url . '/' . $request; 557 558 if ( preg_match("#^$match#", $request_match, $matches) ) { 566 } 567 568 if ( preg_match( "#^$match#", $request_match, $matches ) ) { 559 569 560 570 if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { … … 574 584 // Got a match. 575 585 // Trim the query of everything up to the '?'. 576 $query = preg_replace( "!^.+\?!", '', $query);586 $query = preg_replace( '!^.+\?!', '', $query ); 577 587 578 588 // Substitute the substring matches into the query. 579 $query = addslashes( WP_MatchesMapRegex::apply($query, $matches));589 $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); 580 590 581 591 // Filter out non-public query vars … … 584 594 $query = array(); 585 595 foreach ( (array) $query_vars as $key => $value ) { 586 if ( in_array( $key, $wp->public_query_vars ) ) {587 $query[ $key] = $value;588 if ( isset( $post_type_query_vars[ $key] ) ) {589 $query['post_type'] = $post_type_query_vars[ $key];590 $query['name'] = $value;596 if ( in_array( $key, $wp->public_query_vars ) ) { 597 $query[ $key ] = $value; 598 if ( isset( $post_type_query_vars[ $key ] ) ) { 599 $query['post_type'] = $post_type_query_vars[ $key ]; 600 $query['name'] = $value; 591 601 } 592 602 } … … 598 608 // Do the query 599 609 $query = new WP_Query( $query ); 600 if ( ! empty( $query->posts ) && $query->is_singular ) 610 if ( ! empty( $query->posts ) && $query->is_singular ) { 601 611 return $query->post->ID; 602 else612 } else { 603 613 return 0; 614 } 604 615 } 605 616 }
Note: See TracChangeset
for help on using the changeset viewer.