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.

//Manage Your Media Only
function mymo_parse_query_useronly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
        if ( !current_user_can( 'level_5' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );

add_filter('parse_query', 'mymo_parse_query_useronly' );