BuddyDev

Search

[Resolved] Mediapress – Predefined User Galleries

  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2466

    Brajesh,

    I tried the codes which you provided. In the front-end it is not showing me the sample album, or option to update that particular album.

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #2467

    Hi,
    My mistake, I forgot the code block to attach the creation function

    Please add this line too

    
    
    add_action( 'mpp_actions', 'mpp_custom_auto_create_gallery' );
    
    
  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2469

    Brajesh,

    The coding is working now. Thanks. I’m now trying to add more galleries and see how it is going to be. Will keep you updated.

    Thanks!

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #2470

    Thank you. I am happy it is working. Please do let me know how it went.

  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2471

    Brajesh,

    I’m still stuck at the level about user-meta thingy. Can you please give me an example, or re-code repetition section with atleast 3 galleries, so I can understand clearly.

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #2472

    Hi,
    No problem. I can do that in a minute. Can you please give me the Name for galleries and type for these galleries.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2473

    Brajesh,

    Thanks for your prompt attention. You can just mention sample names, may be:

    Work Images
    Trip Images

    Let all the types be “images”, later I will change the type according to how you instructed in the coding previously.

    Thanks!

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #2474

    Hi,
    Thank you. The code below is modified code from last step.

    Here, we have broken the auto creation into 2 functions to make it even simpler.

    
    /**
     * 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' );
    
    

    So, please use this code for the last part instead of the previous. I hope, It gives you better idea.

  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2475

    Brajesh,

    Thank you so much for taking time to getting this sorted. I will include the newest coding and see how it works. I will let you know the outcome!

    Thank you so much!

  • Participant
    Level: Initiated
    Posts: 12
    NeoLeo on #2476

    Brajesh,

    It seems like the gallery is now working as expected!

    Thank you so much.

    Only bug I found is, now I have 4 galleries. If I update the code and re-upload the file and then view the albums, it shows the last album twice with 2 different IDs.

    It isn’t a huge issue, I can just delete it off by logging into the admin panel though. Can you check for me why it’s happening, if it’s not that time consuming, please?

    Thanks again for the awesome support!

The topic ‘ [Resolved] Mediapress – Predefined User Galleries’ is closed to new replies.

This topic is: resolved