[wp-trac] [WordPress Trac] #56662: WP_REST_Users_Controller::update_item(): 'rest_user_invalid_id ' error will never be thrown as `$user` will never be falsey.

WordPress Trac noreply at wordpress.org
Mon Feb 13 23:08:38 UTC 2023


#56662: WP_REST_Users_Controller::update_item(): 'rest_user_invalid_id ' error will
never be thrown as `$user` will never be falsey.
------------------------------+-----------------------------
 Reporter:  jrf               |       Owner:  hellofromTonya
     Type:  defect (bug)      |      Status:  closed
 Priority:  normal            |   Milestone:  6.2
Component:  REST API          |     Version:  4.7
 Severity:  normal            |  Resolution:  fixed
 Keywords:  has-patch commit  |     Focuses:
------------------------------+-----------------------------
Changes (by hellofromTonya):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"55325" 55325]:
 {{{
 #!CommitTicketReference repository="" revision="55325"
 REST API: Remove 'Invalid user ID' error in
 WP_REST_Users_Controller::update_item().

 Removes the `WP_Error` code for `'Invalid user ID.'`. Why?

 tl;dr
 This branch will never be entered as the `$user` will never be falsey.

 Longer reasoning:

 [39954] introduced `WP_REST_Users_Controller::get_user()` method to
 encapsulate getting the user and handling the `'Invalid user ID.'`
 `WP_Error`. It replaced `get_userdata()` in
 `WP_REST_Users_Controller::update_item()` but left the existing `'Invalid
 user ID.'` `WP_Error` introduced in [38832].

 The code removed in this changeset will never be reached because `$user`
 will never be falsey. Rather, `WP_REST_Users_Controller::get_user()` will
 always return an instance of `WP_Error` or `WP_User`.

 Could the user's ID be falsey?
 No. Why? `WP_REST_Users_Controller::get_user()` checks that the user
 exists, which checks if the ID is falsey.

 Therefore, the code can safely be removed.

 Follow-up to [39954], [38832].

 Props jrf, costdev, hellofromTonya, SergeyBiryukov.
 Fixes #56662.
 }}}

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


More information about the wp-trac mailing list