Skip to content

Commit 94d96bd

Browse files
Coding Standards: Use strict comparison in some wp-admin files.
Props pikamander2, mukesh27, SergeyBiryukov. Fixes #49239. git-svn-id: https://develop.svn.wordpress.org/trunk@47785 602fd350-edb4-49c9-b593-d223f7449a82
1 parent afaab88 commit 94d96bd

24 files changed

Lines changed: 151 additions & 105 deletions

src/wp-admin/admin-header.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
$admin_title = get_bloginfo( 'name' );
4545
}
4646

47-
if ( $admin_title == $title ) {
47+
if ( $admin_title === $title ) {
4848
/* translators: Admin screen title. %s: Admin screen name. */
4949
$admin_title = sprintf( __( '%s — WordPress' ), $title );
5050
} else {
@@ -147,7 +147,7 @@
147147
*/
148148
do_action( 'admin_head' );
149149

150-
if ( get_user_setting( 'mfold' ) == 'f' ) {
150+
if ( get_user_setting( 'mfold' ) === 'f' ) {
151151
$admin_body_class .= ' folded';
152152
}
153153

src/wp-admin/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @since 2.8.0
4646
*/
4747
do_action( 'after_db_upgrade' );
48-
} elseif ( get_option( 'db_version' ) != $wp_db_version && empty( $_POST ) ) {
48+
} elseif ( get_option( 'db_version' ) !== $wp_db_version && empty( $_POST ) ) {
4949
if ( ! is_multisite() ) {
5050
wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
5151
exit;

src/wp-admin/async-upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
if ( isset( $_REQUEST['attachment_id'] ) && intval( $_REQUEST['attachment_id'] ) && $_REQUEST['fetch'] ) {
4343
$id = intval( $_REQUEST['attachment_id'] );
4444
$post = get_post( $id );
45-
if ( 'attachment' != $post->post_type ) {
45+
if ( 'attachment' !== $post->post_type ) {
4646
wp_die( __( 'Invalid post type.' ) );
4747
}
4848
if ( ! current_user_can( 'edit_post', $id ) ) {

src/wp-admin/comment.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
$action = 'deletecomment';
2323
}
2424

25-
if ( 'cdc' == $action ) {
25+
if ( 'cdc' === $action ) {
2626
$action = 'delete';
27-
} elseif ( 'mac' == $action ) {
27+
} elseif ( 'mac' === $action ) {
2828
$action = 'approve';
2929
}
3030

3131
if ( isset( $_GET['dt'] ) ) {
32-
if ( 'spam' == $_GET['dt'] ) {
32+
if ( 'spam' === $_GET['dt'] ) {
3333
$action = 'spam';
34-
} elseif ( 'trash' == $_GET['dt'] ) {
34+
} elseif ( 'trash' === $_GET['dt'] ) {
3535
$action = 'trash';
3636
}
3737
}
@@ -71,7 +71,7 @@
7171
comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) );
7272
}
7373

74-
if ( 'trash' == $comment->comment_approved ) {
74+
if ( 'trash' === $comment->comment_approved ) {
7575
comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) );
7676
}
7777

@@ -101,15 +101,15 @@
101101
}
102102

103103
// No need to re-approve/re-trash/re-spam a comment.
104-
if ( str_replace( '1', 'approve', $comment->comment_approved ) == $action ) {
104+
if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) {
105105
wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
106106
die();
107107
}
108108

109109
require_once ABSPATH . 'wp-admin/admin-header.php';
110110

111111
$formaction = $action . 'comment';
112-
$nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
112+
$nonce_action = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_';
113113
$nonce_action .= $comment_id;
114114

115115
?>
@@ -137,7 +137,7 @@
137137
break;
138138
}
139139

140-
if ( '0' != $comment->comment_approved ) { // If not unapproved.
140+
if ( '0' !== $comment->comment_approved ) { // If not unapproved.
141141
$message = '';
142142
switch ( $comment->comment_approved ) {
143143
case '1':
@@ -271,9 +271,9 @@
271271
comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
272272
}
273273

274-
if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
274+
if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
275275
$redir = wp_get_referer();
276-
} elseif ( '' != wp_get_original_referer() && ! $noredir ) {
276+
} elseif ( wp_get_original_referer() && ! $noredir ) {
277277
$redir = wp_get_original_referer();
278278
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
279279
$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
@@ -348,9 +348,9 @@
348348
* @param int $comment_id The ID of the comment being edited.
349349
*/
350350
$location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
351-
wp_redirect( $location );
352351

353-
exit();
352+
wp_redirect( $location );
353+
exit;
354354

355355
default:
356356
wp_die( __( 'Unknown action.' ) );

src/wp-admin/edit-comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
if ( $doaction ) {
2525
check_admin_referer( 'bulk-comments' );
2626

27-
if ( 'delete_all' == $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
27+
if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
2828
$comment_status = wp_unslash( $_REQUEST['comment_status'] );
2929
$delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
3030
$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 ) );
3131
$doaction = 'delete';
3232
} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
3333
$comment_ids = $_REQUEST['delete_comments'];
34-
$doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
34+
$doaction = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
3535
} elseif ( isset( $_REQUEST['ids'] ) ) {
3636
$comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
3737
} elseif ( wp_get_referer() ) {

src/wp-admin/edit-form-advanced.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
7777
$action = isset( $action ) ? $action : '';
7878

79-
if ( get_option( 'page_for_posts' ) == $post_ID && empty( $post->post_content ) ) {
79+
if ( (int) get_option( 'page_for_posts' ) === $post_ID && empty( $post->post_content ) ) {
8080
add_action( 'edit_form_after_title', '_wp_posts_page_notice' );
8181
remove_post_type_support( $post_type, 'editor' );
8282
}
@@ -228,8 +228,8 @@
228228

229229
$notice = false;
230230
$form_extra = '';
231-
if ( 'auto-draft' == $post->post_status ) {
232-
if ( 'edit' == $action ) {
231+
if ( 'auto-draft' === $post->post_status ) {
232+
if ( 'edit' === $action ) {
233233
$post->post_title = '';
234234
}
235235
$autosave = false;
@@ -276,7 +276,7 @@
276276
)
277277
);
278278

279-
if ( 'post' == $post_type ) {
279+
if ( 'post' === $post_type ) {
280280
$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>';
281281

282282
get_current_screen()->add_help_tab(
@@ -313,7 +313,7 @@
313313
'<p>' . __( '<a href="https://wordpress.org/support/article/wordpress-editor/">Documentation on Writing and Editing Posts</a>' ) . '</p>' .
314314
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
315315
);
316-
} elseif ( 'page' == $post_type ) {
316+
} elseif ( 'page' === $post_type ) {
317317
$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>' .
318318
'<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>';
319319

@@ -331,7 +331,7 @@
331331
'<p>' . __( '<a href="https://wordpress.org/support/article/pages-screen/">Documentation on Editing Pages</a>' ) . '</p>' .
332332
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
333333
);
334-
} elseif ( 'attachment' == $post_type ) {
334+
} elseif ( 'attachment' === $post_type ) {
335335
get_current_screen()->add_help_tab(
336336
array(
337337
'id' => 'overview',
@@ -351,7 +351,7 @@
351351
);
352352
}
353353

354-
if ( 'post' == $post_type || 'page' == $post_type ) {
354+
if ( 'post' === $post_type || 'page' === $post_type ) {
355355
$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>';
356356
$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>';
357357

@@ -364,7 +364,7 @@
364364
);
365365
}
366366

367-
if ( 'post' == $post_type ) {
367+
if ( 'post' === $post_type ) {
368368
$publish_box = '<p>' . __( 'Several boxes on this screen contain settings for how your content will be published, including:' ) . '</p>';
369369
$publish_box .= '<ul><li>' .
370370
__( '<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.' ) .
@@ -402,7 +402,7 @@
402402
'content' => $discussion_settings,
403403
)
404404
);
405-
} elseif ( 'page' == $post_type ) {
405+
} elseif ( 'page' === $post_type ) {
406406
$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>' .
407407
'<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>' .
408408
'<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>';
@@ -471,7 +471,7 @@
471471
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
472472
<?php
473473
}
474-
if ( 'draft' != get_post_status( $post ) ) {
474+
if ( 'draft' !== get_post_status( $post ) ) {
475475
wp_original_referer_field( true, 'previous' );
476476
}
477477

@@ -495,7 +495,7 @@
495495
?>
496496

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

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

537537
if ( ! empty( $shortlink ) && $shortlink !== $permalink && home_url( '?page_id=' . $post->ID ) !== $permalink ) {
538-
$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>';
538+
$sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr( $shortlink ) . '" />' .
539+
'<button type="button" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val());">' .
540+
__( 'Get Shortlink' ) .
541+
'</button>';
539542
}
540543
}
541544

542-
if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
543-
$has_sample_permalink = $sample_permalink_html && 'auto-draft' != $post->post_status;
545+
if ( $post_type_object->public
546+
&& ! ( 'pending' === get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) )
547+
) {
548+
$has_sample_permalink = $sample_permalink_html && 'auto-draft' !== $post->post_status;
544549
?>
545550
<div id="edit-slug-box" class="hide-if-no-js">
546551
<?php
@@ -608,7 +613,7 @@
608613
<td class="autosave-info">
609614
<span class="autosave-message">&nbsp;</span>
610615
<?php
611-
if ( 'auto-draft' != $post->post_status ) {
616+
if ( 'auto-draft' !== $post->post_status ) {
612617
echo '<span id="last-edit">';
613618
$last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) );
614619
if ( $last_user ) {
@@ -642,7 +647,7 @@
642647
<div id="postbox-container-1" class="postbox-container">
643648
<?php
644649

645-
if ( 'page' == $post_type ) {
650+
if ( 'page' === $post_type ) {
646651
/**
647652
* Fires before meta boxes with 'side' context are output for the 'page' post type.
648653
*
@@ -676,7 +681,7 @@
676681

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

679-
if ( 'page' == $post_type ) {
684+
if ( 'page' === $post_type ) {
680685
/**
681686
* Fires after 'normal' context meta boxes have been output for the 'page' post type.
682687
*

src/wp-admin/edit-form-comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<label><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php _ex( 'Spam', 'comment status' ); ?></label>
119119
</fieldset>
120120
</div><!-- .misc-pub-section -->
121-
121+
122122
<div class="misc-pub-section curtime misc-pub-curtime">
123123
<?php
124124
$submitted = sprintf(

src/wp-admin/edit-link-form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
<div id="poststuff">
110110

111-
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
111+
<div id="post-body" class="metabox-holder columns-<?php echo ( 1 === get_current_screen()->get_columns() ) ? '1' : '2'; ?>">
112112
<div id="post-body-content">
113113
<div id="namediv" class="stuffbox">
114114
<h2><label for="link_name"><?php _ex( 'Name', 'link name' ); ?></label></h2>

src/wp-admin/edit-tag-form.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313

1414
// Back compat hooks.
15-
if ( 'category' == $taxonomy ) {
15+
if ( 'category' === $taxonomy ) {
1616
/**
1717
* Fires before the Edit Category form.
1818
*
@@ -22,7 +22,7 @@
2222
* @param WP_Term $tag Current category term object.
2323
*/
2424
do_action_deprecated( 'edit_category_form_pre', array( $tag ), '3.0.0', '{$taxonomy}_pre_edit_form' );
25-
} elseif ( 'link_category' == $taxonomy ) {
25+
} elseif ( 'link_category' === $taxonomy ) {
2626
/**
2727
* Fires before the Edit Link Category form.
2828
*
@@ -177,7 +177,7 @@
177177
$dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' );
178178
wp_dropdown_categories( $dropdown_args );
179179
?>
180-
<?php if ( 'category' == $taxonomy ) : ?>
180+
<?php if ( 'category' === $taxonomy ) : ?>
181181
<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>
182182
<?php else : ?>
183183
<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>
@@ -192,7 +192,7 @@
192192
</tr>
193193
<?php
194194
// Back compat hooks.
195-
if ( 'category' == $taxonomy ) {
195+
if ( 'category' === $taxonomy ) {
196196
/**
197197
* Fires after the Edit Category form fields are displayed.
198198
*
@@ -202,7 +202,7 @@
202202
* @param WP_Term $tag Current category term object.
203203
*/
204204
do_action_deprecated( 'edit_category_form_fields', array( $tag ), '3.0.0', '{$taxonomy}_edit_form_fields' );
205-
} elseif ( 'link_category' == $taxonomy ) {
205+
} elseif ( 'link_category' === $taxonomy ) {
206206
/**
207207
* Fires after the Edit Link Category form fields are displayed.
208208
*
@@ -239,10 +239,10 @@
239239
</table>
240240
<?php
241241
// Back compat hooks.
242-
if ( 'category' == $taxonomy ) {
242+
if ( 'category' === $taxonomy ) {
243243
/** This action is documented in wp-admin/edit-tags.php */
244244
do_action_deprecated( 'edit_category_form', array( $tag ), '3.0.0', '{$taxonomy}_add_form' );
245-
} elseif ( 'link_category' == $taxonomy ) {
245+
} elseif ( 'link_category' === $taxonomy ) {
246246
/** This action is documented in wp-admin/edit-tags.php */
247247
do_action_deprecated( 'edit_link_category_form', array( $tag ), '3.0.0', '{$taxonomy}_add_form' );
248248
} else {

src/wp-admin/edit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
$bulk_messages['post'] = array(
333333
/* translators: %s: Number of posts. */
334334
'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
335-
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
335+
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
336336
/* translators: %s: Number of posts. */
337337
_n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
338338
/* translators: %s: Number of posts. */
@@ -345,7 +345,7 @@
345345
$bulk_messages['page'] = array(
346346
/* translators: %s: Number of pages. */
347347
'updated' => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
348-
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
348+
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
349349
/* translators: %s: Number of pages. */
350350
_n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
351351
/* translators: %s: Number of pages. */
@@ -358,7 +358,7 @@
358358
$bulk_messages['wp_block'] = array(
359359
/* translators: %s: Number of blocks. */
360360
'updated' => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
361-
'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
361+
'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
362362
/* translators: %s: Number of blocks. */
363363
_n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
364364
/* translators: %s: Number of blocks. */

0 commit comments

Comments
 (0)