Wordpress Media manager is a very good tools, but it was designed to act as media pools for all user in the site, sometimes we want to limit the media displayed in Media uploader to show only the media that current user actually owned.

In that case we will need to add a filter to wordpress query, an additional sql query limit that will limit the searched data for media file owner only.

We can add a new filter by invoking the filter 'parse_query' like this :

<?php

// Add Filter for parsing query
add_filter('parse_query', array('limitMedia', 'ParseQuery'));

?>

Then in our custom class we perform the task to add extra additional limit to sql query as follow :

<?php

class limitMedia {

  /**
   * Encapsulating filter parse_query
   *
   * @param object $wp_query
   */
  public function ParseQuery($wp_query) {
    global $current_user;
     
    // User can only view their own uploaded files
    if (isset($_POST['action']) 
        && $_POST['action'] == 'query-attachments') {

      // Adding extra query parameter to limit sql for current user 
      $wp_query->set('author', $current_user->ID);
    }
  }
}

?>

It is also possible to extend the function to limit the query only for user with certain roles, this can be done in such way :

<?php
class limitMedia {
  /**
   * Encapsulating filter parse_query
   *
   * @param object $wp_query
   */
  public function ParseQuery($wp_query) {
    global $current_user;

    $limitedRole = 'editor'; // Editor is limited to see their own files

    if (in_array($limitedRole, $current_user->roles)) { 
      
      // User can only view their own uploaded files
      if (isset($_POST['action']) 
        && $_POST['action'] == 'query-attachments') {
      
        $wp_query->set('author', $current_user->ID);
      } 
  }
}
?>