Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#50255 new defect (bug)

get_the_modified_author() not working

Reported by: stilldreaming's profile stilldreaming Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4.1
Component: Posts, Post Types Keywords:
Focuses: Cc:


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:

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:

Change History (2)

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Posts, Post Types

This ticket was mentioned in Slack in #core-editor by talldanwp. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.