Display only my own files/images in media library

I just want to let user see only their own files in media library.
I have 2 questions:

  1. it works great on list of media library.

    Read More
    add_action('pre_get_posts','users_own_attachments');
     function users_own_attachments( $wp_query_obj ) {
    
     global $current_user, $pagenow;
    
    //echo 'pagenow='.$pagenow;
    
      if( !is_a( $current_user, 'WP_User') )
       return;
    
      if( 'upload.php' != $pagenow )
        return;
    
      if( !current_user_can('delete_pages') )
       $wp_query_obj->set('author', $current_user->id );
    
         return;
    }
    

But when you upload files with modal (lightbox) media libray, it shows all of files.

I have an avatar uploader in you profile page (/wp-admin/profile.php). when I click upload from media library. it popup a modal and shows all of files even not my own files.

How can I make it the popup modal to show only my files/ pictures?

  1. I have an avatar uploader on front-end too.
    I also need to make it show only own pictures on media modal.

How I could add the page? I did echo $pagenow; it’s all index.php.

I believe that if my 1st question has a solution then it would be fine with front end as well.

Related posts