Ticket #12405: 12405.2.diff
| File 12405.2.diff, 4.4 KB (added by mdawaffe, 3 years ago) |
|---|
-
wp-includes/rewrite.php
1281 1281 * @return array Rewrite rule list. 1282 1282 */ 1283 1283 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { 1284 $permalink_structure = preg_quote( $permalink_structure, '#' ); 1285 1284 1286 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/? 1285 1287 $feedregex2 = ''; 1286 1288 foreach ( (array) $this->feeds as $feed_name) { -
wp-includes/classes.php
193 193 $request = $req_uri; 194 194 } 195 195 196 if ( false !== strpos( $wp_rewrite->permalink_structure, '?' ) && !empty( $_SERVER['QUERY_STRING'] ) ) { 197 list( $qs ) = explode( '&', $_SERVER['QUERY_STRING'], 2 ); // only want the first piece 198 if ( false === strpos( $qs, '=' ) ) { // otherwise it's some non-permalink query arg 199 $request_no_qs = $request; 200 $request .= '?' . $qs; 201 } 202 } else { 203 $request_no_qs = false; 204 } 205 196 206 $this->request = $request; 207 $fallback = false; 208 $fallback_query = false; 197 209 198 210 // Look for matches. 199 211 $request_match = $request; 212 $request_match_no_qs = $request_no_qs; 213 200 214 foreach ( (array) $rewrite as $match => $query) { 215 $match = preg_replace( '#\[\^([^\]])+\]#', '[^\\1?]', $match ); 216 $match = str_replace( array( '.*', '.+' ), array( '[^?]*', '[^?]+' ), $match ); 201 217 // Don't try to match against AtomPub calls 202 218 if ( $req_uri == 'wp-app.php' ) 203 219 break; 204 220 205 221 // If the requesting file is the anchor of the match, prepend it 206 222 // to the path info. 207 if ( (! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request) ) 223 if ( (! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request) ) { 208 224 $request_match = $req_uri . '/' . $request; 225 if ( $request_match_no_qs ) 226 $request_match_no_qs = $req_uri . '/' . $request_no_qs; 227 } 209 228 210 229 if ( preg_match("#^$match#", $request_match, $matches) || 211 230 preg_match("#^$match#", urldecode($request_match), $matches) ) { 212 231 // Got a match. 213 232 $this->matched_rule = $match; 233 break; 234 } elseif ( $request_match_no_qs && !$fallback && ( preg_match("#^$match#", $request_match, $matches) || 235 preg_match("#^$match#", urldecode($request_match), $matches) ) ) { 236 // Got a match, but there might be a better one in the other branch 237 $fallback = $match; 238 $fallback_query = $query; 239 continue; 240 } 241 } 214 242 215 // Trim the query of everything up to the '?'. 216 $query = preg_replace("!^.+\?!", '', $query); 243 if ( !$this->matched_rule && $fallback ) { // 2nd branch had the only match 244 $this->matched_rule = $fallback; 245 $query = $fallback_query; 246 } 217 247 218 // Substitute the substring matches into the query. 219 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); 248 if ( $this->matched_rule ) { 249 // Trim the query of everything up to the '?'. 250 $query = preg_replace("!^.+\?!", '', $query); 220 251 221 $this->matched_query = $query; 252 // Substitute the substring matches into the query. 253 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); 222 254 223 // Parse the query. 224 parse_str($query, $perma_query_vars); 255 $this->matched_query = $query; 225 256 226 // If we're processing a 404 request, clear the error var 227 // since we found something. 228 if ( isset($_GET['error']) ) 229 unset($_GET['error']); 257 // Parse the query. 258 parse_str($query, $perma_query_vars); 230 259 231 if ( isset($error) ) 232 unset($error); 260 // If we're processing a 404 request, clear the error var 261 // since we found something. 262 if ( isset($_GET['error']) ) 263 unset($_GET['error']); 233 264 234 break;235 }265 if ( isset($error) ) 266 unset($error); 236 267 } 237 268 238 269 // If req_uri is empty or if it is a request for ourself, unset error. 239 if ( empty($request ) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {270 if ( empty($request_no_qs) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) { 240 271 if ( isset($_GET['error']) ) 241 272 unset($_GET['error']); 242 273
