• Resolved steff3107

    (@steff3107)


    Hello!

    I wanna show the date the post or page has been updated for the last time and by which user in the frontend.

    For the date, i can user the_modified_date('M j, Y');. But how do I get the name of the user that has edited the post/page the last time? The_author shows only the user who has written the post/page.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Just use the author name?

    Thread Starter steff3107

    (@steff3107)

    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.

    Thread Starter steff3107

    (@steff3107)

    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.

    Thread Starter steff3107

    (@steff3107)

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Showing “Page last edited by….” in frontend’ is closed to new replies.