Forgotten Drafts Widget
Adds a dashboard widget listing drafts nobody has touched for over 30 days, oldest first, with their author, so half-finished ideas get finished or cleaned up.
Opens WPIDE on
Code
// Days without changes before a draft counts as forgotten.
$wpide_forgotten_days = 30;
add_action( 'wp_dashboard_setup', function () use ( $wpide_forgotten_days ) {
wp_add_dashboard_widget( 'wpide_forgotten_drafts', 'Forgotten drafts', function () use ( $wpide_forgotten_days ) {
$args = array(
'post_type' => array( 'post', 'page' ),
'post_status' => 'draft',
'posts_per_page' => 10,
'orderby' => 'modified',
'order' => 'ASC',
'no_found_rows' => true,
'date_query' => array( array( 'column' => 'post_modified_gmt', 'before' => $wpide_forgotten_days . ' days ago' ) ),
);
if ( ! current_user_can( 'edit_others_posts' ) ) {
$args['author'] = get_current_user_id();
}
$drafts = get_posts( $args );
if ( ! $drafts ) {
echo '<p>No forgotten drafts.</p>';
return;
}
echo '<ul>';
foreach ( $drafts as $draft ) {
printf(
'<li><a href="%s">%s</a><br><small>%s · last edited %s ago</small></li>',
esc_url( get_edit_post_link( $draft ) ),
esc_html( get_the_title( $draft ) ? get_the_title( $draft ) : '(no title)' ),
esc_html( get_the_author_meta( 'display_name', $draft->post_author ) ),
esc_html( human_time_diff( get_post_modified_time( 'U', true, $draft ) ) )
);
}
echo '</ul>';
} );
} );
Notes
Editors see everyone's drafts; authors only see their own.
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.