Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#51370 closed defect (bug) (fixed)

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

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

Description

Hello!

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.


6 years ago
#1

  • 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: https://core.trac.wordpress.org/ticket/51370

#2 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review5.6
  • Owner set to SergeyBiryukov
  • Status newreviewing

#3 @SergeyBiryukov
6 years ago

  • Resolutionfixed
  • Status reviewingclosed

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.