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.


git-svn-id: https://develop.svn.wordpress.org/trunk@37356 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Eric Andrew Lewis 2016-05-03 19:35:20 +00:00
parent 20715283ce
commit 9e504d6476
1 changed files with 10 additions and 9 deletions

View File

@ -56,7 +56,7 @@ class WP {
public $query_string;
/**
* Permalink or requested URI.
* The request path, e.g. `2015/05/06`.
*
* @since 2.0.0
* @access public
@ -202,18 +202,19 @@ class WP {
// The requested permalink is in $pathinfo for path info requests and
// $req_uri for other requests.
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
$request = $pathinfo;
$requested_path = $pathinfo;
} else {
// If the request uri is the index, blank it out so that we don't try to match it against a rule.
if ( $req_uri == $wp_rewrite->index )
$req_uri = '';
$request = $req_uri;
$requested_path = $req_uri;
}
$requested_file = $req_uri;
$this->request = $request;
$this->request = $requested_path;
// Look for matches.
$request_match = $request;
$request_match = $requested_path;
if ( empty( $request_match ) ) {
// An empty request could only match against ^$ regex
if ( isset( $rewrite['$'] ) ) {
@ -223,9 +224,9 @@ class WP {
}
} else {
foreach ( (array) $rewrite as $match => $query ) {
// If the requesting file is the anchor of the match, prepend it to the path info.
if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
$request_match = $req_uri . '/' . $request;
// If the requested file is the anchor of the match, prepend it to the path info.
if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )
$request_match = $requested_file . '/' . $requested_path;
if ( preg_match("#^$match#", $request_match, $matches) ||
preg_match("#^$match#", urldecode($request_match), $matches) ) {
@ -269,7 +270,7 @@ class WP {
}
// If req_uri is empty or if it is a request for ourself, unset error.
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
if ( empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
unset( $error, $_GET['error'] );
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )