Make WordPress Core

Ticket #18877: 18877.2.diff

File 18877.2.diff, 7.6 KB (added by ericlewis, 9 years ago)
  • src/wp-includes/class-wp-rewrite.php

     
    19001900        }
    19011901
    19021902        /**
     1903         * Go through a list of rewrite rules and find a match.
     1904         *
     1905         * @since 3.3.0
     1906         * @access private
     1907         *
     1908         * @param $request
     1909         * @param $req_uri
     1910         * @param array $rewrite Rewrite pairs (regex matches and rewritten query strings).
     1911         */
     1912        public function find_match( $request, $req_uri, $rewrite ) {
     1913                $found_match = false;
     1914                // Look for matches.
     1915                $request_match = $request;
     1916                if ( empty( $request_match ) ) {
     1917                        // An empty request could only match against ^$ regex
     1918                        if ( isset( $rewrite['$'] ) ) {
     1919                                $this->matched_rule = '$';
     1920                                $query = $rewrite['$'];
     1921                                $matches = array('');
     1922                        }
     1923                } else {
     1924                        foreach ( (array) $rewrite as $match => $query ) {
     1925                                // If the requesting file is the anchor of the match, prepend it to the path info.
     1926                                if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
     1927                                        $request_match = $req_uri . '/' . $request;
     1928
     1929                                if ( preg_match("#^$match#", $request_match, $matches) ||
     1930                                        preg_match("#^$match#", urldecode($request_match), $matches) ) {
     1931
     1932                                        if ( $this->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
     1933                                                // This is a verbose page match, let's check to be sure about it.
     1934                                                $page = get_page_by_path( $matches[ $varmatch[1] ] );
     1935                                                if ( ! $page ) {
     1936                                                        continue;
     1937                                                }
     1938
     1939                                                $post_status_obj = get_post_status_object( $page->post_status );
     1940                                                if ( ! $post_status_obj->public && ! $post_status_obj->protected
     1941                                                        && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
     1942                                                        continue;
     1943                                                }
     1944                                        }
     1945
     1946                                        // Got a match.
     1947                                        $found_match = true;
     1948                                        break;
     1949                                }
     1950                        }
     1951                }
     1952
     1953                if ( $found_match ) {
     1954                        // Trim the query of everything up to the '?'.
     1955                        $query = preg_replace("!^.+\?!", '', $query);
     1956
     1957                        // Substitute the substring matches into the query.
     1958                        $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
     1959
     1960                        return array( $match, $query );
     1961                } else {
     1962                        return false;
     1963                }
     1964        }
     1965
     1966        /**
    19031967         * Constructor - Calls init(), which runs setup.
    19041968         *
    19051969         * @since 1.5.0
  • src/wp-includes/class-wp.php

     
    189189
    190190                        $this->request = $request;
    191191
    192                         // Look for matches.
    193                         $request_match = $request;
    194                         if ( empty( $request_match ) ) {
    195                                 // An empty request could only match against ^$ regex
    196                                 if ( isset( $rewrite['$'] ) ) {
    197                                         $this->matched_rule = '$';
    198                                         $query = $rewrite['$'];
    199                                         $matches = array('');
    200                                 }
    201                         } else {
    202                                 foreach ( (array) $rewrite as $match => $query ) {
    203                                         // If the requesting file is the anchor of the match, prepend it to the path info.
    204                                         if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
    205                                                 $request_match = $req_uri . '/' . $request;
     192                        $result = $wp_rewrite->find_match( $request, $req_uri, $rewrite );
    206193
    207                                         if ( preg_match("#^$match#", $request_match, $matches) ||
    208                                                 preg_match("#^$match#", urldecode($request_match), $matches) ) {
     194                        if ( $result ) {
     195                                $this->matched_rule = $result[0];
     196                                $this->matched_query = $result[1];
    209197
    210                                                 if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
    211                                                         // This is a verbose page match, let's check to be sure about it.
    212                                                         $page = get_page_by_path( $matches[ $varmatch[1] ] );
    213                                                         if ( ! $page ) {
    214                                                                 continue;
    215                                                         }
    216 
    217                                                         $post_status_obj = get_post_status_object( $page->post_status );
    218                                                         if ( ! $post_status_obj->public && ! $post_status_obj->protected
    219                                                                 && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
    220                                                                 continue;
    221                                                         }
    222                                                 }
    223 
    224                                                 // Got a match.
    225                                                 $this->matched_rule = $match;
    226                                                 break;
    227                                         }
    228                                 }
    229                         }
    230 
    231                         if ( isset( $this->matched_rule ) ) {
    232                                 // Trim the query of everything up to the '?'.
    233                                 $query = preg_replace("!^.+\?!", '', $query);
    234 
    235                                 // Substitute the substring matches into the query.
    236                                 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
    237 
    238                                 $this->matched_query = $query;
    239 
    240198                                // Parse the query.
    241                                 parse_str($query, $perma_query_vars);
     199                                parse_str($this->matched_query, $perma_query_vars);
    242200
    243201                                // If we're processing a 404 request, clear the error var since we found something.
    244202                                if ( '404' == $error )
  • src/wp-includes/rewrite.php

     
    497497        }
    498498
    499499        // Look for matches.
    500         $request_match = $request;
    501         foreach ( (array)$rewrite as $match => $query) {
     500        $result = $wp_rewrite->find_match( $request, $url, $rewrite );
     501        if ( $result ) {
     502                // Got a match.
     503                $match = $result[0];
     504                $query = $result[1];
    502505
    503                 // If the requesting file is the anchor of the match, prepend it
    504                 // to the path info.
    505                 if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) )
    506                         $request_match = $url . '/' . $request;
    507 
    508                 if ( preg_match("#^$match#", $request_match, $matches) ) {
    509 
    510                         if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
    511                                 // This is a verbose page match, let's check to be sure about it.
    512                                 $page = get_page_by_path( $matches[ $varmatch[1] ] );
    513                                 if ( ! $page ) {
    514                                         continue;
     506                // Filter out non-public query vars
     507                global $wp;
     508                parse_str( $query, $query_vars );
     509                $query = array();
     510                foreach ( (array) $query_vars as $key => $value ) {
     511                        if ( in_array( $key, $wp->public_query_vars ) ){
     512                                $query[$key] = $value;
     513                                if ( isset( $post_type_query_vars[$key] ) ) {
     514                                        $query['post_type'] = $post_type_query_vars[$key];
     515                                        $query['name'] = $value;
    515516                                }
    516 
    517                                 $post_status_obj = get_post_status_object( $page->post_status );
    518                                 if ( ! $post_status_obj->public && ! $post_status_obj->protected
    519                                         && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
    520                                         continue;
    521                                 }
    522517                        }
     518                }
    523519
    524                         // Got a match.
    525                         // Trim the query of everything up to the '?'.
    526                         $query = preg_replace("!^.+\?!", '', $query);
     520                // Resolve conflicts between posts with numeric slugs and date archive queries.
     521                $query = wp_resolve_numeric_slug_conflicts( $query );
    527522
    528                         // Substitute the substring matches into the query.
    529                         $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
    530 
    531                         // Filter out non-public query vars
    532                         global $wp;
    533                         parse_str( $query, $query_vars );
    534                         $query = array();
    535                         foreach ( (array) $query_vars as $key => $value ) {
    536                                 if ( in_array( $key, $wp->public_query_vars ) ){
    537                                         $query[$key] = $value;
    538                                         if ( isset( $post_type_query_vars[$key] ) ) {
    539                                                 $query['post_type'] = $post_type_query_vars[$key];
    540                                                 $query['name'] = $value;
    541                                         }
    542                                 }
    543                         }
    544 
    545                         // Resolve conflicts between posts with numeric slugs and date archive queries.
    546                         $query = wp_resolve_numeric_slug_conflicts( $query );
    547 
    548                         // Do the query
    549                         $query = new WP_Query( $query );
    550                         if ( ! empty( $query->posts ) && $query->is_singular )
    551                                 return $query->post->ID;
    552                         else
    553                                 return 0;
    554                 }
     523                // Do the query
     524                $query = new WP_Query( $query );
     525                if ( ! empty( $query->posts ) && $query->is_singular )
     526                        return $query->post->ID;
     527                else
     528                        return 0;
    555529        }
    556530        return 0;
    557531}