Opened 5 years ago
Last modified 8 weeks ago
#50255 new defect (bug)
get_the_modified_author() not working
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.4.1 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
It seems that get_the_modified_author() is not working.
Looking at the source code of the function I noticed that the _edit_last meta field is not filled for the specific post, even though the post was edited.
After a closer look it seems that _edit_last is not in the meta data for regular posts and for pages (though I noticed it was there for the standard privacy page). It is there for custom posts.
So it seems that get_the_modified_author() is not working for pages and regular posts.
I looked at wp_check_post_lock() and saw that this function takes another approach. It looks at the _edit_lock field. This field is still there after the editing is over.
So, this piece of code works for pages, posts and custom posts:
<?php function abc_get_user_id( $post_id ) { $lock = get_post_meta( $post_id, '_edit_lock', true ); if ( ! $lock ) { return 0; } $lock = explode( ':', $lock ); $time = $lock[0]; $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); return $user; }
In this case the user who modified the page/post is part of another field, which makes it harder to filter for that.
My suggestion would be to make _edit_last work again, or have a specific field in the post object, just like post_modified and post_modified_gmt that are used for the modification date/time. This would make it easier to filter also.
The functions get_the_modified_date() and get_the_modified_time() are working correctly.
I have tested this on WP 5.4.1
This was discussed in the forum here:
https://wordpress.org/support/topic/get_the_modified_author-not-working/
I just ran into this as well. I found that some post types were not showing the last modified author and instead defaulting to the original author that created it. From my testing it seems post types that do not have legacy meta boxes do not set
_edit_last
in the database, so I would guess that step is missing from the REST API function that saves post data.