diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
index 8a13723..de5e865 100644
a
|
b
|
function wp_update_comment($commentarr) { |
2143 | 2143 | // First, get all of the original fields |
2144 | 2144 | $comment = get_comment($commentarr['comment_ID'], ARRAY_A); |
2145 | 2145 | if ( empty( $comment ) ) { |
2146 | | return 0; |
| 2146 | /** |
| 2147 | * Filters the error return value of wp_update_comment(). |
| 2148 | * |
| 2149 | * Allows returning a value different than zero, which also indicates a |
| 2150 | * successful update with no changed data. |
| 2151 | * |
| 2152 | * @since 4.7.0 |
| 2153 | * |
| 2154 | * @param mixed $error The error return value. |
| 2155 | */ |
| 2156 | return apply_filters( 'wp_update_comment_error', 0 ); |
2147 | 2157 | } |
2148 | 2158 | |
2149 | 2159 | // Make sure that the comment post ID is valid (if specified). |
2150 | 2160 | if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { |
2151 | | return 0; |
| 2161 | /** This filter is documented in wp-includes/comment.php */ |
| 2162 | return apply_filters( 'wp_update_comment_error', 0 ); |
2152 | 2163 | } |
2153 | 2164 | |
2154 | 2165 | // Escape data pulled from DB. |
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index e6f7920..9fd4743 100644
a
|
b
|
class WP_REST_Comments_Controller extends WP_REST_Controller { |
644 | 644 | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
645 | 645 | } |
646 | 646 | |
| 647 | add_filter( 'wp_update_comment_error', '__return_false' ); |
647 | 648 | $updated = wp_update_comment( $prepared_args ); |
| 649 | remove_filter( 'wp_update_comment_error', '__return_false' ); |
648 | 650 | |
649 | | if ( 0 === $updated ) { |
| 651 | if ( false === $updated ) { |
650 | 652 | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
651 | 653 | } |
652 | 654 | |
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index a8526c8..23d6e49 100644
a
|
b
|
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase |
1586 | 1586 | $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] ); |
1587 | 1587 | } |
1588 | 1588 | |
| 1589 | public function test_update_item_no_change() { |
| 1590 | wp_set_current_user( self::$admin_id ); |
| 1591 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| 1592 | $response = $this->server->dispatch( $request ); |
| 1593 | $this->assertEquals( 200, $response->get_status() ); |
| 1594 | } |
| 1595 | |
1589 | 1596 | public function test_update_comment_status() { |
1590 | 1597 | wp_set_current_user( self::$admin_id ); |
1591 | 1598 | |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index cdd5ec0..8a0948f 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
1556 | 1556 | $this->assertEquals( $params['excerpt'], $post->post_excerpt ); |
1557 | 1557 | } |
1558 | 1558 | |
| 1559 | public function test_update_item_no_change() { |
| 1560 | wp_set_current_user( self::$editor_id ); |
| 1561 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1562 | $response = $this->server->dispatch( $request ); |
| 1563 | $this->check_update_post_response( $response ); |
| 1564 | } |
| 1565 | |
1559 | 1566 | public function test_rest_update_post() { |
1560 | 1567 | wp_set_current_user( self::$editor_id ); |
1561 | 1568 | |
diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php
index df2c030..702f6f8 100644
a
|
b
|
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
542 | 542 | $this->assertEquals( 'new-slug', $data['slug'] ); |
543 | 543 | } |
544 | 544 | |
| 545 | public function test_update_item_no_change() { |
| 546 | wp_set_current_user( self::$administrator ); |
| 547 | $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); |
| 548 | $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); |
| 549 | $response = $this->server->dispatch( $request ); |
| 550 | $this->assertEquals( 200, $response->get_status() ); |
| 551 | } |
| 552 | |
545 | 553 | public function test_update_item_invalid_term() { |
546 | 554 | wp_set_current_user( self::$administrator ); |
547 | 555 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php
index 09e11a6..6108a7b 100644
a
|
b
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
840 | 840 | $this->assertEquals( $pw_before, $user->user_pass ); |
841 | 841 | } |
842 | 842 | |
| 843 | public function test_update_item_no_change() { |
| 844 | $this->allow_user_to_manage_multisite(); |
| 845 | wp_set_current_user( self::$user ); |
| 846 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); |
| 847 | $response = $this->server->dispatch( $request ); |
| 848 | $this->assertEquals( 200, $response->get_status() ); |
| 849 | } |
| 850 | |
843 | 851 | public function test_update_item_existing_email() { |
844 | 852 | $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); |
845 | 853 | $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) ); |