From 9787f2fff9a3cfb823e9215ffdfd225138fd7776 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 29 Jun 2020 22:42:08 +0000 Subject: [PATCH] Comments: Minor adjustments to `wp_update_comment()`: * Revert the logic of `$wp_error` checks to avoid negation. * Clarify the return value, restore the edits from [47017]. * Update `wp_update_comment_data` filter check to allow `false` to prevent the update. Follow-up to [48154]. See #39732. git-svn-id: https://develop.svn.wordpress.org/trunk@48215 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 8246fc9bc5..c1165d9198 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2427,8 +2427,8 @@ function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false * * @param array $commentarr Contains information on the comment. * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. - * @return int|bool|WP_Error Comment was updated if value is 1, or was not updated if value is 0, - * false, or a WP_Error object. + * @return int|false|WP_Error The value 1 if the comment was updated, 0 if not updated. + * False or a WP_Error object on failure. */ function wp_update_comment( $commentarr, $wp_error = false ) { global $wpdb; @@ -2436,20 +2436,20 @@ function wp_update_comment( $commentarr, $wp_error = false ) { // First, get all of the original fields. $comment = get_comment( $commentarr['comment_ID'], ARRAY_A ); if ( empty( $comment ) ) { - if ( ! $wp_error ) { + if ( $wp_error ) { + return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ); + } else { return 0; } - - return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ); } // Make sure that the comment post ID is valid (if specified). if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { - if ( ! $wp_error ) { + if ( $wp_error ) { + return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ); + } else { return 0; } - - return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ); } // Escape data pulled from DB. @@ -2490,8 +2490,8 @@ function wp_update_comment( $commentarr, $wp_error = false ) { /** * Filters the comment data immediately before it is updated in the database. * - * Note: data being passed to the filter is already unslashed. Returning 0 or a - * WP_Error object is preventing the comment to be updated. + * Note: data being passed to the filter is already unslashed. Returning false + * or a WP_Error object would prevent the comment from being updated. * * @since 4.7.0 * @since 5.5.0 The `$wp_error` parameter was added. @@ -2499,13 +2499,12 @@ function wp_update_comment( $commentarr, $wp_error = false ) { * @param array $data The new, processed comment data. * @param array $comment The old, unslashed comment data. * @param array $commentarr The new, raw comment data. - * @param bool $wp_error Optional. Whether to return a WP_Error on failure. - * Default false. + * @param bool $wp_error Whether to return a WP_Error on failure. */ $data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr, $wp_error ); // Do not carry on on failure. - if ( is_wp_error( $data ) || 0 === $data ) { + if ( is_wp_error( $data ) || ! $data ) { return $data; }