Skip to content

Commit

Permalink
Coding Standards: Use strict comparison in some wp-admin files.
Browse files Browse the repository at this point in the history
Props pikamander2, mukesh27, SergeyBiryukov.
Fixes #49239.

git-svn-id: https://develop.svn.wordpress.org/trunk@47785 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 12, 2020
1 parent afaab88 commit 94d96bd
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/wp-admin/admin-header.php
Expand Up @@ -44,7 +44,7 @@
$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 {
Expand Down Expand Up @@ -147,7 +147,7 @@
*/
do_action( 'admin_head' );

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

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/admin.php
Expand Up @@ -45,7 +45,7 @@
* @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;
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/async-upload.php
Expand Up @@ -42,7 +42,7 @@
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 ) ) {
Expand Down
24 changes: 12 additions & 12 deletions src/wp-admin/comment.php
Expand Up @@ -22,16 +22,16 @@
$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';
}
}
Expand Down Expand Up @@ -71,7 +71,7 @@
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.' ) );
}

Expand Down Expand Up @@ -101,15 +101,15 @@
}

// 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();
}

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;

?>
Expand Down Expand Up @@ -137,7 +137,7 @@
break;
}

if ( '0' != $comment->comment_approved ) { // If not unapproved.
if ( '0' !== $comment->comment_approved ) { // If not unapproved.
$message = '';
switch ( $comment->comment_approved ) {
case '1':
Expand Down Expand Up @@ -271,9 +271,9 @@
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 ) );
Expand Down Expand Up @@ -348,9 +348,9 @@
* @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.' ) );
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/edit-comments.php
Expand Up @@ -24,14 +24,14 @@
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() ) {
Expand Down
39 changes: 22 additions & 17 deletions src/wp-admin/edit-form-advanced.php
Expand Up @@ -76,7 +76,7 @@
$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' );
}
Expand Down Expand Up @@ -228,8 +228,8 @@

$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;
Expand Down Expand Up @@ -276,7 +276,7 @@
)
);

