"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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.