From 1c8733e6f22b5e5c9cc8c7a6f0fed7ece0131109 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 7 Jun 2024 12:27:59 +0000 Subject: [PATCH] Coding Standards: Use strict comparison in `wp-admin/includes/post.php`. 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 --- src/wp-admin/includes/post.php | 30 +++++++++++----------- tests/phpunit/tests/admin/includesPost.php | 14 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 30fcb7cc871b6..d6494d53a4bcd 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -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 ) { @@ -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; } @@ -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; } @@ -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; } @@ -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 { @@ -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 ] ); } } @@ -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 ); @@ -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 .= '' . __( 'Change Permalink Structure' ) . "\n"; } @@ -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; @@ -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; } @@ -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; } @@ -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; @@ -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(); @@ -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. @@ -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; } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 2bbd9fab213a9..de7b42f5eb15a 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -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 ), ); @@ -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, ); @@ -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 ), );