Make WordPress Core

Ticket #48223: 48223.1.diff

File 48223.1.diff, 6.5 KB (added by apedog, 4 years ago)

48223.1.diff fixes some errors in 48223.diff and replaces it

  • 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.php
    2 index 508fae2f03..e2ee96404c 100644
    3 --- a/wp-includes/class-wp.php
    4 +++ b/wp-includes/class-wp.php
    5 @@ -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.x
    13 +        * @var string[]
    14 +        */
    15 +       public $matched_rules;
    16 +
    17 +       /**
    18 +        * Array of all potential matched rules found.
    19 +        *
    20 +        * @since x.x.x
    21 +        * @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 ^$ regex
    40                                 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 here
    70 +                       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.x
    90 +        */
    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 query
    97 +                       $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 { 
    6666         */
    6767        public $matched_rule;
    6868
    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 
    8569        /**
    8670         * Rewrite query the request matched.
    8771         *
    class WP { 
    221205
    222206                        // Look for matches.
    223207                        $request_match = $requested_path;
    224 
    225                         if ( ! isset( $this->all_matched_rules ) ){
    226                                 $this->all_matched_rules = array();
    227                         }
    228 
    229208                        if ( empty( $request_match ) ) {
    230209                                // An empty request could only match against ^$ regex
    231210                                if ( isset( $rewrite['$'] ) ) {
    232                                         $this->all_matched_rules[] = '$';
     211                                        $this->matched_rule = '$';
    233212                                        $query              = $rewrite['$'];
    234213                                        $matches            = array( '' );
    235                                         $this->matched_rules = $this->all_matched_rules;
    236214                                }
    237                         } else if ( empty( $this->all_matched_rules ) ){
     215                        } else {
    238216                                foreach ( (array) $rewrite as $match => $query ) {
    239217                                        // If the requested file is the anchor of the match, prepend it to the path info.
    240218                                        if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) {
    class WP { 
    258236                                                        }
    259237                                                }
    260238
    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;
    267242                                        }
    268                                         $this->matched_rules = $this->all_matched_rules;
    269243                                }
    270244                        }
    271245
    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 
    282246                        if ( isset( $this->matched_rule ) ) {
    283247                                // Trim the query of everything up to the '?'.
    284248                                $query = preg_replace( '!^.+\?!', '', $query );
    class WP { 
    754718                nocache_headers();
    755719        }
    756720
    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 
    776721        /**
    777722         * Sets up all of the variables required by the WordPress environment.
    778723         *
    class WP { 
    785730         * @param string|array $query_args Passed to parse_request().
    786731         */
    787732        public function main( $query_args = '' ) {
    788 
    789                 add_action( 'pre_handle_404', array($this, 'maybe_try_another_matched_rule'), 10, 2 );
    790 
    791733                $this->init();
    792734                $this->parse_request( $query_args );
    793735                $this->send_headers();