From aa69c25d5fc8fee8919b3a33d4bf0f1355d9acd9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 12 May 2020 18:32:08 +0000 Subject: [PATCH] Coding Standards: Use strict comparison in some `wp-admin` files. Props pikamander2, mukesh27, SergeyBiryukov. Fixes #49239. Built from https://develop.svn.wordpress.org/trunk@47785 git-svn-id: http://core.svn.wordpress.org/trunk@47561 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-header.php | 4 ++-- wp-admin/admin.php | 2 +- wp-admin/async-upload.php | 2 +- wp-admin/comment.php | 24 ++++++++++---------- wp-admin/edit-comments.php | 4 ++-- wp-admin/edit-form-advanced.php | 39 +++++++++++++++++++-------------- wp-admin/edit-form-comment.php | 2 +- wp-admin/edit-link-form.php | 2 +- wp-admin/edit-tag-form.php | 14 ++++++------ wp-admin/edit.php | 6 ++--- wp-admin/export.php | 14 ++++++------ wp-admin/import.php | 2 +- wp-admin/includes/upgrade.php | 18 +++++++++++---- wp-admin/install-helper.php | 36 +++++++++++++++++++----------- wp-admin/install.php | 7 +++--- wp-admin/link-manager.php | 2 +- wp-admin/link-parse-opml.php | 16 +++++++------- wp-admin/link.php | 4 ++-- wp-admin/load-styles.php | 2 +- wp-admin/media-upload.php | 6 ++--- wp-admin/media.php | 4 ++-- wp-admin/menu-header.php | 34 +++++++++++++++++++++------- wp-admin/ms-delete-site.php | 4 ++-- wp-admin/my-sites.php | 8 +++++-- wp-includes/version.php | 2 +- 25 files changed, 152 insertions(+), 106 deletions(-) diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index e1bc7998eb..43f91483bc 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -44,7 +44,7 @@ if ( is_network_admin() ) { $admin_title = get_bloginfo( 'name' ); } -if ( $admin_title == $title ) { +if ( $admin_title === $title ) { /* translators: Admin screen title. %s: Admin screen name. */ $admin_title = sprintf( __( '%s — WordPress' ), $title ); } else { @@ -147,7 +147,7 @@ do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConven */ do_action( 'admin_head' ); -if ( get_user_setting( 'mfold' ) == 'f' ) { +if ( get_user_setting( 'mfold' ) === 'f' ) { $admin_body_class .= ' folded'; } diff --git a/wp-admin/admin.php b/wp-admin/admin.php index 8f0e761255..0437af415a 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -45,7 +45,7 @@ if ( get_option( 'db_upgraded' ) ) { * @since 2.8.0 */ do_action( 'after_db_upgrade' ); -} elseif ( get_option( 'db_version' ) != $wp_db_version && empty( $_POST ) ) { +} elseif ( get_option( 'db_version' ) !== $wp_db_version && empty( $_POST ) ) { if ( ! is_multisite() ) { wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); exit; diff --git a/wp-admin/async-upload.php b/wp-admin/async-upload.php index 0419e71a1a..792fedcfd6 100644 --- a/wp-admin/async-upload.php +++ b/wp-admin/async-upload.php @@ -42,7 +42,7 @@ if ( ! current_user_can( 'upload_files' ) ) { if ( isset( $_REQUEST['attachment_id'] ) && intval( $_REQUEST['attachment_id'] ) && $_REQUEST['fetch'] ) { $id = intval( $_REQUEST['attachment_id'] ); $post = get_post( $id ); - if ( 'attachment' != $post->post_type ) { + if ( 'attachment' !== $post->post_type ) { wp_die( __( 'Invalid post type.' ) ); } if ( ! current_user_can( 'edit_post', $id ) ) { diff --git a/wp-admin/comment.php b/wp-admin/comment.php index fea0b8a37c..f5d4b3320f 100644 --- a/wp-admin/comment.php +++ b/wp-admin/comment.php @@ -22,16 +22,16 @@ if ( isset( $_POST['deletecomment'] ) ) { $action = 'deletecomment'; } -if ( 'cdc' == $action ) { +if ( 'cdc' === $action ) { $action = 'delete'; -} elseif ( 'mac' == $action ) { +} elseif ( 'mac' === $action ) { $action = 'approve'; } if ( isset( $_GET['dt'] ) ) { - if ( 'spam' == $_GET['dt'] ) { + if ( 'spam' === $_GET['dt'] ) { $action = 'spam'; - } elseif ( 'trash' == $_GET['dt'] ) { + } elseif ( 'trash' === $_GET['dt'] ) { $action = 'trash'; } } @@ -71,7 +71,7 @@ switch ( $action ) { comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) ); } - if ( 'trash' == $comment->comment_approved ) { + if ( 'trash' === $comment->comment_approved ) { comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) ); } @@ -101,7 +101,7 @@ switch ( $action ) { } // No need to re-approve/re-trash/re-spam a comment. - if ( str_replace( '1', 'approve', $comment->comment_approved ) == $action ) { + if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) { wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) ); die(); } @@ -109,7 +109,7 @@ switch ( $action ) { require_once ABSPATH . 'wp-admin/admin-header.php'; $formaction = $action . 'comment'; - $nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_'; + $nonce_action = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_'; $nonce_action .= $comment_id; ?> @@ -137,7 +137,7 @@ switch ( $action ) { break; } - if ( '0' != $comment->comment_approved ) { // If not unapproved. + if ( '0' !== $comment->comment_approved ) { // If not unapproved. $message = ''; switch ( $comment->comment_approved ) { case '1': @@ -271,9 +271,9 @@ switch ( $action ) { comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); } - if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { + if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { $redir = wp_get_referer(); - } elseif ( '' != wp_get_original_referer() && ! $noredir ) { + } elseif ( wp_get_original_referer() && ! $noredir ) { $redir = wp_get_original_referer(); } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { $redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) ); @@ -348,9 +348,9 @@ switch ( $action ) { * @param int $comment_id The ID of the comment being edited. */ $location = apply_filters( 'comment_edit_redirect', $location, $comment_id ); - wp_redirect( $location ); - exit(); + wp_redirect( $location ); + exit; default: wp_die( __( 'Unknown action.' ) ); diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index d74fd62e20..978040065f 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -24,14 +24,14 @@ $doaction = $wp_list_table->current_action(); if ( $doaction ) { check_admin_referer( 'bulk-comments' ); - if ( 'delete_all' == $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) { + if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) { $comment_status = wp_unslash( $_REQUEST['comment_status'] ); $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] ); $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) ); $doaction = 'delete'; } elseif ( isset( $_REQUEST['delete_comments'] ) ) { $comment_ids = $_REQUEST['delete_comments']; - $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; + $doaction = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; } elseif ( isset( $_REQUEST['ids'] ) ) { $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) ); } elseif ( wp_get_referer() ) { diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 14899438cf..20aea33a3f 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -76,7 +76,7 @@ $post_ID = isset( $post_ID ) ? (int) $post_ID : 0; $user_ID = isset( $user_ID ) ? (int) $user_ID : 0; $action = isset( $action ) ? $action : ''; -if ( get_option( 'page_for_posts' ) == $post_ID && empty( $post->post_content ) ) { +if ( (int) get_option( 'page_for_posts' ) === $post_ID && empty( $post->post_content ) ) { add_action( 'edit_form_after_title', '_wp_posts_page_notice' ); remove_post_type_support( $post_type, 'editor' ); } @@ -228,8 +228,8 @@ if ( isset( $_GET['message'] ) ) { $notice = false; $form_extra = ''; -if ( 'auto-draft' == $post->post_status ) { - if ( 'edit' == $action ) { +if ( 'auto-draft' === $post->post_status ) { + if ( 'edit' === $action ) { $post->post_title = ''; } $autosave = false; @@ -276,7 +276,7 @@ add_screen_option( ) ); -if ( 'post' == $post_type ) { +if ( 'post' === $post_type ) { $customize_display = '

