Ticket #48223: 48223.1.diff
File 48223.1.diff, 6.5 KB (added by , 4 years ago) |
---|
-
deleted file 48223.diff
diff --git a/48223.diff b/48223.diff deleted file mode 100644 index d3820df37e..0000000000
+ - 1 diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php2 index 508fae2f03..e2ee96404c 1006443 --- a/wp-includes/class-wp.php4 +++ b/wp-includes/class-wp.php5 @@ -66,6 +66,22 @@ class WP {6 */7 public $matched_rule;8 9 + /**10 + * Array of matched rules to loop over.11 + *12 + * @since x.x.x13 + * @var string[]14 + */15 + public $matched_rules;16 +17 + /**18 + * Array of all potential matched rules found.19 + *20 + * @since x.x.x21 + * @var string[]22 + */23 + public $all_matched_rules;24 +25 /**26 * Rewrite query the request matched.27 *28 @@ -205,14 +221,20 @@ class WP {29 30 // Look for matches.31 $request_match = $requested_path;32 +33 + if ( empty($this->all_matched_rules) ){34 + $this->all_matched_rules = array();35 + $this->matched_rules = $this->all_matched_rules;36 + }37 +38 if ( empty( $request_match ) ) {39 // An empty request could only match against ^$ regex40 if ( isset( $rewrite['$'] ) ) {41 - $this->matched_rule = '$';42 + $this->all_matched_rules[] = '$';43 $query = $rewrite['$'];44 $matches = array( '' );45 }46 - } else {47 + } else if ( empty( $this->all_matched_rules ) ){48 foreach ( (array) $rewrite as $match => $query ) {49 // If the requested file is the anchor of the match, prepend it to the path info.50 if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) {51 @@ -236,13 +258,27 @@ class WP {52 }53 }54 55 - // Got a match.56 - $this->matched_rule = $match;57 - break;58 + // Got a match - add to matched_rules array.59 + $this->all_matched_rules[] = array(60 + 'matches' => $matches,61 + 'match' => $match,62 + 'query' => $query,63 + );64 }65 + $this->matched_rules = $this->all_matched_rules;66 }67 }68 69 + // we set $this->matched_rule here70 + if (! empty($this->matched_rules)){71 + $pop = reset($this->matched_rules);72 + array_shift($this->matched_rules);73 +74 + $this->matched_rule = $pop['match'];75 + $query = $pop['query'];76 + $matches = $pop['matches'];77 + }78 +79 if ( isset( $this->matched_rule ) ) {80 // Trim the query of everything up to the '?'.81 $query = preg_replace( '!^.+\?!', '', $query );82 @@ -718,6 +754,25 @@ class WP {83 nocache_headers();84 }85 86 + /**87 + * Try to parse another rule/query that matches our request.88 + *89 + * @since x.x.x90 + */91 + function maybe_try_another_matched_rule($preemt, $wp_query){92 +93 + if ( empty($wp_query->posts) && !empty($this->matched_rules) ){94 +95 + // there is some redundancy here - no need to re-parse $_SERVER etc.96 + // but we do need to try parsing another matched rule and query97 + $this->parse_request();98 + $this->query_posts();99 + $this->handle_404();100 + }101 +102 + return false;103 + }104 +105 /**106 * Sets up all of the variables required by the WordPress environment.107 *108 @@ -730,6 +785,9 @@ class WP {109 * @param string|array $query_args Passed to parse_request().110 */111 public function main( $query_args = '' ) {112 +113 + add_action( 'pre_handle_404', array($this, 'maybe_try_another_matched_rule'), 10, 2 );114 +115 $this->init();116 $this->parse_request( $query_args );117 $this->send_headers(); -
wp-includes/class-wp.php
diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 58ec03460a..508fae2f03 100644
a b class WP { 66 66 */ 67 67 public $matched_rule; 68 68 69 /**70 * Array of matched rules to loop over.71 *72 * @since x.x.x73 * @var string[]74 */75 public $matched_rules;76 77 /**78 * Array of all potential matched rules found.79 *80 * @since x.x.x81 * @var string[]82 */83 public $all_matched_rules;84 85 69 /** 86 70 * Rewrite query the request matched. 87 71 * … … class WP { 221 205 222 206 // Look for matches. 223 207 $request_match = $requested_path; 224 225 if ( ! isset( $this->all_matched_rules ) ){226 $this->all_matched_rules = array();227 }228 229 208 if ( empty( $request_match ) ) { 230 209 // An empty request could only match against ^$ regex 231 210 if ( isset( $rewrite['$'] ) ) { 232 $this-> all_matched_rules[]= '$';211 $this->matched_rule = '$'; 233 212 $query = $rewrite['$']; 234 213 $matches = array( '' ); 235 $this->matched_rules = $this->all_matched_rules;236 214 } 237 } else if ( empty( $this->all_matched_rules ) ){215 } else { 238 216 foreach ( (array) $rewrite as $match => $query ) { 239 217 // If the requested file is the anchor of the match, prepend it to the path info. 240 218 if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) { … … class WP { 258 236 } 259 237 } 260 238 261 // Got a match - add to matched_rules array. 262 $this->all_matched_rules[] = array( 263 'matches' => $matches, 264 'match' => $match, 265 'query' => $query, 266 ); 239 // Got a match. 240 $this->matched_rule = $match; 241 break; 267 242 } 268 $this->matched_rules = $this->all_matched_rules;269 243 } 270 244 } 271 245 272 // we set $this->matched_rule here273 if (! empty($this->matched_rules)){274 $pop = reset($this->matched_rules);275 array_shift($this->matched_rules);276 277 $this->matched_rule = $pop['match'];278 $query = $pop['query'];279 $matches = $pop['matches'];280 }281 282 246 if ( isset( $this->matched_rule ) ) { 283 247 // Trim the query of everything up to the '?'. 284 248 $query = preg_replace( '!^.+\?!', '', $query ); … … class WP { 754 718 nocache_headers(); 755 719 } 756 720 757 /**758 * Try to parse another rule/query that matches our request.759 *760 * @since x.x.x761 */762 function maybe_try_another_matched_rule($preemt, $wp_query){763 764 if ( empty($wp_query->posts) && !empty($this->matched_rules) ){765 766 // there is some redundancy here - no need to re-parse $_SERVER etc.767 // but we do need to try parsing another matched rule and query768 $this->parse_request();769 $this->query_posts();770 $this->handle_404();771 }772 773 return false;774 }775 776 721 /** 777 722 * Sets up all of the variables required by the WordPress environment. 778 723 * … … class WP { 785 730 * @param string|array $query_args Passed to parse_request(). 786 731 */ 787 732 public function main( $query_args = '' ) { 788 789 add_action( 'pre_handle_404', array($this, 'maybe_try_another_matched_rule'), 10, 2 );790 791 733 $this->init(); 792 734 $this->parse_request( $query_args ); 793 735 $this->send_headers();