BuddyDev

Search

Only one Gallery per user and auto create gallery during registration

Tagged: 

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #24951

    Hello

    How can I set that only one gallery for one user and auto create that gallery during registration

    Kerrymusic

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #24953

    https://buddydev.com/support/forums/topic/mediapress-predefined-user-galleries/

    I have seen this post and can disable user to create edit and delete gallery but don’t know how to auto create gallery when registration

    And use the Name as the gallery name

    Kerry

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #24955

    This is our Gallery site, we want to have gallery for Magazine cover girl. Each user only have one gallery
    http://cover.y-popstyle.com/

    1. I want the NAME field as the Gallery Name
    2. Auto create ONE gallery when the user registration
    3. No need to have Create Gallery (I follow your instruction and that OK)
    4. The “Drop File Upload Area”, It got the “Please Select Gallery”, I dont need that because I only have one gallery. How can I remove that ?

    I would provide 3 more photos to explain what I want to achieve!
    http://cover.y-popstyle.com/wp-content/uploads/2019/03/buddydev1.png
    http://cover.y-popstyle.com/wp-content/uploads/2019/03/buddydev2.png
    http://cover.y-popstyle.com/wp-content/uploads/2019/03/buddydev3.png

    Thanks a lot

    Kerry

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #24957

    I try myself to follow your example and have some progress!
    1. I can not let user create delete edit Gallery
    2. I can set the Title of the Gallery as the nickname
    3. can Auto create after pressing the Profile

    What I dont know how to do are:
    1. Auto Create during registration
    2. remove the “Please Select Gallery” in upload shortcode, because each user only have one gallery so dont need select

    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();
     $username = $user_id->user_login; 
     $nickname = get_user_meta($user_id, 'nickname', true);
      
     //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 ) ) {
      //No, then we need to create it.
      
    
      //repeat it as you want
      $gallery_id = mpp_create_gallery( array(
       'creator_id'  => $user_id,
       'title'    => $nickname,
       '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"
       ) );
     
      //let us keep the id in usermeta to avoid creating it again, right?
      if ( !  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
     
     //go ahead, do it for other types too
     
     
     
    }
    
    add_action( 'mpp_actions', 'mpp_custom_auto_create_gallery' );
    
  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #24981

    Hi,
    Welcome to BuddyDev.

    Thank you for using MediaPress.

    Here is the code that you can use to create a gallery when a user activates their account.

    
    
    /**
     * Create gallery on user activation.
     *
     * @param int $user_id user id.
     */
    function mpp_custom_create_gallery_on_account_activation( $user_id ) {
    	// make sure that user gallery functions are available.
    	if ( ! function_exists( 'mpp_create_gallery' ) ) {
    		return;
    	}
    
    	$display_name = bp_core_get_user_displayname( $user_id );
    
    	// does this user has predefined gallery?
    	// we use this check to avoid same type of gallery again and again for the user(we most probably don't need it).
    	if ( ! get_user_meta( $user_id, '_mpp_predefined_gallery_photo_1', true ) ) {
    		// No, then we need to create it.
    		// repeat it as you want.
    		$gallery_id = mpp_create_gallery(
    			array(
    				'creator_id'   => $user_id,
    				'title'        => $display_name,
    				'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".
    			)
    		);
    
    		// let us keep the id in usermeta to avoid creating it again, right?
    		if ( ! is_wp_error( $gallery_id ) ) {
    			// you can change the key to anything.
    			update_user_meta( $user_id, '_mpp_predefined_gallery_photo_1', $gallery_id );
    		}
    	}
    }
    
    add_action( 'bp_core_activated_user', 'mpp_custom_create_gallery_on_account_activation' , 2 );
    
    

    Please do not use the shortcode for asking user to upload. Instead, redirect user to their gallery. They can upload from there.

    3. Restricting creation. This is a bit tricky in your case. It is very easy to disable gallery creation. In your case, restricting based on number of gallery is a bit tricky.

    I will see if I can put some code quickly today. Otherwise, will suggest using a plugin.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #24985

    Really Thanks for your reply and your help.

    Yeah, I just use your code and the gallery will be created.

    Another question I search for web and your site about the media listing shortcode. also cannot find the answer.

    As I only have one gallery for one user, therefore, I want user click “myGallery” will just list out all the media but not only one gallery

    I want to list all the media photo of that “USER” if click the menu of “myGallery”, I cannot find ANY shortcode of media listing only for that “LOGIN USER”

    https://buddydev.com/mediapress/shortcodes/mpp-list-media/

    see picture here
    http://cover.y-popstyle.com/wp-content/uploads/2019/03/medialist.png

    Thanks for your help

    Kerry

  • Participant
    Level: Initiated
    Posts: 17
  • Participant
    Level: Initiated
    Posts: 17
  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #24999

    Hi,
    Please add the following code too.

    
    
    /**
     * Redirect from members/user/mediapress/ to their single gallery.
     */
    function mpp_custom_redirect_to_single_gallery() {
    	if ( ! function_exists( 'mpp_is_user_gallery_component' ) || ! mpp_is_user_gallery_component() ) {
    		return;
    	}
    
    	// we are on some internal page, no need to redirect.
    	if ( bp_current_action() ) {
    		return;
    	}
    
    	// find out the gallery permalink and redirect.
    	$gallery_id = get_user_meta( bp_displayed_user_id(), '_mpp_predefined_gallery_photo_1', true );
    	if ( ! $gallery_id ) {
    		return;
    	}
    	$permalink = mpp_get_gallery_permalink( $gallery_id );
    	if ( $permalink ) {
    		bp_core_redirect();
    	}
    
    }
    
    add_action( 'bp_template_redirect', 'mpp_custom_redirect_to_single_gallery' );
    
    

    It should work in conjunction with our previous code.

    Please give it a try and let me know(I haven’t tried it yet).

    For create gallery, I will be assisting you later.

    regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 17
    KerryMusic on #25001

    Really Thanks for Help

    I just add the code. Seem it still go to Gallery List page!!

    Is that possible to hide/disable the delete button for user?? dont let user delete.

    I thinks the site will be no more need change to be use for Public
    1. Create Gallery when registration (OK)
    2. myGallery go to Media List
    3. User not allow to delete
    4. User cannot Create Gallery

    Thanks for you support
    Kerry

You must be logged in to reply to this topic.

This topic is: not resolved