This Q&A 显示如何限制用户角色能够在仪表板中看到的帖子。缺少附件部分,即:
add_filter( \'pre_get_posts\', \'wpse_72278_current_author_media\' );
add_filter( \'views_upload\', \'wpse_72278_custom_view_count\', 10, 1 );
function wpse_72278_current_author_media( $query )
{
global $pagenow, $user_ID;
if( \'upload.php\' !== $pagenow )
return $query;
if ( $query->is_admin && current_user_can( \'editor\' ) )
$query->set( \'author\', $user_ID );
return $query;
}
function wpse_72278_custom_view_count( $views )
{
global $user_ID, $wpdb;
if ( !current_user_can(\'editor\') )
return $views;
$total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts
WHERE post_author = \'$user_ID\'
AND post_type = \'attachment\' " );
$image = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts
WHERE post_author = \'$user_ID\'
AND post_mime_type LIKE \'image/%\' " );
$video = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts
WHERE post_author = \'$user_ID\'
AND post_mime_type LIKE \'video/%\' " );
$detached = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts
WHERE post_author = \'$user_ID\'
AND post_type = \'attachment\' AND post_parent = \'0\' " );
$views[\'all\'] = preg_replace( \'/\\(.+\\)/U\', \'(\'.$total.\')\', $views[\'all\'] );
$views[\'image\'] = preg_replace( \'/\\(.+\\)/U\', \'(\'.$image.\')\', $views[\'image\'] );
$views[\'video\'] = preg_replace( \'/\\(.+\\)/U\', \'(\'.$video.\')\', $views[\'video\'] );
$views[\'detached\'] = preg_replace( \'/\\(.+\\)/U\', \'(\'.$detached.\')\', $views[\'detached\'] );
return $views;
}
This other 处理一个作者拥有的帖子和另一个作者上传的帖子的问题。
如果你还没有跳到3.5,this last one 处理附件的自定义字段。