@@ -205,11 +205,13 @@ public function parse_request( $extra_query_vars = '' ) {
205205 $ 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.
208- if ( $ req_uri == $ wp_rewrite ->index ) {
208+ if ( $ req_uri === $ wp_rewrite ->index ) {
209209 $ req_uri = '' ;
210210 }
211+
211212 $ requested_path = $ req_uri ;
212213 }
214+
213215 $ requested_file = $ req_uri ;
214216
215217 $ this ->request = $ requested_path ;
@@ -226,23 +228,32 @@ public function parse_request( $extra_query_vars = '' ) {
226228 } else {
227229 foreach ( (array ) $ rewrite as $ match => $ query ) {
228230 // If the requested file is the anchor of the match, prepend it to the path info.
229- if ( ! empty ( $ requested_file ) && str_starts_with ( $ match , $ requested_file ) && $ requested_file != $ requested_path ) {
231+ if ( ! empty ( $ requested_file )
232+ && str_starts_with ( $ match , $ requested_file )
233+ && $ requested_file !== $ requested_path
234+ ) {
230235 $ request_match = $ requested_file . '/ ' . $ requested_path ;
231236 }
232237
233- if ( preg_match ( "#^ $ match# " , $ request_match , $ matches ) ||
234- preg_match ( "#^ $ match# " , urldecode ( $ request_match ), $ matches ) ) {
238+ if ( preg_match ( "#^ $ match# " , $ request_match , $ matches )
239+ || preg_match ( "#^ $ match# " , urldecode ( $ request_match ), $ matches )
240+ ) {
235241
236- if ( $ wp_rewrite ->use_verbose_page_rules && preg_match ( '/pagename=\$matches\[([0-9]+)\]/ ' , $ query , $ varmatch ) ) {
242+ if ( $ wp_rewrite ->use_verbose_page_rules
243+ && preg_match ( '/pagename=\$matches\[([0-9]+)\]/ ' , $ query , $ varmatch )
244+ ) {
237245 // This is a verbose page match, let's check to be sure about it.
238246 $ page = get_page_by_path ( $ matches [ $ varmatch [1 ] ] );
247+
239248 if ( ! $ page ) {
240249 continue ;
241250 }
242251
243252 $ post_status_obj = get_post_status_object ( $ page ->post_status );
253+
244254 if ( ! $ post_status_obj ->public && ! $ post_status_obj ->protected
245- && ! $ post_status_obj ->private && $ post_status_obj ->exclude_from_search ) {
255+ && ! $ post_status_obj ->private && $ post_status_obj ->exclude_from_search
256+ ) {
246257 continue ;
247258 }
248259 }
@@ -267,13 +278,15 @@ public function parse_request( $extra_query_vars = '' ) {
267278 parse_str ( $ query , $ perma_query_vars );
268279
269280 // If we're processing a 404 request, clear the error var since we found something.
270- if ( '404 ' == $ error ) {
281+ if ( '404 ' === $ error ) {
271282 unset( $ error , $ _GET ['error ' ] );
272283 }
273284 }
274285
275286 // If req_uri is empty or if it is a request for ourself, unset error.
276- if ( empty ( $ requested_path ) || $ requested_file == $ self || str_contains ( $ _SERVER ['PHP_SELF ' ], 'wp-admin/ ' ) ) {
287+ if ( empty ( $ requested_path ) || $ requested_file === $ self
288+ || str_contains ( $ _SERVER ['PHP_SELF ' ], 'wp-admin/ ' )
289+ ) {
277290 unset( $ error , $ _GET ['error ' ] );
278291
279292 if ( isset ( $ perma_query_vars ) && str_contains ( $ _SERVER ['PHP_SELF ' ], 'wp-admin/ ' ) ) {
@@ -306,8 +319,14 @@ public function parse_request( $extra_query_vars = '' ) {
306319 foreach ( $ this ->public_query_vars as $ wpvar ) {
307320 if ( isset ( $ this ->extra_query_vars [ $ wpvar ] ) ) {
308321 $ this ->query_vars [ $ wpvar ] = $ this ->extra_query_vars [ $ wpvar ];
309- } elseif ( isset ( $ _GET [ $ wpvar ] ) && isset ( $ _POST [ $ wpvar ] ) && $ _GET [ $ wpvar ] !== $ _POST [ $ wpvar ] ) {
310- wp_die ( __ ( 'A variable mismatch has been detected. ' ), __ ( 'Sorry, you are not allowed to view this item. ' ), 400 );
322+ } elseif ( isset ( $ _GET [ $ wpvar ] ) && isset ( $ _POST [ $ wpvar ] )
323+ && $ _GET [ $ wpvar ] !== $ _POST [ $ wpvar ]
324+ ) {
325+ wp_die (
326+ __ ( 'A variable mismatch has been detected. ' ),
327+ __ ( 'Sorry, you are not allowed to view this item. ' ),
328+ 400
329+ );
311330 } elseif ( isset ( $ _POST [ $ wpvar ] ) ) {
312331 $ this ->query_vars [ $ wpvar ] = $ _POST [ $ wpvar ];
313332 } elseif ( isset ( $ _GET [ $ wpvar ] ) ) {
@@ -357,6 +376,7 @@ public function parse_request( $extra_query_vars = '' ) {
357376 // Limit publicly queried post_types to those that are 'publicly_queryable'.
358377 if ( isset ( $ this ->query_vars ['post_type ' ] ) ) {
359378 $ queryable_post_types = get_post_types ( array ( 'publicly_queryable ' => true ) );
379+
360380 if ( ! is_array ( $ this ->query_vars ['post_type ' ] ) ) {
361381 if ( ! in_array ( $ this ->query_vars ['post_type ' ], $ queryable_post_types , true ) ) {
362382 unset( $ this ->query_vars ['post_type ' ] );
@@ -434,10 +454,12 @@ public function send_headers() {
434454 }
435455 if ( ! empty ( $ this ->query_vars ['error ' ] ) ) {
436456 $ status = (int ) $ this ->query_vars ['error ' ];
457+
437458 if ( 404 === $ status ) {
438459 if ( ! is_user_logged_in () ) {
439460 $ headers = array_merge ( $ headers , wp_get_nocache_headers () );
440461 }
462+
441463 $ headers ['Content-Type ' ] = get_option ( 'html_type ' ) . '; charset= ' . get_option ( 'blog_charset ' );
442464 } elseif ( in_array ( $ status , array ( 403 , 500 , 502 , 503 ), true ) ) {
443465 $ exit_required = true ;
@@ -450,6 +472,7 @@ public function send_headers() {
450472 if ( 'feed ' === $ this ->query_vars ['feed ' ] ) {
451473 $ type = get_default_feed ();
452474 }
475+
453476 $ headers ['Content-Type ' ] = feed_content_type ( $ type ) . '; charset= ' . get_option ( 'blog_charset ' );
454477
455478 // We're showing a feed, so WP is indeed the only thing that last changed.
@@ -467,6 +490,7 @@ public function send_headers() {
467490 ) {
468491 $ wp_last_modified_post = mysql2date ( $ date_format , get_lastpostmodified ( 'GMT ' ), false );
469492 $ wp_last_modified_comment = mysql2date ( $ date_format , get_lastcommentmodified ( 'GMT ' ), false );
493+
470494 if ( strtotime ( $ wp_last_modified_post ) > strtotime ( $ wp_last_modified_comment ) ) {
471495 $ wp_last_modified = $ wp_last_modified_post ;
472496 } else {
@@ -501,8 +525,9 @@ public function send_headers() {
501525 $ wp_modified_timestamp = strtotime ( $ wp_last_modified );
502526
503527 if ( ( $ client_last_modified && $ client_etag ) ?
504- ( ( $ client_modified_timestamp >= $ wp_modified_timestamp ) && ( $ client_etag == $ wp_etag ) ) :
505- ( ( $ client_modified_timestamp >= $ wp_modified_timestamp ) || ( $ client_etag == $ wp_etag ) ) ) {
528+ ( ( $ client_modified_timestamp >= $ wp_modified_timestamp ) && ( $ client_etag === $ wp_etag ) ) :
529+ ( ( $ client_modified_timestamp >= $ wp_modified_timestamp ) || ( $ client_etag === $ wp_etag ) )
530+ ) {
506531 $ status = 304 ;
507532 $ exit_required = true ;
508533 }
@@ -570,12 +595,15 @@ public function send_headers() {
570595 */
571596 public function build_query_string () {
572597 $ this ->query_string = '' ;
598+
573599 foreach ( (array ) array_keys ( $ this ->query_vars ) as $ wpvar ) {
574- if ( '' != $ this ->query_vars [ $ wpvar ] ) {
600+ if ( '' !== $ this ->query_vars [ $ wpvar ] ) {
575601 $ this ->query_string .= ( strlen ( $ this ->query_string ) < 1 ) ? '' : '& ' ;
602+
576603 if ( ! is_scalar ( $ this ->query_vars [ $ wpvar ] ) ) { // Discard non-scalars.
577604 continue ;
578605 }
606+
579607 $ this ->query_string .= $ wpvar . '= ' . rawurlencode ( $ this ->query_vars [ $ wpvar ] );
580608 }
581609 }
@@ -595,6 +623,7 @@ public function build_query_string() {
595623 '2.1.0 ' ,
596624 'query_vars, request '
597625 );
626+
598627 parse_str ( $ this ->query_string , $ this ->query_vars );
599628 }
600629 }
0 commit comments