#55420 closed defect (bug) (fixed)
Warning thrown by method get_the_modified_author if author was removed
Reported by: | juanlopez4691 | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Users | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
If a post has been last modified by a removed author, method get_the_modified_author
throws a warning:
Warning: Attempt to read property "display_name" on bool in htdocs/wp-includes/author-template.php on line 104
This happens because get_userdata
returns false if the user that modified the post last no longer exists.
A possible solution:
Modify file wp-includes/author-template.php
, line 104, from
return apply_filters( 'the_modified_author', $last_user->display_name );
to
return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
Attachments (2)
Change History (11)
This ticket was mentioned in PR #2430 on WordPress/wordpress-develop by juanlopez4691.
3 years ago
#2
- Keywords has-patch added
#3
@
3 years ago
- Version 5.9.2 deleted
Hi there!
Welcome to Trac and thanks for the ticket and patch.
Can you please share steps to replicate the issue because I can't replicate it from the given instruction?
#4
@
3 years ago
@mukesh27 You can try as follows:
- Log in admin create a post with any existing user.
- Create a new user.
- Logout and login back as user /2/.
- Modify the post created in /1/
- Log out and login back as user /1/ (should have administrator role).
- Delete user #2.
The result is:
postmeta
field_edit_last
for the modified post is still holding the removed user /2/.- Using method
get_the_modified_author
to retrieve the name of the user who last modified post #1 raises a warning, as described in the ticket.
My proposed patch is just a defensive measure similar to what is applied in method get_the_author_meta
, line 175 (https://bit.ly/3N91DIi).
Another possible solution could be to modify file wp-includes/author-template.php
, line 104
from
return apply_filters( 'the_modified_author', $last_user->display_name );
to
return apply_filters( 'the_modified_author', empty( $last_user ) ? '' : $last_user->display_name );
#5
@
3 years ago
Thanks for the steps.
If I try to remove a user from WordPress it shows me the attached screen in which the first option removes posts/content that the user added on the site. If you select the 2nd option then it will assign a new author in the post/content which old author created.
How do you delete the user?
#6
@
3 years ago
@mukesh27 Just the same way. The problem is that attributing a new user to all posts created by the removed user do not fix the _edit_last
postmeta entries for those posts. It just updates column post_author
in the posts
table.
Is not about who created the posts, but who modified them the last.
A warning is thrown when retrieving the the last author that modified the post if that user was removed.
See https://core.trac.wordpress.org/ticket/55420
Trac ticket: [](https://core.trac.wordpress.org/ticket/55420)