<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56362] trunk/src/wp-includes/class-wp.php: Coding Standards: Use strict comparison in `wp-includes/class-wp.php`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56362">56362</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56362","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-08-07 09:59:20 +0000 (Mon, 07 Aug 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Coding Standards: Use strict comparison in `wp-includes/class-wp.php`.

Includes minor code layout fixes for better readability.

Follow-up to <a href="https://core.trac.wordpress.org/changeset/1043">[1043]</a>, <a href="https://core.trac.wordpress.org/changeset/2534">[2534]</a>, <a href="https://core.trac.wordpress.org/changeset/2584">[2584]</a>, <a href="https://core.trac.wordpress.org/changeset/2627">[2627]</a>, <a href="https://core.trac.wordpress.org/changeset/2958">[2958]</a>, <a href="https://core.trac.wordpress.org/changeset/3252">[3252]</a>, <a href="https://core.trac.wordpress.org/changeset/3564">[3564]</a>, <a href="https://core.trac.wordpress.org/changeset/21818">[21818]</a>, <a href="https://core.trac.wordpress.org/changeset/37356">[37356]</a>.

Props aristath, poena, afercia, SergeyBiryukov.
See <a href="https://core.trac.wordpress.org/ticket/58831">#58831</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpphp">trunk/src/wp-includes/class-wp.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp.php        2023-08-06 12:50:42 UTC (rev 56361)
+++ trunk/src/wp-includes/class-wp.php  2023-08-07 09:59:20 UTC (rev 56362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -205,11 +205,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $requested_path = $pathinfo;
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><span class="cx" style="display: block; padding: 0 10px">                                // If the request uri is the index, blank it out so that we don't try to match it against a rule.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( $req_uri == $wp_rewrite->index ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $req_uri === $wp_rewrite->index ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $req_uri = '';
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $requested_path = $req_uri;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $requested_file = $req_uri;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->request = $requested_path;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -226,23 +228,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><span class="cx" style="display: block; padding: 0 10px">                                foreach ( (array) $rewrite as $match => $query ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        // If the requested file is the anchor of the match, prepend it to the path info.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( ! empty( $requested_file ) && str_starts_with( $match, $requested_file ) && $requested_file != $requested_path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( ! empty( $requested_file )
+                                               && str_starts_with( $match, $requested_file )
+                                               && $requested_file !== $requested_path
+                                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 $request_match = $requested_file . '/' . $requested_path;
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( preg_match( "#^$match#", $request_match, $matches ) ||
-                                               preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( preg_match( "#^$match#", $request_match, $matches )
+                                               || preg_match( "#^$match#", urldecode( $request_match ), $matches )
+                                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( $wp_rewrite->use_verbose_page_rules
+                                                       && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch )
+                                               ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         // This is a verbose page match, let's check to be sure about it.
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $page = get_page_by_path( $matches[ $varmatch[1] ] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         if ( ! $page ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $post_status_obj = get_post_status_object( $page->post_status );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         if ( ! $post_status_obj->public && ! $post_status_obj->protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                                && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                         && ! $post_status_obj->private && $post_status_obj->exclude_from_search
+                                                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                                 continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -267,13 +278,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                parse_str( $query, $perma_query_vars );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                // If we're processing a 404 request, clear the error var since we found something.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( '404' == $error ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( '404' === $error ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         unset( $error, $_GET['error'] );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // If req_uri is empty or if it is a request for ourself, unset error.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( empty( $requested_path ) || $requested_file == $self || str_contains( $_SERVER['PHP_SELF'], 'wp-admin/' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( empty( $requested_path ) || $requested_file === $self
+                               || str_contains( $_SERVER['PHP_SELF'], 'wp-admin/' )
+                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 unset( $error, $_GET['error'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( isset( $perma_query_vars ) && str_contains( $_SERVER['PHP_SELF'], 'wp-admin/' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,8 +319,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $this->public_query_vars as $wpvar ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( isset( $this->extra_query_vars[ $wpvar ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        } elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) {
-                               wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] )
+                               && $_GET[ $wpvar ] !== $_POST[ $wpvar ]
+                       ) {
+                               wp_die(
+                                       __( 'A variable mismatch has been detected.' ),
+                                       __( 'Sorry, you are not allowed to view this item.' ),
+                                       400
+                               );
</ins><span class="cx" style="display: block; padding: 0 10px">                         } elseif ( isset( $_POST[ $wpvar ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->query_vars[ $wpvar ] = $_POST[ $wpvar ];
</span><span class="cx" style="display: block; padding: 0 10px">                        } elseif ( isset( $_GET[ $wpvar ] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -357,6 +376,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Limit publicly queried post_types to those that are 'publicly_queryable'.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $this->query_vars['post_type'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $queryable_post_types = get_post_types( array( 'publicly_queryable' => true ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( ! is_array( $this->query_vars['post_type'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types, true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        unset( $this->query_vars['post_type'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -434,10 +454,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $this->query_vars['error'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $status = (int) $this->query_vars['error'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( 404 === $status ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( ! is_user_logged_in() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $headers = array_merge( $headers, wp_get_nocache_headers() );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );
</span><span class="cx" style="display: block; padding: 0 10px">                        } elseif ( in_array( $status, array( 403, 500, 502, 503 ), true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $exit_required = true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -450,6 +472,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 'feed' === $this->query_vars['feed'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $type = get_default_feed();
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers['Content-Type'] = feed_content_type( $type ) . '; charset=' . get_option( 'blog_charset' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // We're showing a feed, so WP is indeed the only thing that last changed.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -467,6 +490,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $wp_last_modified_post    = mysql2date( $date_format, get_lastpostmodified( 'GMT' ), false );
</span><span class="cx" style="display: block; padding: 0 10px">                                $wp_last_modified_comment = mysql2date( $date_format, get_lastcommentmodified( 'GMT' ), false );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( strtotime( $wp_last_modified_post ) > strtotime( $wp_last_modified_comment ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $wp_last_modified = $wp_last_modified_post;
</span><span class="cx" style="display: block; padding: 0 10px">                                } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -501,8 +525,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $wp_modified_timestamp = strtotime( $wp_last_modified );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ( $client_last_modified && $client_etag ) ?
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag ) ) :
-                                       ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) ) :
+                                       ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) )
+                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $status        = 304;
</span><span class="cx" style="display: block; padding: 0 10px">                                $exit_required = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -570,12 +595,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function build_query_string() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->query_string = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( (array) array_keys( $this->query_vars ) as $wpvar ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( '' != $this->query_vars[ $wpvar ] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( '' !== $this->query_vars[ $wpvar ] ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $this->query_string .= ( strlen( $this->query_string ) < 1 ) ? '' : '&';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( ! is_scalar( $this->query_vars[ $wpvar ] ) ) { // Discard non-scalars.
</span><span class="cx" style="display: block; padding: 0 10px">                                        continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $this->query_string .= $wpvar . '=' . rawurlencode( $this->query_vars[ $wpvar ] );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -595,6 +623,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                '2.1.0',
</span><span class="cx" style="display: block; padding: 0 10px">                                'query_vars, request'
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         parse_str( $this->query_string, $this->query_vars );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre>
</div>
</div>

</body>
</html>