Halloween Sale 15% off Ends in See the plans
PHP

"Recently Edited" Menu in the Admin Bar

Adds a menu to the admin bar listing the last eight posts and pages you edited, with their status, so you can jump back into your work from anywhere on the site.

Don’t have WPIDE yet? Install it on your site

Code

// Number of items to list.
$wpide_recent_count = 8;

add_action( 'admin_bar_menu', function ( $admin_bar ) use ( $wpide_recent_count ) {
    if ( ! current_user_can( 'edit_posts' ) ) {
        return;
    }

    $posts = get_posts( array(
        'post_type'      => 'any',
        'post_status'    => array( 'publish', 'draft', 'pending', 'future', 'private' ),
        'posts_per_page' => $wpide_recent_count,
        'orderby'        => 'modified',
        'meta_key'       => '_edit_last',
        'meta_value'     => get_current_user_id(),
        'no_found_rows'  => true,
    ) );

    if ( ! $posts ) {
        return;
    }

    $admin_bar->add_node( array(
        'id'    => 'wpide-recent-edits',
        'title' => '<span class="ab-icon dashicons dashicons-backup" style="margin-top:2px" aria-hidden="true"></span><span class="ab-label">Recent</span>',
    ) );

    foreach ( $posts as $post ) {
        $admin_bar->add_node( array(
            'id'     => 'wpide-recent-' . $post->ID,
            'parent' => 'wpide-recent-edits',
            'title'  => esc_html( wp_trim_words( get_the_title( $post ) ? get_the_title( $post ) : '(no title)', 8 ) . ( 'publish' !== $post->post_status ? ' - ' . $post->post_status : '' ) ),
            'href'   => get_edit_post_link( $post->ID, 'url' ),
        ) );
    }
}, 80 );

Notes

Based on WordPress's own "last edited by" record; change $wpide_recent_count for a longer list.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.