BuddyDev

Search

[Resolved] Auto create gallery

  • Participant
    Level: Initiated
    Posts: 1
    bjoerndz on #15184

    Good Morning
    This doesnt works, what did i wrong?

    WordPress 4.9.6
    Buddypress 3.0 (templatepack Nouveau)

    /**
     * Creates a gallery
     *  
     * @param array $args
     *	@type int $creator_id owner of the gallery
     *	@type string $title gallery title
     *	@type string $description gallery description
     *  @type string $status possible values( public, private, loggedin etc)
     *	@type string $component possible values( 'members', 'groups' etc)
     *  @type int $component_id owner id( user_id or group id depending on specified $component)
     *	@type string $type media type( possible values photo, audio, video, doc)
     *  
     * @return int|boolean|WP_Error
     */
    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;
    
    }
    
    function mpp_custom_auto_create_gallery() {
    	
    	if ( ! bp_is_my_profile() ) {
    		return ;
    	}
    	
    	//make sure that user gallery functions are available
    	if ( ! function_exists( 'mpp_create_gallery' ) ) {
    		return;
    	}
    	
    	$user_id = get_current_user_id();
    	
    	//does this user has predefined gallery?
    	//we use this check to avoid same type of gallery again and again for the user
    	if ( ! get_user_meta(  $user_id, '_mpp_predefined_gallery_photo_1', true ) ) {
    		
    		$gallery_id = mpp_custom_create_gallery( array(
    			'title'	=> 'Smple Gallery 1',
    			'type'	=> 'photo', //can be 'audio', 'video', 'doc'
    			'status'=> mpp_get_default_status()
    			
    		) );
    		
    	//let us keep the id in usermeta to avoid creating it again, right?
    		if ( $gallery_id && !  is_wp_error( $gallery_id ) ) {
    			update_user_meta( $user_id, '_mpp_predefined_gallery_photo_1', $gallery_id ); //you can change the key to anything
    
    		}
    	
    		
    		
    	}//end of repeatable block
    	
    	//2nd gallery
    	if ( ! get_user_meta(  $user_id, '_mpp_predefined_gallery_photo_2', true ) ) {
    
    		$gallery_id = mpp_custom_create_gallery( array(
    			'title'	=> 'Smple Gallery 2',
    			'type'	=> 'photo', //can be 'audio', 'video', 'doc'
    			'status'=> mpp_get_default_status()
    
    		) );
    
    	//let us keep the id in usermeta to avoid creating it again, right?
    		if ( $gallery_id && !  is_wp_error( $gallery_id ) ) {
    			update_user_meta( $user_id, '_mpp_predefined_gallery_photo_2', $gallery_id ); //you can change the key to anything
    
    		}
    
    		
    		
    	}
    		
    		//3rd gallery
    	if ( ! get_user_meta(  $user_id, '_mpp_predefined_gallery_photo_3', true ) ) {
    
    		$gallery_id = mpp_custom_create_gallery( array(
    			'title'	=> 'Smple Gallery 3',
    			'type'	=> 'photo', //can be 'audio', 'video', 'doc'
    			'status'=> mpp_get_default_status()
    
    		) );
    
    	//let us keep the id in usermeta to avoid creating it again, right?
    		if ( $gallery_id && !  is_wp_error( $gallery_id ) ) {
    			update_user_meta( $user_id, '_mpp_predefined_gallery_photo_3', $gallery_id ); //you can change the key to anything
    
    		}
    
    	}
    	
    	//and so on
    
    }
    
    add_action( 'mpp_actions', 'mpp_custom_auto_create_gallery' );
  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #15199

    Hi @bjoerndz

    I haven’t tested the above code on BP 3.0. I don’t see any issue though.

    Will check and get back to you later today.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 1
    bjoerndz on #15241

    Hi Brajesh
    any news for me ?

    Regards
    Björn

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #15242

    Hello Bjoerndz,

    I have checked this code on WordPress 4.9.6 with BuddyPress 3.0 ( Nouveau ) and it is working fine. Where you have put this code i.e. Active Theme “functions.php” or “bp-custom.php” file. Also try with newly register user weather it creates default galleries or not. Please let me know.

    Thank You
    Ravi

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #20945

    Closing it and marking as resolved .

You must be logged in to reply to this topic.

This topic is: resolved