Comments: Make wp_update_comment() return false instead of 0 for an invalid comment or post ID.

This addresses an inconsistency where 0 could mean one of the three scenarios:

* Invalid comment ID.
* Invalid comment post ID.
* No DB rows updated. This is not an error and should not be treated as one.

With this change, `wp_update_comment()` always returns either `false` or a `WP_Error` object on failure, depending on the value of the `$wp_error` parameter.

Follow-up to [48154], [48215], [48216], [48218], [48230].

Props dd32, jnylen0, enrico.sorcinelli.
Fixes #39732. See #38700, #39735.
Built from https://develop.svn.wordpress.org/trunk@48235


git-svn-id: http://core.svn.wordpress.org/trunk@48004 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-06-30 14:12:04 +00:00
parent c4f6669d69
commit bf222a442b
2 changed files with 5 additions and 3 deletions

View File

@ -2422,6 +2422,8 @@ function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false
* @since 2.0.0
* @since 4.9.0 Add updating comment meta during comment update.
* @since 5.5.0 The `$wp_error` parameter was added.
* @since 5.5.0 The return values for an invalid comment or post ID
* were changed to false instead of 0.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
@ -2439,7 +2441,7 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
if ( $wp_error ) {
return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) );
} else {
return 0;
return false;
}
}
@ -2448,7 +2450,7 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
if ( $wp_error ) {
return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
} else {
return 0;
return false;
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-48234';
$wp_version = '5.5-alpha-48235';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.