if ( 'post' == $post_type ) {
if ( 'post' === $post_type ) {
$customize_display = '<p>' . __( '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.' ) . '</p>';

get_current_screen()->add_help_tab(
Expand Down Expand Up @@ -313,7 +313,7 @@
'<p>' . __( '<a href="https://wordpress.org/support/article/wordpress-editor/">Documentation on Writing and Editing Posts</a>' ) . '</p>' .
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
);
} elseif ( 'page' == $post_type ) {
} elseif ( 'page' === $post_type ) {
$about_pages = '<p>' . __( '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 &#8220;Parent&#8221; of the other, creating a group of pages.' ) . '</p>' .
'<p>' . __( '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.' ) . '</p>';

Expand All @@ -331,7 +331,7 @@
'<p>' . __( '<a href="https://wordpress.org/support/article/pages-screen/">Documentation on Editing Pages</a>' ) . '</p>' .
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
);
} elseif ( 'attachment' == $post_type ) {
} elseif ( 'attachment' === $post_type ) {
get_current_screen()->add_help_tab(
array(
'id' => 'overview',
Expand All @@ -351,7 +351,7 @@
);
}

if ( 'post' == $post_type || 'page' == $post_type ) {
if ( 'post' === $post_type || 'page' === $post_type ) {
$inserting_media = '<p>' . __( '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 &#8220;Create a new gallery&#8221; button.' ) . '</p>';
$inserting_media .= '<p>' . __( '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. <a href="https://wordpress.org/support/article/embeds/">Learn more about embeds</a>.' ) . '</p>';

Expand All @@ -364,7 +364,7 @@
);
}

if ( 'post' == $post_type ) {
if ( 'post' === $post_type ) {
$publish_box = '<p>' . __( 'Several boxes on this screen contain settings for how your content will be published, including:' ) . '</p>';
$publish_box .= '<ul><li>' .
__( '<strong>Publish</strong> &mdash; You can set the terms of publishing your post in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a post or making it stay at the top of your blog indefinitely (sticky). The Password protected option allows you to set an arbitrary password for each post. The Private option hides the post from everyone except editors and administrators. Publish (immediately) allows you to set a future or past date and time, so you can schedule a post to be published in the future or backdate a post.' ) .
Expand Down Expand Up @@ -402,7 +402,7 @@
'content' => $discussion_settings,
)
);
} elseif ( 'page' == $post_type ) {
} elseif ( 'page' === $post_type ) {
$page_attributes = '<p>' . __( '<strong>Parent</strong> &mdash; You can arrange your pages in hierarchies. For example, you could have an &#8220;About&#8221; page that has &#8220;Life Story&#8221; and &#8220;My Dog&#8221; pages under it. There are no limits to how many levels you can nest pages.' ) . '</p>' .
'<p>' . __( '<strong>Template</strong> &mdash; Some themes have custom templates you can use for certain pages that might have additional features or custom layouts. If so, you&#8217;ll see them in this dropdown menu.' ) . '</p>' .
'<p>' . __( '<strong>Order</strong> &mdash; Pages are usually ordered alphabetically, but you can choose your own order by entering a number (1 for first, etc.) in this field.' ) . '</p>';
Expand Down Expand Up @@ -471,7 +471,7 @@
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
<?php
}
if ( 'draft' != get_post_status( $post ) ) {
if ( 'draft' !== get_post_status( $post ) ) {
wp_original_referer_field( true, 'previous' );
}

Expand All @@ -495,7 +495,7 @@
?>

<div id="poststuff">
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
<div id="post-body" class="metabox-holder columns-<?php echo ( 1 === get_current_screen()->get_columns() ) ? '1' : '2'; ?>">
<div id="post-body-content">

<?php if ( post_type_supports( $post_type, 'title' ) ) { ?>
Expand Down Expand Up @@ -535,12 +535,17 @@
$shortlink = wp_get_shortlink( $post->ID, 'post' );

if ( ! empty( $shortlink ) && $shortlink !== $permalink && home_url( '?page_id=' . $post->ID ) !== $permalink ) {
$sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr( $shortlink ) . '" /><button type="button" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val());">' . __( 'Get Shortlink' ) . '</button>';
$sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr( $shortlink ) . '" />' .
'<button type="button" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val());">' .
__( 'Get Shortlink' ) .
'</button>';
}
}

if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
$has_sample_permalink = $sample_permalink_html && 'auto-draft' != $post->post_status;
if ( $post_type_object->public
&& ! ( 'pending' === get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) )
) {
$has_sample_permalink = $sample_permalink_html && 'auto-draft' !== $post->post_status;
?>
<div id="edit-slug-box" class="hide-if-no-js">
<?php
Expand Down Expand Up @@ -608,7 +613,7 @@
<td class="autosave-info">
<span class="autosave-message">&nbsp;</span>
<?php
if ( 'auto-draft' != $post->post_status ) {
if ( 'auto-draft' !== $post->post_status ) {
echo '<span id="last-edit">';
$last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) );
if ( $last_user ) {
Expand Down Expand Up @@ -642,7 +647,7 @@
<div id="postbox-container-1" class="postbox-container">
<?php

if ( 'page' == $post_type ) {
if ( 'page' === $post_type ) {
/**
* Fires before meta boxes with 'side' context are output for the 'page' post type.
*
Expand Down Expand Up @@ -676,7 +681,7 @@

do_meta_boxes( null, 'normal', $post );

if ( 'page' == $post_type ) {
if ( 'page' === $post_type ) {
/**
* Fires after 'normal' context meta boxes have been output for the 'page' post type.
*
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/edit-form-comment.php
Expand Up @@ -118,7 +118,7 @@
<label><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php _ex( 'Spam', 'comment status' ); ?></label>
</fieldset>
</div><!-- .misc-pub-section -->

<div class="misc-pub-section curtime misc-pub-curtime">
<?php
$submitted = sprintf(
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/edit-link-form.php
Expand Up @@ -108,7 +108,7 @@

<div id="poststuff">

<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
<div id="post-body" class="metabox-holder columns-<?php echo ( 1 === get_current_screen()->get_columns() ) ? '1' : '2'; ?>">
<div id="post-body-content">
<div id="namediv" class="stuffbox">
<h2><label for="link_name"><?php _ex( 'Name', 'link name' ); ?></label></h2>
Expand Down
14 changes: 7 additions & 7 deletions src/wp-admin/edit-tag-form.php
Expand Up @@ -12,7 +12,7 @@
}

// Back compat hooks.
if ( 'category' == $taxonomy ) {
if ( 'category' === $taxonomy ) {
/**
* Fires before the Edit Category form.
*
Expand All @@ -22,7 +22,7 @@
* @param WP_Term $tag Current category term object.
*/
do_action_deprecated( 'edit_category_form_pre', array( $tag ), '3.0.0', '{$taxonomy}_pre_edit_form' );
} elseif ( 'link_category' == $taxonomy ) {
} elseif ( 'link_category' === $taxonomy ) {
/**
* Fires before the Edit Link Category form.
*
Expand Down Expand Up @@ -177,7 +177,7 @@
$dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' );
wp_dropdown_categories( $dropdown_args );
?>
<?php if ( 'category' == $taxonomy ) : ?>
<?php if ( 'category' === $taxonomy ) : ?>
<p class="description"><?php _e( 'Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.' ); ?></p>
<?php else : ?>
<p class="description"><?php _e( 'Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.' ); ?></p>
Expand All @@ -192,7 +192,7 @@
</tr>
<?php
// Back compat hooks.
if ( 'category' == $taxonomy ) {
if ( 'category' === $taxonomy ) {
/**
* Fires after the Edit Category form fields are displayed.
*
Expand All @@ -202,7 +202,7 @@
* @param WP_Term $tag Current category term object.
*/
do_action_deprecated( 'edit_category_form_fields', array( $tag ), '3.0.0', '{$taxonomy}_edit_form_fields' );
} elseif ( 'link_category' == $taxonomy ) {
} elseif ( 'link_category' === $taxonomy ) {
/**
* Fires after the Edit Link Category form fields are displayed.
*
Expand Down Expand Up @@ -239,10 +239,10 @@
</table>
<?php
// Back compat hooks.
if ( 'category' == $taxonomy ) {
if ( 'category' === $taxonomy ) {
/** This action is documented in wp-admin/edit-tags.php */
do_action_deprecated( 'edit_category_form', array( $tag ), '3.0.0', '{$taxonomy}_add_form' );
} elseif ( 'link_category' == $taxonomy ) {
} elseif ( 'link_category' === $taxonomy ) {
/** This action is documented in wp-admin/edit-tags.php */
do_action_deprecated( 'edit_link_category_form', array( $tag ), '3.0.0', '{$taxonomy}_add_form' );
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/edit.php
Expand Up @@ -332,7 +332,7 @@
$bulk_messages['post'] = array(
/* translators: %s: Number of posts. */
'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
/* translators: %s: Number of posts. */
_n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
/* translators: %s: Number of posts. */
Expand All @@ -345,7 +345,7 @@
$bulk_messages['page'] = array(
/* translators: %s: Number of pages. */
'updated' => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
/* translators: %s: Number of pages. */
_n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
/* translators: %s: Number of pages. */
Expand All @@ -358,7 +358,7 @@
$bulk_messages['wp_block'] = array(
/* translators: %s: Number of blocks. */
'updated' => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
/* translators: %s: Number of blocks. */
_n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
/* translators: %s: Number of blocks. */
Expand Down

0 comments on commit 94d96bd

Please sign in to comment.