Skip to content

Commit

Permalink
Coding Standards: Use strict comparison in wp-admin/includes/post.php.
Browse files Browse the repository at this point in the history
Follow-up to [2718], [7103], [7338], [8857], [9036], [9103], [11807], [11908], [15315], [16901], [17078], [23725], [23735], [44141], [45583].

Props aristath, poena, afercia, SergeyBiryukov.
See #60700.

git-svn-id: https://develop.svn.wordpress.org/trunk@58360 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 7, 2024
1 parent 5115c7a commit 1c8733e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
}
}

if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] !== $post_data['user_ID'] )
&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {

if ( $update ) {
Expand Down Expand Up @@ -165,7 +165,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
}

foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] != $post_data[ $timeunit ] ) {
if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] !== $post_data[ $timeunit ] ) {
$post_data['edit_date'] = '1';
break;
}
Expand Down Expand Up @@ -375,7 +375,7 @@ function edit_post( $post_data = null ) {
continue;
}

if ( $meta->post_id != $post_id ) {
if ( (int) $meta->post_id !== $post_id ) {
continue;
}

Expand All @@ -402,7 +402,7 @@ function edit_post( $post_data = null ) {
continue;
}

if ( $meta->post_id != $post_id ) {
if ( (int) $meta->post_id !== $post_id ) {
continue;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ function bulk_edit_posts( $post_data = null ) {
}
}

if ( -1 == $post_data['_status'] ) {
if ( '-1' === $post_data['_status'] ) {
$post_data['post_status'] = null;
unset( $post_data['post_status'] );
} else {
Expand Down Expand Up @@ -550,7 +550,7 @@ function bulk_edit_posts( $post_data = null ) {
);

foreach ( $reset as $field ) {
if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) {
unset( $post_data[ $field ] );
}
}
Expand Down Expand Up @@ -1404,7 +1404,7 @@ function wp_edit_attachments_query( $q = false ) {
* @return string Space-separated string of class names.
*/
function postbox_classes( $box_id, $screen_id ) {
if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
if ( isset( $_GET['edit'] ) && $_GET['edit'] === $box_id ) {
$classes = array( '' );
} elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
$closed = get_user_option( 'closedpostboxes_' . $screen_id );
Expand Down Expand Up @@ -1577,7 +1577,7 @@ function get_sample_permalink_html( $post, $new_title = null, $new_slug = null )

// Encourage a pretty permalink setting.
if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
&& ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID )
&& ! ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID )
) {
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n";
}
Expand Down Expand Up @@ -1713,7 +1713,7 @@ function wp_check_post_lock( $post ) {

$lock = explode( ':', $lock );
$time = $lock[0];
$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
$user = isset( $lock[1] ) ? (int) $lock[1] : (int) get_post_meta( $post->ID, '_edit_last', true );

if ( ! get_userdata( $user ) ) {
return false;
Expand All @@ -1722,7 +1722,7 @@ function wp_check_post_lock( $post ) {
/** This filter is documented in wp-admin/includes/ajax-actions.php */
$time_window = apply_filters( 'wp_check_post_lock_window', 150 );

if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
if ( $time && $time > time() - $time_window && get_current_user_id() !== $user ) {
return $user;
}

Expand Down Expand Up @@ -1752,7 +1752,7 @@ function wp_set_post_lock( $post ) {

$user_id = get_current_user_id();

if ( 0 == $user_id ) {
if ( 0 === $user_id ) {
return false;
}

Expand Down Expand Up @@ -1829,7 +1829,7 @@ function _admin_notice_post_locked() {
if ( $locked ) {
$query_args = array();
if ( get_post_type_object( $post->post_type )->public ) {
if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
if ( 'publish' === $post->post_status || $user->ID !== (int) $post->post_author ) {
// Latest content is in autosave.
$nonce = wp_create_nonce( 'post_preview_' . $post->ID );
$query_args['preview_id'] = $post->ID;
Expand Down Expand Up @@ -2081,7 +2081,7 @@ function post_preview() {

$is_autosave = false;

if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() === (int) $post->post_author
&& ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
) {
$saved_post_id = edit_post();
Expand Down Expand Up @@ -2156,7 +2156,7 @@ function wp_autosave( $post_data ) {
$post_data['post_category'] = explode( ',', $post_data['catslist'] );
}

if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() === (int) $post->post_author
&& ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
) {
// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
Expand Down Expand Up @@ -2408,7 +2408,7 @@ function the_block_editor_meta_boxes() {

$meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
foreach ( $meta_boxes as $meta_box ) {
if ( false == $meta_box || ! $meta_box['title'] ) {
if ( false === $meta_box || ! $meta_box['title'] ) {
continue;
}

Expand Down
14 changes: 7 additions & 7 deletions tests/phpunit/tests/admin/includesPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ public function test_bulk_edit_posts_stomping() {

$request = array(
'post_type' => 'post',
'post_author' => -1,
'ping_status' => -1,
'comment_status' => -1,
'_status' => -1,
'post_author' => '-1',
'ping_status' => '-1',
'comment_status' => '-1',
'_status' => '-1',
'post' => array( $post1, $post2 ),
);

Expand Down Expand Up @@ -273,8 +273,8 @@ public function test_bulk_edit_posts_should_preserve_post_format_when_unchanged(
set_post_format( $post_ids[1], 'aside' );

$request = array(
'post_format' => -1, // Don't change the post format.
'_status' => -1,
'post_format' => '-1', // Don't change the post format.
'_status' => '-1',
'post' => $post_ids,
);

Expand Down Expand Up @@ -367,7 +367,7 @@ public function test_bulk_edit_posts_should_set_post_format_before_wp_update_pos

$request = array(
'post_format' => 'aside',
'_status' => -1,
'_status' => '-1',
'post' => array( self::$post_id ),
);

Expand Down

0 comments on commit 1c8733e

Please sign in to comment.