diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php
index 508fae2f03..e2ee96404c 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.x |
| 73 | * @var string[] |
| 74 | */ |
| 75 | public $matched_rules; |
| 76 | |
| 77 | /** |
| 78 | * Array of all potential matched rules found. |
| 79 | * |
| 80 | * @since x.x.x |
| 81 | * @var string[] |
| 82 | */ |
| 83 | public $all_matched_rules; |
| 84 | |
69 | 85 | /** |
70 | 86 | * Rewrite query the request matched. |
71 | 87 | * |
… |
… |
class WP { |
205 | 221 | |
206 | 222 | // Look for matches. |
207 | 223 | $request_match = $requested_path; |
| 224 | |
| 225 | if ( empty($this->all_matched_rules) ){ |
| 226 | $this->all_matched_rules = array(); |
| 227 | $this->matched_rules = $this->all_matched_rules; |
| 228 | } |
| 229 | |
208 | 230 | if ( empty( $request_match ) ) { |
209 | 231 | // An empty request could only match against ^$ regex |
210 | 232 | if ( isset( $rewrite['$'] ) ) { |
211 | | $this->matched_rule = '$'; |
| 233 | $this->all_matched_rules[] = '$'; |
212 | 234 | $query = $rewrite['$']; |
213 | 235 | $matches = array( '' ); |
214 | 236 | } |
215 | | } else { |
| 237 | } else if ( empty( $this->all_matched_rules ) ){ |
216 | 238 | foreach ( (array) $rewrite as $match => $query ) { |
217 | 239 | // If the requested file is the anchor of the match, prepend it to the path info. |
218 | 240 | if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) { |
… |
… |
class WP { |
236 | 258 | } |
237 | 259 | } |
238 | 260 | |
239 | | // Got a match. |
240 | | $this->matched_rule = $match; |
241 | | break; |
| 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 | ); |
242 | 267 | } |
| 268 | $this->matched_rules = $this->all_matched_rules; |
243 | 269 | } |
244 | 270 | } |
245 | 271 | |
| 272 | // we set $this->matched_rule here |
| 273 | 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 | |
246 | 282 | if ( isset( $this->matched_rule ) ) { |
247 | 283 | // Trim the query of everything up to the '?'. |
248 | 284 | $query = preg_replace( '!^.+\?!', '', $query ); |
… |
… |
class WP { |
718 | 754 | nocache_headers(); |
719 | 755 | } |
720 | 756 | |
| 757 | /** |
| 758 | * Try to parse another rule/query that matches our request. |
| 759 | * |
| 760 | * @since x.x.x |
| 761 | */ |
| 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 query |
| 768 | $this->parse_request(); |
| 769 | $this->query_posts(); |
| 770 | $this->handle_404(); |
| 771 | } |
| 772 | |
| 773 | return false; |
| 774 | } |
| 775 | |
721 | 776 | /** |
722 | 777 | * Sets up all of the variables required by the WordPress environment. |
723 | 778 | * |
… |
… |
class WP { |
730 | 785 | * @param string|array $query_args Passed to parse_request(). |
731 | 786 | */ |
732 | 787 | public function main( $query_args = '' ) { |
| 788 | |
| 789 | add_action( 'pre_handle_404', array($this, 'maybe_try_another_matched_rule'), 10, 2 ); |
| 790 | |
733 | 791 | $this->init(); |
734 | 792 | $this->parse_request( $query_args ); |
735 | 793 | $this->send_headers(); |