Restrict Media Library so users only see own media

There are no settings within Access to limit who can see what content in the Media Library.

You can use the WordPress filter ‘ajax_query_attachments_args’ to add restrictions, such as to only show a user their own media, like so:

add_filter( 'ajax_query_attachments_args', 'show_current_user_attachments', 10, 1 );
function show_current_user_attachments( $query = array() ) {

    $user_id = get_current_user_id();
    if( $user_id ) {
        $query['author'] = $user_id;
    }
    return $query;
}

From https://codex.wordpress.org/Plugin_API/Filter_Reference/ajax_query_attachments_args#Examples


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments