Home Forums Front-end Issues Hiding media library from users


Hiding media library from users

  • I am using the acf_form() function to displays a front end form for submitting data for my custom field type.

    One of the fields is the image upload. It works fine, but I do not want to display my whole media library to users. I just want a basic, native file uploader. I do not want guests to see my whole library.

    Do I have to create a whole new field type for this or are there alternatives?

  • Hi @dkjensen

    This issue is a current limitation of the WP media library popup.

    It is only possible to limit the media library to ‘uploaded to a specific post’ or ‘not connected with a post’.

    When you are editing a user, the images available are the ones which are not connected with posts.

    It is possible for you to tell ACF to use the basic uploader (no media library popup) with this code:

    acf_update_setting(‘uploader’, ‘basic’);
    Perhaps you could hook into the admin_head and check if that page is an edit user page? Then run this code?

  • Howdy,

    I recently found this, which is working for me

    add_filter( 'posts_where', 'devplus_attachments_wpquery_where' );
    function devplus_attachments_wpquery_where( $where ){
    	global $current_user;
    	if( is_user_logged_in() ){
    		// we spreken over een ingelogde user
    		if( isset( $_POST['action'] ) ){
    			// library query
    			if( $_POST['action'] == 'query-attachments' ){
    				$where .= ' AND post_author='.$current_user->data->ID;
    	return $where;

    Hope it helps!

  • This worked for me too. However, I ran into issues with the gallery field. After the first submission, if you get back to the same form, it won’t set the selected media. So, I am use the following code.

    add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );
    function wpb_show_current_user_attachments( $query ) {
        $user_id = get_current_user_id();
        if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
    ') ) {
            $query['author'] = $user_id;
        return $query;
  • Where can I add acf_update_setting('uploader', 'basic'); to force all image fields to use the uploader instead of popping up the image / media library?


Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Hiding media library from users’ is closed to new replies.