Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison where static strings are involved.

This reduces the number of WordPress.PHP.StrictComparisons.LooseComparison issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

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

    r47617 r47808  
    641641    }
    642642    $data = trim( $data );
    643     if ( 'N;' == $data ) {
     643    if ( 'N;' === $data ) {
    644644        return true;
    645645    }
     
    15181518 */
    15191519function bool_from_yn( $yn ) {
    1520     return ( strtolower( $yn ) == 'y' );
     1520    return ( 'y' === strtolower( $yn ) );
    15211521}
    15221522
     
    15411541    $feed = preg_replace( '/^_+/', '', $feed );
    15421542
    1543     if ( '' == $feed || 'feed' === $feed ) {
     1543    if ( '' === $feed || 'feed' === $feed ) {
    15441544        $feed = get_default_feed();
    15451545    }
     
    18421842        echo $referer_field;
    18431843    }
     1844
    18441845    return $referer_field;
    18451846}
     
    18611862function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
    18621863    $ref = wp_get_original_referer();
     1864
    18631865    if ( ! $ref ) {
    1864         $ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
    1865     }
     1866        $ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
     1867    }
     1868
    18661869    $orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
     1870
    18671871    if ( $echo ) {
    18681872        echo $orig_referer_field;
    18691873    }
     1874
    18701875    return $orig_referer_field;
    18711876}
     
    19731978    // We need to find the permissions of the parent folder that exists and inherit that.
    19741979    $target_parent = dirname( $target );
    1975     while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
     1980    while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
    19761981        $target_parent = dirname( $target_parent );
    19771982    }
     
    23352340    $upload_path = trim( get_option( 'upload_path' ) );
    23362341
    2337     if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
     2342    if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
    23382343        $dir = WP_CONTENT_DIR . '/uploads';
    23392344    } elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
     
    23462351    $url = get_option( 'upload_url_path' );
    23472352    if ( ! $url ) {
    2348         if ( empty( $upload_path ) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) {
     2353        if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) {
    23492354            $url = WP_CONTENT_URL . '/uploads';
    23502355        } else {
     
    32123217 */
    32133218function wp_nonce_ays( $action ) {
    3214     if ( 'log-out' == $action ) {
     3219    if ( 'log-out' === $action ) {
    32153220        $html = sprintf(
    32163221            /* translators: %s: Site title. */
     
    35403545
    35413546        <?php
    3542         if ( 'rtl' == $text_direction ) {
     3547        if ( 'rtl' === $text_direction ) {
    35433548            echo 'body { font-family: Tahoma, Arial; }';
    35443549        }
     
    43344339        // New subpattern?
    43354340        if ( $firstchar != $subchar ) {
    4336             if ( '' != $subchar ) {
     4341            if ( '' !== $subchar ) {
    43374342                $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern".
    43384343                $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
     
    52155220    $server_parts    = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
    52165221    $server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
    5217     return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
     5222
     5223    return ( 'lighttpd' === $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ) );
    52185224}
    52195225
     
    52495255        }
    52505256    }
     5257
    52515258    return $default;
    52525259}
     
    52755282         * via ISAPI then pretty permalinks will not work.
    52765283         */
    5277         $supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( PHP_SAPI == 'cgi-fcgi' );
     5284        $supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
    52785285    }
    52795286
     
    53255332
    53265333    // Absolute Windows drive paths are not allowed:
    5327     if ( ':' == substr( $file, 1, 1 ) ) {
     5334    if ( ':' === substr( $file, 1, 1 ) ) {
    53285335        return 2;
    53295336    }
     
    53655372 */
    53665373function wp_guess_url() {
    5367     if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL ) {
     5374    if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
    53685375        $url = WP_SITEURL;
    53695376    } else {
     
    53765383
    53775384            // The request is for a file in ABSPATH.
    5378         } elseif ( $script_filename_dir . '/' == $abspath_fix ) {
     5385        } elseif ( $script_filename_dir . '/' === $abspath_fix ) {
    53795386            // Strip off any file/query params in the path.
    53805387            $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
     
    59365943        $del_post = get_post( $post_id );
    59375944
    5938         if ( ! $del_post || 'trash' != $del_post->post_status ) {
     5945        if ( ! $del_post || 'trash' !== $del_post->post_status ) {
    59395946            delete_post_meta( $post_id, '_wp_trash_meta_status' );
    59405947            delete_post_meta( $post_id, '_wp_trash_meta_time' );
     
    59545961        $del_comment = get_comment( $comment_id );
    59555962
    5956         if ( ! $del_comment || 'trash' != $del_comment->comment_approved ) {
     5963        if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
    59575964            delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
    59585965            delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
Note: See TracChangeset for help on using the changeset viewer.