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
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /var/www/wpfrontier.com/public_html/wp-content/plugins/frontier-buttons/include/frontier-buttons-hooks.php:395 Stack trace: #0 /var/www/wpfrontier.com/public_html/wp-content/plugins/frontier-buttons/include/frontier-buttons-hooks.php(395): implode(Array, ',') #1 /var/www/wpfrontier.com/public_html/wp-includes/class-wp-hook.php(324): frontier_buttons_teeny_init(Array, 'comment') #2 /var/www/wpfrontier.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #3 /var/www/wpfrontier.com/public_html/wp-includes/class-wp-editor.php(804): apply_filters('teeny_mce_befor...', Array, 'comment') #4 /var/www/wpfrontier.com/public_html/wp-includes/class-wp-editor.php(312): _WP_Editors::editor_settings('comment', Array) #5 /var/www/wpfrontier.com/public_html/wp-includes/general-template.php(3971): _WP_Editors::editor('', 'comment', Array) #6 /var/www/wpfrontier.com/public_html/wp-content/plugins/frontier-buttons/include/frontier-buttons-hooks.php(468): wp_editor('', 'comment', Array) #7 /var/www/wpfrontier.com/public_html/wp-includes/class-wp-hook.php(324): frontier_buttons_comments_editor(Array) #8 /var/www/wpfrontier.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #9 /var/www/wpfrontier.com/public_html/wp-includes/comment-template.php(2681): apply_filters('comment_form_de...', Array) #10 /var/www/wpfrontier.com/public_html/wp-content/themes/weaver-xtreme/comments.php(89): comment_form() #11 /var/www/wpfrontier.com/public_html/wp-includes/comment-template.php(1631): require('/var/www/wpfron...') #12 /var/www/wpfrontier.com/public_html/wp-content/themes/weaver-xtreme/single.php(55): comments_template('/comments.php', true) #13 /var/www/wpfrontier.com/public_html/wp-includes/template-loader.php(113): include('/var/www/wpfron...') #14 /var/www/wpfrontier.com/public_html/wp-blog-header.php(19): require_once('/var/www/wpfron...') #15 /var/www/wpfrontier.com/public_html/index.php(17): require('/var/www/wpfron...') #16 {main} thrown in /var/www/wpfrontier.com/public_html/wp-content/plugins/frontier-buttons/include/frontier-buttons-hooks.php on line 395