Make WordPress Core


Ignore:
Timestamp:
05/03/2016 07:35:20 PM (9 years ago)
Author:
ericlewis
Message:

Rewrite Rules: Add self-describing variables to rewrite matcher.

The rewrite rule matching code in WP::parse_request() used an unclear variable $request to represent the requested path (e.g. "2016/05/03") as well as a deceptively named variable $request_uri, which actually represents the requested file when an install used PATHINFO links.

Those variables are replaced with $requested_path and $requested_file respectively for clarity.

Fixes #36674.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r36900 r37356  
    5757
    5858    /**
    59      * Permalink or requested URI.
     59     * The request path, e.g. `2015/05/06`.
    6060     *
    6161     * @since 2.0.0
     
    203203            //  $req_uri for other requests.
    204204            if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
    205                 $request = $pathinfo;
     205                $requested_path = $pathinfo;
    206206            } else {
    207207                // If the request uri is the index, blank it out so that we don't try to match it against a rule.
    208208                if ( $req_uri == $wp_rewrite->index )
    209209                    $req_uri = '';
    210                 $request = $req_uri;
    211             }
    212 
    213             $this->request = $request;
     210                $requested_path = $req_uri;
     211            }
     212            $requested_file = $req_uri;
     213
     214            $this->request = $requested_path;
    214215
    215216            // Look for matches.
    216             $request_match = $request;
     217            $request_match = $requested_path;
    217218            if ( empty( $request_match ) ) {
    218219                // An empty request could only match against ^$ regex
     
    224225            } else {
    225226                foreach ( (array) $rewrite as $match => $query ) {
    226                     // If the requesting file is the anchor of the match, prepend it to the path info.
    227                     if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
    228                         $request_match = $req_uri . '/' . $request;
     227                    // If the requested file is the anchor of the match, prepend it to the path info.
     228                    if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )
     229                        $request_match = $requested_file . '/' . $requested_path;
    229230
    230231                    if ( preg_match("#^$match#", $request_match, $matches) ||
     
    270271
    271272            // If req_uri is empty or if it is a request for ourself, unset error.
    272             if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
     273            if ( empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
    273274                unset( $error, $_GET['error'] );
    274275
Note: See TracChangeset for help on using the changeset viewer.