Skip to content

Commit

Permalink
Coding Standards: Use strict comparison where static strings are invo…
Browse files Browse the repository at this point in the history
…lved.

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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47808 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 16, 2020
1 parent 36e4db6 commit 6742d0d
Show file tree
Hide file tree
Showing 160 changed files with 1,144 additions and 1,008 deletions.
2 changes: 1 addition & 1 deletion src/wp-admin/admin-header.php
Expand Up @@ -147,7 +147,7 @@
*/
do_action( 'admin_head' );

if ( get_user_setting( 'mfold' ) === 'f' ) {
if ( 'f' === get_user_setting( 'mfold' ) ) {
$admin_body_class .= ' folded';
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/edit-form-advanced.php
Expand Up @@ -59,7 +59,7 @@

wp_enqueue_script( 'editor-expand' );
$_content_editor_dfw = true;
$_wp_editor_expand = ( get_user_setting( 'editor_expand', 'on' ) === 'on' );
$_wp_editor_expand = ( 'on' === get_user_setting( 'editor_expand', 'on' ) );
}

if ( wp_is_mobile() ) {
Expand Down
54 changes: 27 additions & 27 deletions src/wp-admin/includes/ajax-actions.php
Expand Up @@ -176,7 +176,7 @@ function wp_ajax_wp_compression_test() {
wp_die( -1 );
}

if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' == ini_get( 'output_handler' ) ) {
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
update_site_option( 'can_compress_scripts', 0 );
wp_die( 0 );
}
Expand Down Expand Up @@ -209,10 +209,10 @@ function wp_ajax_wp_compression_test() {

echo $out;
wp_die();
} elseif ( 'no' == $_GET['test'] ) {
} elseif ( 'no' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' );
update_site_option( 'can_compress_scripts', 0 );
} elseif ( 'yes' == $_GET['test'] ) {
} elseif ( 'yes' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' );
update_site_option( 'can_compress_scripts', 1 );
}
Expand Down Expand Up @@ -704,13 +704,13 @@ function wp_ajax_delete_comment() {
$delta = -1;

if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) {
if ( 'trash' == $status ) {
if ( 'trash' === $status ) {
wp_die( time() );
}

$r = wp_trash_comment( $comment );
} elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) {
if ( 'trash' != $status ) {
if ( 'trash' !== $status ) {
wp_die( time() );
}

Expand All @@ -721,13 +721,13 @@ function wp_ajax_delete_comment() {
$delta = 1;
}
} elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) {
if ( 'spam' == $status ) {
if ( 'spam' === $status ) {
wp_die( time() );
}

$r = wp_spam_comment( $comment );
} elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) {
if ( 'spam' != $status ) {
if ( 'spam' !== $status ) {
wp_die( time() );
}

Expand Down Expand Up @@ -883,7 +883,7 @@ function wp_ajax_trash_post( $action ) {
wp_die( 1 );
}

if ( 'trash-post' == $action ) {
if ( 'trash-post' === $action ) {
$done = wp_trash_post( $id );
} else {
$done = wp_untrash_post( $id );
Expand Down Expand Up @@ -1301,7 +1301,7 @@ function wp_ajax_replyto_comment( $action ) {
wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
}

if ( '' == $comment_content ) {
if ( '' === $comment_content ) {
wp_die( __( 'Error: Please type a comment.' ) );
}

Expand Down Expand Up @@ -1344,11 +1344,11 @@ function wp_ajax_replyto_comment( $action ) {
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';

ob_start();
if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) {
if ( isset( $_REQUEST['mode'] ) && 'dashboard' === $_REQUEST['mode'] ) {
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
_wp_dashboard_recent_comments_row( $comment );
} else {
if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
if ( isset( $_REQUEST['mode'] ) && 'single' === $_REQUEST['mode'] ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
} else {
$wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
Expand Down Expand Up @@ -1403,7 +1403,7 @@ function wp_ajax_edit_comment() {
wp_die( -1 );
}

if ( '' == $_POST['content'] ) {
if ( '' === $_POST['content'] ) {
wp_die( __( 'Error: Please type a comment.' ) );
}

Expand Down Expand Up @@ -1461,7 +1461,7 @@ function wp_ajax_add_menu_item() {
foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
if (
! empty( $menu_item_data['menu-item-type'] ) &&
'custom' != $menu_item_data['menu-item-type'] &&
'custom' !== $menu_item_data['menu-item-type'] &&
! empty( $menu_item_data['menu-item-object-id'] )
) {
switch ( $menu_item_data['menu-item-type'] ) {
Expand Down Expand Up @@ -1544,7 +1544,7 @@ function wp_ajax_add_meta() {
wp_die( -1 );
}

if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
if ( isset( $_POST['metakeyselect'] ) && '#NONE#' === $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
wp_die( 1 );
}

Expand Down Expand Up @@ -1604,7 +1604,7 @@ function wp_ajax_add_meta() {
$key = wp_unslash( $_POST['meta'][ $mid ]['key'] );
$value = wp_unslash( $_POST['meta'][ $mid ]['value'] );

if ( '' == trim( $key ) ) {
if ( '' === trim( $key ) ) {
wp_die( __( 'Please provide a custom field name.' ) );
}

Expand Down Expand Up @@ -1795,11 +1795,11 @@ function wp_ajax_menu_get_metabox() {

require_once ABSPATH . 'wp-admin/includes/nav-menu.php';

if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
if ( isset( $_POST['item-type'] ) && 'post_type' === $_POST['item-type'] ) {
$type = 'posttype';
$callback = 'wp_nav_menu_item_post_type_meta_box';
$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' === $_POST['item-type'] ) {
$type = 'taxonomy';
$callback = 'wp_nav_menu_item_taxonomy_meta_box';
$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
Expand Down Expand Up @@ -1985,7 +1985,7 @@ function wp_ajax_inline_save() {

$post_ID = (int) $_POST['post_ID'];

if ( 'page' == $_POST['post_type'] ) {
if ( 'page' === $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_ID ) ) {
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
}
Expand Down Expand Up @@ -2030,7 +2030,7 @@ function wp_ajax_inline_save() {
}

// Status.
if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) {
$data['visibility'] = 'private';
$data['post_status'] = 'private';
} else {
Expand Down Expand Up @@ -2180,7 +2180,7 @@ function wp_ajax_find_posts() {
$alt = '';
foreach ( $posts as $post ) {
$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
$alt = ( 'alternate' === $alt ) ? '' : 'alternate';

switch ( $post->post_status ) {
case 'publish':
Expand All @@ -2198,7 +2198,7 @@ function wp_ajax_find_posts() {
break;
}

if ( '0000-00-00 00:00:00' == $post->post_date ) {
if ( '0000-00-00 00:00:00' === $post->post_date ) {
$time = '';
} else {
/* translators: Date format in table columns, see https://www.php.net/date */
Expand Down Expand Up @@ -2883,7 +2883,7 @@ function wp_ajax_get_attachment() {
wp_send_json_error();
}

if ( 'attachment' != $post->post_type ) {
if ( 'attachment' !== $post->post_type ) {
wp_send_json_error();
}

Expand Down Expand Up @@ -2996,7 +2996,7 @@ function wp_ajax_save_attachment() {
$changes = $_REQUEST['changes'];
$post = get_post( $id, ARRAY_A );

if ( 'attachment' != $post['post_type'] ) {
if ( 'attachment' !== $post['post_type'] ) {
wp_send_json_error();
}

Expand Down Expand Up @@ -3087,7 +3087,7 @@ function wp_ajax_save_attachment_compat() {

$post = get_post( $id, ARRAY_A );

if ( 'attachment' != $post['post_type'] ) {
if ( 'attachment' !== $post['post_type'] ) {
wp_send_json_error();
}

Expand Down Expand Up @@ -3154,7 +3154,7 @@ function wp_ajax_save_attachment_order() {
continue;
}

if ( 'attachment' != $attachment->post_type ) {
if ( 'attachment' !== $attachment->post_type ) {
continue;
}

Expand Down Expand Up @@ -3190,7 +3190,7 @@ function wp_ajax_send_attachment_to_editor() {
wp_send_json_error();
}

if ( 'attachment' != $post->post_type ) {
if ( 'attachment' !== $post->post_type ) {
wp_send_json_error();
}

Expand Down Expand Up @@ -3304,7 +3304,7 @@ function wp_ajax_send_link_to_editor() {
$ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );
if ( $ext ) {
$ext_type = wp_ext2type( $ext );
if ( 'audio' == $ext_type || 'video' == $ext_type ) {
if ( 'audio' === $ext_type || 'video' === $ext_type ) {
$type = $ext_type;
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/wp-admin/includes/bookmark.php
Expand Up @@ -39,7 +39,7 @@ function edit_link( $link_id = 0 ) {
$_POST['link_name'] = esc_html( $_POST['link_name'] );
$_POST['link_image'] = esc_html( $_POST['link_image'] );
$_POST['link_rss'] = esc_url( $_POST['link_rss'] );
if ( ! isset( $_POST['link_visible'] ) || 'N' != $_POST['link_visible'] ) {
if ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) {
$_POST['link_visible'] = 'Y';
}

Expand Down Expand Up @@ -174,15 +174,15 @@ function wp_insert_link( $linkdata, $wp_error = false ) {
$update = true;
}

if ( trim( $link_name ) == '' ) {
if ( trim( $link_url ) != '' ) {
if ( '' === trim( $link_name ) ) {
if ( '' !== trim( $link_url ) ) {
$link_name = $link_url;
} else {
return 0;
}
}

if ( trim( $link_url ) == '' ) {
if ( '' === trim( $link_url ) ) {
return 0;
}

Expand Down Expand Up @@ -309,7 +309,8 @@ function wp_update_link( $linkdata ) {
*/
function wp_link_manager_disabled_message() {
global $pagenow;
if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) {

if ( ! in_array( $pagenow, array( 'link-manager.php', 'link-add.php', 'link.php' ), true ) ) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-core-upgrader.php
Expand Up @@ -104,7 +104,7 @@ public function upgrade( $current, $args = array() ) {
*/
if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
$to_download = 'rollback';
} elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) {
} elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version == $current->partial_version && $partial ) {
$to_download = 'partial';
} elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
Expand Down Expand Up @@ -402,7 +402,7 @@ public function check_files() {

foreach ( $checksums as $file => $checksum ) {
// Skip files which get updated.
if ( 'wp-content' == substr( $file, 0, 10 ) ) {
if ( 'wp-content' === substr( $file, 0, 10 ) ) {
continue;
}
if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-custom-image-header.php
Expand Up @@ -281,7 +281,7 @@ public function process_default_headers() {
* or 'uploaded' (for the Uploaded Images control).
*/
public function show_header_selector( $type = 'default' ) {
if ( 'default' == $type ) {
if ( 'default' === $type ) {
$headers = $this->default_headers;
} else {
$headers = get_uploaded_header_images();
Expand Down Expand Up @@ -359,7 +359,7 @@ function toggle_text() {
if ( ! checked )
return;
text_color = $('#text-color');
if ( '' == text_color.val().replace('#', '') ) {
if ( '' === text_color.val().replace('#', '') ) {
text_color.val( default_color );
pickColor( default_color );
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/wp-admin/includes/class-language-pack-upgrader.php
Expand Up @@ -188,7 +188,7 @@ public function bulk_upgrade( $language_updates = array(), $args = array() ) {
return true;
}

if ( 'upgrader_process_complete' == current_filter() ) {
if ( 'upgrader_process_complete' === current_filter() ) {
$this->skin->feedback( 'starting_upgrade' );
}

Expand Down Expand Up @@ -232,9 +232,9 @@ public function bulk_upgrade( $language_updates = array(), $args = array() ) {
$this->skin->language_update = $language_update;

$destination = WP_LANG_DIR;
if ( 'plugin' == $language_update->type ) {
if ( 'plugin' === $language_update->type ) {
$destination .= '/plugins';
} elseif ( 'theme' == $language_update->type ) {
} elseif ( 'theme' === $language_update->type ) {
$destination .= '/themes';
}

Expand Down Expand Up @@ -335,9 +335,9 @@ public function check_package( $source, $remote_source ) {
$po = false;
$mo = false;
foreach ( (array) $files as $file => $filedata ) {
if ( '.po' == substr( $file, -3 ) ) {
if ( '.po' === substr( $file, -3 ) ) {
$po = true;
} elseif ( '.mo' == substr( $file, -3 ) ) {
} elseif ( '.mo' === substr( $file, -3 ) ) {
$mo = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-plugin-installer-skin.php
Expand Up @@ -60,13 +60,13 @@ public function after() {

$from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';

if ( 'import' == $from ) {
if ( 'import' === $from ) {
$install_actions['activate_plugin'] = sprintf(
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
__( 'Activate Plugin &amp; Run Importer' )
);
} elseif ( 'press-this' == $from ) {
} elseif ( 'press-this' === $from ) {
$install_actions['activate_plugin'] = sprintf(
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-walker-nav-menu-checklist.php
Expand Up @@ -75,7 +75,7 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
global $_nav_menu_placeholder, $nav_menu_selected_id;

$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' === $item->post_type ? $item->object_id : $_nav_menu_placeholder;
$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;

$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
Expand Down

0 comments on commit 6742d0d

Please sign in to comment.