Replies
Viewing 5 posts - 1 through 5 (of 5 total)
Hey Ravi,
thank you! The code works just fine! You’re great!
I guess the problem really was that the meta key “_mpp_predefined_gallery_photo_1” already existed for the users I tested.
I’m sorry that I have to ask, but where can I check the existing meta keys for certain users and is there a way to delete the metakey if it already exists?
Thank you, best
Jacob
Hello Ravi,
thanks for your quick response, I tested the changes, but unfortunately no gallery gets created.
My bp-custom file now looks like this:
<?php // hacks and mods will go here // Stop gallery creation, only superadmin can function mpp_custom_check_gallery_create_permission( $can_do, $component, $user_id ) { if ( is_super_admin() ) { $can_do = true; //ok super admin can create it } else { $can_do = false;//no one else can } return $can_do; } add_filter( 'mpp_user_can_create_gallery', 'mpp_custom_check_gallery_create_permission', 10, 3 ); //stop editing title add_action( 'mpp_user_can_edit_gallery', function ( $can, $gallery, $user_id ) { // Do not check if not allowed to edit gallery details. if ( ! $can || $gallery->user_id != $user_id ) { return $can; } // Do not allow to change the title. if ( ! empty( $_POST['mpp-gallery-title'] ) && $gallery->title != $_POST['mpp-gallery-title'] ) { $can = false; } return $can; } ); // Restrict gallery deletion function mpp_custom_check_gallery_delete_permission( $can, $user_id ){ // only superadmin can if ( is_super_admin() ) { $can = true; } else { $can = false; } return $can;//do not allow it at all } add_filter( 'mpp_user_can_delete_gallery', 'mpp_custom_check_gallery_delete_permission', 10, 2 ); 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 ) ) { //No, then we need to create it. //repeat it as you want $gallery_id = mpp_create_gallery( array( 'creator_id' => $user_id, 'title' => bp_core_get_user_displayname( $user_id ), '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( 'bp_template_redirect', 'mpp_custom_auto_create_gallery'); ?>
Thank you, best
Jacob
- This reply was modified 2 years, 9 months ago by Jacob.
Viewing 5 posts - 1 through 5 (of 5 total)