Halloween Sale 15% off Ends in See the plans
PHP

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.

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

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

  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.