Recent Drafts From All Authors Widget
Lists the latest drafts from every author on the dashboard, so editors can see what is in progress across the team.
Opens WPIDE on
Code
// How many drafts to list.
$wpide_drafts_widget_count = 10;
add_action( 'wp_dashboard_setup', function () use ( $wpide_drafts_widget_count ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_team_drafts', 'Team Drafts', function () use ( $wpide_drafts_widget_count ) {
$drafts = get_posts( array(
'post_type' => 'any',
'post_status' => 'draft',
'numberposts' => $wpide_drafts_widget_count,
'orderby' => 'modified',
) );
if ( ! $drafts ) {
echo '<p>No drafts right now.</p>';
return;
}
echo '<ul>';
foreach ( $drafts as $draft ) {
$author = get_the_author_meta( 'display_name', $draft->post_author );
printf(
'<li><a href="%1$s">%2$s</a> <span style="color:#646970">by %3$s, %4$s ago</span></li>',
esc_url( get_edit_post_link( $draft->ID ) ),
esc_html( get_the_title( $draft ) ? get_the_title( $draft ) : '(no title)' ),
esc_html( $author ),
esc_html( human_time_diff( get_post_modified_time( 'U', true, $draft ), time() ) )
);
}
echo '</ul>';
} );
} );
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.