BuddyDev

Search

[Resolved] Default galleries for every group or single mixed media gallery

  • Participant
    Level: Enlightened
    Posts: 40
    Jaume Aragay on #3235

    Is there a way to have 4 default galleries (with their default names) created on group creation, one for each allowed media type? I want consistent gallery names from group to group and want only one gallery for each media type in every group.

    It may work disabling “new gallery” options once the group has been created if the first (and only) 4 galleries named “images”, “docs”, “music” and “video” are created by default on group creation.

    By the way, why is not a single gallery with mixed media allowed?

  • Keymaster
    (BuddyDev Team)
    Posts: 21849
    Brajesh Singh on #3238

    Hi Jaume,
    1. Automatic gallery creation is easily doable. I have posted the codes in the forum for that for users. In your case, @ravi1987 will post the code for BuddyPress group creation trigger.

    2. Technically, we have the functionality to allow mixed gallery. But we don’t have any plans to enable it anytime soon. The reason is User interface. Displaying mixed media in single gallery is going to make the layout look awful and that’s the reason we haven’t enabled it.

    Hope that helps.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2461
    Ravi on #3241

    Hi Jaume,

    Please check the following code in your bp-custom.php file.

    
    function mpp_custom_create_gallery( $args ) {
    
    	$user_id = get_current_user_id();
    
    	$default = array(
    		'creator_id'	 => $user_id,
    		'title'			 => '',
    		'description'	 => '', //add description if any
    		'status'		 => mpp_get_default_status(),//can use any of the status e.g. 'public' , 'private', 'loggedin', 'friends' etc
    		'component'		 => 'members',//for user
    		'component_id'	 => $user_id,//no need to change
    		'type'			 => 'photo', //can change to "audio", "video", "doc"
    	);
    
    	$args = wp_parse_args( $args, $default );
    
    	$gallery_id = mpp_create_gallery( $args );
    
    	return $gallery_id;
    
    }
    //Automatic gallery creation for groups on group create
    function mpp_custom_create_default_group_galleries( $group_id, $group ) {
    	//make sure that you have enabled all these types in your Admin MediaPress setiings for the groups component
    	$types = array('photo' =>  'Images', 'video' => 'Video', 'audio'=> 'Music', 'doc'=> 'Docs' );
    
    	foreach ( $types as  $type => $label ) {
    
    		if ( ! mpp_component_supports_type( 'groups', $type ) ) {
    			continue;//component does not support this type
    		}
    		$gallery_id =  mpp_get_wall_gallery_id( array(
    			'component'     => 'groups',
    			'component_id'  => $group_id,
    			'media_type'    => $type
    		) );
    
    		if ( ! $gallery_id ) {
    			//let us create one
    			$gallery_id = mpp_custom_create_gallery( array(
    				'title'	=> $label,
    				'type'	=> $type,
    				'status'=> mpp_get_default_status(),
    				'component' => 'groups',//for user
    				'component_id'  => $group_id,
    			) );
    
    			mpp_update_wall_gallery_id(
    				array(
    					'component' => 'groups',
    					'component_id'  => $group_id,
    					'gallery_id'    => $gallery_id,
    					'media_type'    => $type
    				)
    			);
    
    		}
    
    	}
    
    	//and so on
    
    }
    add_action( 'groups_created_group', 'mpp_custom_create_default_group_galleries', 0, 2 );
    
    function mpp_custom_disable_user_to_create_group_gallery( $can_do, $component, $component_id ) {
    
    	if ( $component == 'groups' && ! is_super_admin() ){
    		$can_do = false;
    	}
    
    	return $can_do;
    }
    add_filter( 'mpp_user_can_create_gallery', 'mpp_custom_disable_user_to_create_group_gallery', 10, 3 );

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 40
    Jaume Aragay on #3260

    Works great! 😀

    Thanks!

    Jaume.

You must be logged in to reply to this topic.

This topic is: resolved