[wp-trac] [WordPress Trac] #39732: Allowing wp_update_comment() to return WP_Error

WordPress Trac noreply at wordpress.org
Thu Jan 23 22:04:12 UTC 2020


#39732: Allowing wp_update_comment() to return WP_Error
-------------------------------------------------+-------------------------
 Reporter:  enrico.sorcinelli                    |       Owner:
                                                 |  enrico.sorcinelli
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  5.4
Component:  Comments                             |     Version:  4.8
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests early       |     Focuses:
  needs-dev-note                                 |
-------------------------------------------------+-------------------------
Changes (by imath):

 * keywords:
     has-patch has-unit-tests needs-testing early needs-refresh needs-dev-
     note
     => has-patch has-unit-tests early needs-dev-note


Comment:

 Hi thanks a lot @enrico.sorcinelli for your contributions and patches
 about this ticket.

 I've updated the patch to current trunk and made the following edits in
 [https://core.trac.wordpress.org/attachment/ticket/39732/39732.9.patch
 39732.9.patch]

 1. I think it's safer to return what was used before if the `$wp_error`
 argument is true. That is to say `0`.
 2. I've edited what was done for the `'wp_update_comment_data'` as I
 believe the WP_Error object never makes its way there as it is returned,
 so we must keep the comment `$data` unchanged. I believe it is better to
 pass the `$wp_error` argument to inform the plugin what type of return is
 expected if it's needed to stop the update process.
 3. I believe it's wrong to return an error if the comment data has not
 changed because it prevents the comment meta update. So I removed the code
 you added after the `$wpdb->update()` part.
 4. In `edit_comment()` we need to return the result of the update process
 and do the `wp_die()` into the comment edit screen otherwise we are
 redirected even if there was an error.
 5. We need to adapt `wp_ajax_edit_comment()` to eventually return the
 error.
 6. I've run `composer format` on all edited files.
 7. I've tested the patch from the form of the `wp-admin/comment.php`
 screen. I confirm it works as expected.
 8. I've tested the patch using the Quick edit (Ajax) link of a listed
 comment of the `wp-admin/edit-comments.php` screen. I confirm it works as
 expected.
 9. I've run `phpunit --group comment`, `phpunit --group ajax` & `phpunit
 --group restapi` and I confirm tests passed successfully.

 @davidbaumwald could you have a look at it and check if it's good to be
 committed?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39732#comment:35>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list