Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#51370 closed defect (bug) (fixed)

Errors in the wp_dropdown_users() function when specifying a non-existent user

Reported by: campusboy1987's profile campusboy1987 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version: 5.5.1
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:



When editing a page whose author was deleted in the classic editor, the metabox with the author's choice generates a "Notice"error.

When the Metabox is called by the post_author_meta_box () function, the wp_dropdown_users () function is run, where one of the parameters is:

'selected' => empty( $post->ID ) ? $user_ID : $post->post_author,

This causes the following section of code to run:

$users[] = get_userdata( $parsed_args['selected'] );

But since the page author is deleted, get_userdata() returns false and the data will still be added to the list of users, which generates an error when composing user data, since the code expects an object of the WP_User class.

Example of an error in the log file:

Trying to get property 'display_name' of non-object in ..\wp-includes\user.php on line 1208
Trying to get property 'user_login' of non-object in ..\wp-includes\user.php on line 1208
Trying to get property 'ID' of non-object in ..\wp-includes\user.php on line 1215
Trying to get property 'ID' of non-object in ..\wp-includes\user.php on line 1216

Change History (4)

This ticket was mentioned in PR #545 on WordPress/wordpress-develop by campusboy87.

4 years ago

  • Keywords has-patch added

Added a check for the existence of a user, since the function can get the ID of the user (for example, the author of the page) that was deleted.

Trac ticket:

#2 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49036:

Users: Check if the user ID passed as selected to wp_dropdown_users() corresponds to an existing user.

This avoids a few PHP notices if the include_selected parameter was specified and a non-existing user ID was passed.

Props campusboy1987.
Fixes #51370.

Note: See TracTickets for help on using tickets.