From f5942603c055cb5af6334c730f696d873fa60df4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 29 Jun 2020 23:42:03 +0000 Subject: [PATCH] Comments: Make `wp_update_comment()` return a `WP_Error` object for a canceled update, if `$wp_error` parameter is true. Remove redundant checks for `wp_update_comment()` results being `false`, as the function always returns a `WP_Error` object now if `$wp_error` is true. Follow-up to [48154], [48215], [48216]. See #39732. Built from https://develop.svn.wordpress.org/trunk@48218 git-svn-id: http://core.svn.wordpress.org/trunk@47987 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-xmlrpc-server.php | 2 +- wp-includes/comment.php | 12 ++++++++++-- .../endpoints/class-wp-rest-comments-controller.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index d015964f0a..c96104ccfa 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -3789,7 +3789,7 @@ class wp_xmlrpc_server extends IXR_Server { } $result = wp_update_comment( $comment, true ); - if ( is_wp_error( $result ) || false === $result ) { + if ( is_wp_error( $result ) ) { return new IXR_Error( 500, $result->get_error_message() ); } diff --git a/wp-includes/comment.php b/wp-includes/comment.php index a8cc4dda29..6cc20e18c1 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2503,9 +2503,17 @@ function wp_update_comment( $commentarr, $wp_error = false ) { */ $data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr, $wp_error ); + if ( ! $data ) { + $data = new WP_Error( 'comment_update_canceled', __( 'Comment update canceled.' ) ); + } + // Do not carry on on failure. - if ( is_wp_error( $data ) || ! $data ) { - return $data; + if ( is_wp_error( $data ) ) { + if ( $wp_error ) { + return $data; + } else { + return false; + } } $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 97dbb737c7..d72efedcbc 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -870,7 +870,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $updated = wp_update_comment( wp_slash( (array) $prepared_args ), true ); - if ( is_wp_error( $updated ) || false === $updated ) { + if ( is_wp_error( $updated ) ) { return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), diff --git a/wp-includes/version.php b/wp-includes/version.php index edfafb4d72..821215a3e1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48217'; +$wp_version = '5.5-alpha-48218'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.