Support

Account

Home Forums Add-ons Gallery Field Gallery field showing all media

Solved

Gallery field showing all media

  • Hi,

    I love the Gallery field plugin, its really nice. I’m building a
    wedding vendors directory (photographers, wedding planners, designers) and I would like users to be able to have their own profile and upload a gallery.

    I have everything working, except for the problem that when I use the Media Library, the user has access to all gallery images that have been previously uploaded.

    Is there a way individual users can create a gallery without looking at someone’s else media?

    Thanks!

  • You can use this code in your functions.php file

    // Restrict media library to show only own user files
    add_action('pre_get_posts','ml_restrict_media_library');
    function ml_restrict_media_library( $wp_query_obj ) {
    
    	global $current_user, $pagenow;
    
    	if( !is_a( $current_user, 'WP_User') )
    
    		return;
    
    	if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
    
    		return;
    
    	if( !current_user_can('delete_pages') )
    
    		$wp_query_obj->set('author', $current_user->ID );
    
    	return;
    
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.