Make WordPress Core

Opened 6 years ago

Last modified 5 weeks ago

#50255 assigned defect (bug)

get_the_modified_author() not working for posts updated via REST API

Reported by: stilldreaming's profile stilldreaming Owned by: westonruter's profile westonruter
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: needs-patch
Focuses: rest-api 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/

Change History (10)

#1 @SergeyBiryukov
6 years ago

  • Component changed from General to Posts, Post Types

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


4 years ago

#3 @kurtrank
10 months ago

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.

#4 @westonruter
7 weeks ago

  • Milestone changed from Awaiting Review to 6.9

#5 @westonruter
7 weeks ago

  • Keywords needs-patch added
  • Owner set to westonruter
  • Status changed from new to assigned

#6 @westonruter
7 weeks ago

  • Focuses rest-api added
  • Summary changed from get_the_modified_author() not working to get_the_modified_author() not working for posts updated via REST API

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


6 weeks ago

#8 @SirLouen
6 weeks ago

  • Milestone changed from 6.9 to 7.0
  • Version 5.4.1 deleted

Punting to 7.0

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


5 weeks ago

#10 @SirLouen
5 weeks ago

  • Milestone changed from 7.0 to Future Release

I punted to 7.0, but given that it doesn't even have a patch, I think it would be better to move it to Future Release and once it's a little more warmed up, add it to 7.0.

Note: See TracTickets for help on using tickets.