Make WordPress Core

Opened 6 years ago

Last modified 3 months ago

#50255 assigned defect (bug)

get_the_modified_author() not working for posts updated via REST API

Reported by: stilldreaming Owned by: westonruter
Priority: normal Milestone: Future Release
Component: Posts, Post Types Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: rest-api

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 (11)

#1 @SergeyBiryukov
6 years ago

  • Component GeneralPosts, Post Types

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


5 years ago

#3 @kurtrank
18 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
10 months ago

  • Milestone Awaiting Review6.9

#5 @westonruter
10 months ago

  • Keywords needs-patch added
  • Owner set to westonruter
  • Status newassigned

#6 @westonruter
10 months ago

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

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


10 months ago

#8 @SirLouen
10 months ago

  • Milestone 6.97.0
  • Version 5.4.1

Punting to 7.0

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


9 months ago

#10 @SirLouen
9 months ago

  • Milestone 7.0Future 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.

This ticket was mentioned in PR #11793 on WordPress/wordpress-develop by @sukhendu2002.


3 months ago
#11

  • Keywords has-patch has-unit-tests added; needs-patch removed
Note: See TracTickets for help on using tickets.