WordPress.org

Ready to get started?Download WordPress

Ideas

Recent drafts on dashboard - see drafts and pendings of all users

  1. Marco
    Member

    12345

    Id like to have a better recent draft widget on the dashboard. Best would be on that I can customize in the options menu.

    I got a blog with me as admin, one editor and a lot of journalists.

    The editor and me should see all drafts and pendings on the dashboard to edit and publish them.

    I "hacked" the code for this option into my wordpress. Here is the code I use right now:

    function wp_dashboard_recent_drafts( $drafts = false ) {
    	if ( !$drafts ) {
    		$pendings_query = new WP_Query( array(
    			'post_type' => 'post',
    			'post_status' => 'pending',
    			'posts_per_page' => 150,
    			'orderby' => 'modified',
    			'order' => 'DESC'
    		) );
    		$pendings =& $pendings_query->posts;
    
    		$drafts_query = new WP_Query( array(
    			'post_type' => 'post',
    			'post_status' => 'draft',
    			'posts_per_page' => 150,
    			'orderby' => 'modified',
    			'order' => 'DESC'
    		) );
    		$drafts =& $drafts_query->posts;
    	}
    
    	if ( $drafts && is_array( $drafts ) || $pendings && is_array( $pendings )) {
    		$list = array();
    		foreach ( $pendings as $pending ) {
    			$url = get_edit_post_link( $pending->ID );
    			$title = _draft_or_post_title( $pending->ID );
    			$last_id = get_post_meta( $pending->ID, '_edit_last', true);
    			$last_user = get_userdata($last_id);
    			$last_modified = '<i>' . esc_html( $last_user->display_name ) . '</i>';
    			$item = '<h4><a href="' . $url . '" title="' . sprintf( __( 'Edit “%s”' ), esc_attr( $title ) ) . '">' . esc_html($title) . '</a>' . '<abbr> ' . __('Pending') . '</abbr>' . '<abbr style="display:block;margin-left:0;">' . sprintf(__('Last edited by %1$s on %2$s at %3$s'), $last_modified, mysql2date(get_option('date_format'), $pending->post_modified), mysql2date(get_option('time_format'), $pending->post_modified)) . '</abbr></h4>';
    			if ( $the_content = preg_split( '#\s#', strip_tags( $pending->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
    				$item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
    			$list[] = $item;
    		}
    		foreach ( $drafts as $draft ) {
    			$url = get_edit_post_link( $draft->ID );
    			$title = _draft_or_post_title( $draft->ID );
    			$last_id = get_post_meta( $draft->ID, '_edit_last', true);
    			$last_user = get_userdata($last_id);
    			$last_modified = '<i>' . esc_html( $last_user->display_name ) . '</i>';
    			$item = '<h4><a href="' . $url . '" title="' . sprintf( __( 'Edit “%s”' ), esc_attr( $title ) ) . '">' . esc_html($title) . '</a>' . '<abbr> ' .  __('Draft') . '</abbr>' . '<abbr style="display:block;margin-left:0;">' . sprintf(__('Last edited by %1$s on %2$s at %3$s'), $last_modified, mysql2date(get_option('date_format'), $draft->post_modified), mysql2date(get_option('time_format'), $draft->post_modified)) . '</abbr></h4>';
    			if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
    				$item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
    			$list[] = $item;
    		}
    ?>
    	<ul>
    		<li><?php echo join( "</li>\n<li>", $list ); ?></li>
    	</ul>
    <?php
    	} else {
    		_e('There are no drafts at the moment');
    	}
    Posted: 3 years ago #
  2. Jon Lynch
    Member

    I have made some minor changes to the above and then published it as a plugin available at the plugin repository.

    Hope you don't mind Marco?

    Posted: 2 years ago #
  3. Thanks for the changes :)

    Looking good to me

    Posted: 2 years ago #
  4. Sven
    Member

    Thanks a lot. It is great, for handling our editors that really makes sense.

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    2 Votes
  • Status

    This is plugin territory