Here is how I solved this:
function current_author_count_posts( $acounts, $type, $perm )
{
if ( 'readable' != $perm || !is_user_logged_in() || current_user_can('administrator') )
return $acounts;
$cache_key = _count_posts_cache_key( $type, $perm );
$counts = wp_cache_get( $cache_key, 'counts_current_author' );
if ( false === $counts ) {
global $wpdb;
$query = $wpdb->prepare( "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_author = %d GROUP BY post_status", $type, get_current_user_id() );
$results = (array) $wpdb->get_results( $query, ARRAY_A );
$counts = array_fill_keys( get_post_stati(), 0 );
foreach ( $results as $row )
$counts[ $row['post_status'] ] = $row['num_posts'];
$counts = (object) $counts;
wp_cache_set( $cache_key, $counts, 'counts_current_author' );
wp_cache_replace( $cache_key, $counts, 'counts' );//replace previously set cache
}
return $counts;
}
function display_posts_for_current_author_only($query)
{
if(!current_user_can('administrator'))
{
global $user_ID;
$query->set('author', $user_ID);
}
return $query;
}
function restrict_admin()
{
add_action('pre_get_posts', 'display_posts_for_current_author_only');
add_filter( 'wp_count_posts', 'current_author_count_posts', 0, 3 );
}
add_action( 'admin_init', 'restrict_admin', 1 );
I am not sure it is the best way, since it runs similar query twice, but it seems that there is no a hook to do it efficiently.
Would you update your plugin in this or a similar way?
Thank you very much.