' . __( 'The title field and the big Post Editing Area are fixed in place, but you can reposition all the other boxes using drag and drop. You can also minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.' ) . '

'; get_current_screen()->add_help_tab( @@ -313,7 +313,7 @@ if ( 'post' == $post_type ) { '

' . __( 'Documentation on Writing and Editing Posts' ) . '

' . '

' . __( 'Support' ) . '

' ); -} elseif ( 'page' == $post_type ) { +} elseif ( 'page' === $post_type ) { $about_pages = '

' . __( 'Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the “Parent” of the other, creating a group of pages.' ) . '

' . '

' . __( 'Creating a Page is very similar to creating a Post, and the screens can be customized in the same way using drag and drop, the Screen Options tab, and expanding/collapsing boxes as you choose. This screen also has the distraction-free writing space, available in both the Visual and Text modes via the Fullscreen buttons. The Page editor mostly works the same as the Post editor, but there are some Page-specific features in the Page Attributes box.' ) . '

'; @@ -331,7 +331,7 @@ if ( 'post' == $post_type ) { '

' . __( 'Documentation on Editing Pages' ) . '

' . '

' . __( 'Support' ) . '

' ); -} elseif ( 'attachment' == $post_type ) { +} elseif ( 'attachment' === $post_type ) { get_current_screen()->add_help_tab( array( 'id' => 'overview', @@ -351,7 +351,7 @@ if ( 'post' == $post_type ) { ); } -if ( 'post' == $post_type || 'page' == $post_type ) { +if ( 'post' === $post_type || 'page' === $post_type ) { $inserting_media = '

' . __( 'You can upload and insert media (images, audio, documents, etc.) by clicking the Add Media button. You can select from the images and files already uploaded to the Media Library, or upload new media to add to your page or post. To create an image gallery, select the images to add and click the “Create a new gallery” button.' ) . '

'; $inserting_media .= '

' . __( 'You can also embed media from many popular websites including Twitter, YouTube, Flickr and others by pasting the media URL on its own line into the content of your post/page. Learn more about embeds.' ) . '

'; @@ -364,7 +364,7 @@ if ( 'post' == $post_type || 'page' == $post_type ) { ); } -if ( 'post' == $post_type ) { +if ( 'post' === $post_type ) { $publish_box = '

' . __( 'Several boxes on this screen contain settings for how your content will be published, including:' ) . '

'; $publish_box .= '