Limit users to specific uploads

I'd like to restrict users to only see/manage only their own uploads. However, there's a requirement to allow one than one account to manage these uploads. It cannot just be the person who originally uploaded them.

Is this possible?

Topic content-restriction uploads Wordpress

Category Web


Add this code in your Functions.php. This code help you to show user only their own uploads but admin can see all media uploaded by other users and this code is tested on current wordpress Version 5.8

// Limit media library access

add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' 
);

function wpb_show_current_user_attachments( $query ) {
$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && 
!current_user_can('edit_others_posts
 ') ) {
    $query['author'] = $user_id;
}
return $query;
} 

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.