Media library to list images only user uploaded

This works for me in order to list the items uploaded by a user on the media library.

function users_my_media_only( $wp_query ) {
    if ( false !== strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) ) {
        $current_user = wp_get_current_user();
        $current_user = $current_user->ID;
        if ( ! current_user_can( 'manage_options' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}
add_filter('parse_query', 'users_my_media_only' );

It will allow all users with the manage_options capability (usually admin) to see all images, the other users will see only their own images. Note that a few improvements can be made like $pagenow and current_user_can. Not a beauty but it does the job

Leave a Comment