我最后使用了下面的代码。希望有人觉得这有用。
/* Display only user-uploaded files to each user in Media Library for file upload form*/
function user_restrict_media_library( $wp_query_obj ) {
global $current_user, $pagenow;
if( !is_a( $current_user, \'WP_User\') )
return;
if( \'admin-ajax.php\' != $pagenow || $_REQUEST[\'action\'] != \'query-attachments\' )
return;
if( !current_user_can(\'manage_media_library\') )
$wp_query_obj->set(\'author\', $current_user->ID );
return;
}
add_action(\'pre_get_posts\',\'user_restrict_media_library\');