Just use the author name?
How?
If I use the_author
it shows only the name of the user that has wirtten the page/post.
But I want to show the name of the user that has edited the page/post the last time.
I use WP as CMS. There are several users having rights to edit posts and pages. In the frontend the name should be showed so that it’s apparent who is responsible for each page/post.
There must be a possibility to show the editor’s name. Because in the backend, it’s shown when you edit a existing page/post (under the SAVE-button).
In wp-admin/post.php I found the following code:
if ( $last = wp_check_post_lock( $post->ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
$message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
$message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
With this code, the user that has edited the post the last time is presented, isn’t it?
And output with:
echo $last_user_name;
But the function “wp_check_post_lock( $post->ID )” should be replaced. Unfortunately, I’ve no idea, with which other function.
Well, at last I’ve found the answer on my own. While searching the admin-files, I found the right code:
<?php
$post_ID = get_the_ID();
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
printf(__('Last edited by %1$s on %2$s at %3$s'), wp_specialchars( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'),
$post->post_modified));
};
?>
Thanks for this! I was just looking for the same thing today.
Is there some way to display this ONLY if the user is logged in and is an admin?
Thanks in advance for any solutions!