Halloween Sale 15% off Ends in See the plans
PHP

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.

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

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

  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.