Frontier Restrict Media
Frontier Restrict media will restrict users to only access their own media files
Main Features
- Users without the capability edit_others_posts will only have access to their own media files from the media gallery
Frontier Restrict Media on wordpress.org: Download Plugin | Plugin Support
Code is simple, and if you do not want to install the plugin, you can add the below code to your functions.php
//Restrict users who dont have capability edit_others_posts, to only see media they have uploaded themselves
function my_own_restrict_media($query)
{
//Check if it is an admin query
if ($query->is_admin && !current_user_can( 'edit_others_posts' ))
{
//Check if it is an attachment query
if ($query->query['post_type'] === 'attachment')
{
// Get current user, and author=current user to query
$current_user = wp_get_current_user();
$query->set('author', $current_user->ID);
}
}
return $query;
}
add_filter('pre_get_posts', 'my_own_restrict_media');
Comments
Frontier Restrict Media — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>