How To Restricting Users To View Only Media Library Items They Upload In WordPress

By default, WordPress allows every author to view all the images in media library, which isn’t a great idea, right? Adding this snippet to WordPress’ current theme’s functions.php file will restrict users to view only media library items they uploaded in the library.

7 thoughts on “How To Restricting Users To View Only Media Library Items They Upload In WordPress”

      1. I think, this will do the job…


        add_action('pre_get_posts','ml_restrict_media_library');
        function ml_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;
        }

Leave a Comment