NotOneBit Blog

Get started today on your next web project with NotOneBit
We've been doing web development before you were born *

Two WordPress Plugins To Improve Your User Management Page (Part 2)

In the second part of this post I’ll show you how you can add a column that lists the total number of pages for a user with a break out of the drafts, pending private, and published. Each element is linked to the respective list of pages. Note that this modification removes the Posts column from the user page, however if you wish to retain it, remove the first five lines (the notonebit_modify_user_columns and the associated add_filter call).


The following code would be added to your theme’s functions.php file.

* Mod to add a pages column with detail to the users page. Also removes the posts column 
add_filter('manage_users_columns', 'notonebit_modify_user_columns');
function notonebit_modify_user_columns( $cols ) {
 return array_merge( $cols, array( 'num_posts' => 'Pages' ) );
function notonebit_count_user_posts_by_type_and_status( $userid, $post_status, $post_type = "post" ) {
 global $wpdb;
 $where = "WHERE post_author = " . $userid . " AND post_type = '" . $post_type . "' AND (post_status = '" . $post_status . "')";
 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
 return $count;
add_action('manage_users_custom_column', 'notonebit_user_posts_count_column_content', 10, 3);
function notonebit_user_posts_count_column_content($output, $column_name, $user_id) {
 $user = get_userdata( $user_id );
 if ( 'num_posts' == $column_name ) {
 $drafts = notonebit_count_user_posts_by_type_and_status( $user_id, 'draft', 'page' );
 $published = notonebit_count_user_posts_by_type_and_status( $user_id, 'publish', 'page' );
 $pending = notonebit_count_user_posts_by_type_and_status( $user_id, 'pending', 'page' );
 $private = notonebit_count_user_posts_by_type_and_status( $user_id, 'private', 'page' );
 $all = $drafts + $published + $pending + $private;
 return 'All: <a href="/wp-admin/edit.php?author='.$user_id.'&amp;post_type=page">'.$all.'</a>
 <br />Draft: <a href="/wp-admin/edit.php?post_status=draft&amp;post_type=page&amp;author='.$user_id.'">'.$drafts.'</a>
 Pending: <a href="/wp-admin/edit.php?post_status=pending&amp;post_type=page&amp;author='.$user_id.'">'.$pending.'</a>
 Published: <a href="/wp-admin/edit.php?post_status=publish&amp;post_type=page&amp;author='.$user_id.'">'.$published.'</a>
 Private: <a href="/wp-admin/edit.php?post_status=private&amp;post_type=page&amp;author='.$user_id.'">'.$private.'</a>';

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: