BuddyDev

Search

[Resolved] BP-Member Type Default Type,with member type generator and hidden profile fields

  • Participant
    Level: Initiated
    Posts: 2
    C on #4474

    Hi,

    First, thank you so much for solving my previous issue. I was struggling and the update really fixed my problem.
    https://buddydev.com/support/forums/topic/bp-member-type-generator-xprofile-member-type-field/#post-4111

    Now, I’m facing another issue, related to the same thing, but a bit different. Now my users are not supposed to choose their member type. I need them all to start with the same member type (‘Member’) and it will only be changed when the admin decides to upgrade them.

    To keep them from changing the member field I used “BuddyPress Non Editable Profile Fields”. The problem is that I don’t know exactly how to set a member type as default.
    I tried to set both the field and the member type values with hooks to the moment when the users signup (with the standard form and also with social login) but it does’t seem to be working.

    I’m still quite a newbie with this so I’m sure my solution is wrong, but not really sure why. So, any help or hints, would be really really appreciated 🙂

    Thank you so much!!

    This is my code:

    function wsl_set_default_member_type($user_id, $provider, $hybridauth_user_profile) {

    bp_set_member_type( $user_id, ‘Member’ );
    xprofile_set_field_data (‘Tipo’, $user_id, ‘Member’ );
    }
    add_action(‘wsl_hook_process_login_after_wp_insert_user’, ‘wsl_set_default_member_type’, 10, 3);

    function set_default_member_type( $user_id ) {
    bp_set_member_type( $user_id, ‘Member’ );
    xprofile_set_field_data (‘Tipo’, $user_id, ‘Member’ );
    }
    add_action( ‘bp_core_signup_user’, ‘set_default_member_type’ );

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4476

    Hi,
    Thank you for posting.

    1. You don’t need the Non editable profile field plugin, just do not install/activate or use the Member type field (It is not required as a field if only admin can change it)

    Here is the code you can put in your bp-custom.php to safely update the default member type when teh user account is activated.

    
    
    function buddydev_set_member_type( $user_id ) {
    	
    	$member_type = 'student';//change with the unique slug of your member type
    	bp_set_member_type( $user_id, $member_type );
    	
    }
    add_action( 'bp_core_activated_user', 'buddydev_set_member_type', 0 );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4609

    Hi C,
    Can you please let me know if it worked or not?
    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    C on #4610

    Yes, It worked!
    I had to add also this, to make it work with social login 🙂

    
    function wsl_set_default_member_type( $user_id, $provider, $hybridauth_user_profile ) {
    
    	bp_set_member_type( $user_id, 'member');
    }
    
    add_action( 'wsl_hook_process_login_after_wp_insert_user ', 'wsl_set_default_member_type ', 10, 3 );
    
    

    Thanks!!!!

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4611

    Thank you for confirming and posting the tip for social login.
    Marking it as resolved 🙂

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 5
    billy on #14188

    hello,
    I’d like to ask if the code mentioned in #4476 still works, cause when i added it to bp-custom.php, new registered user still have empty member type

    
    function buddydev_set_member_type( $user_id ) {
    	
    	$member_type = 'tutor';//change with the unique slug of your member type
    	bp_set_member_type( $user_id, $member_type );
    	
    }
    add_action( 'bp_core_activated_user', 'buddydev_set_member_type', 0 );
    

    what I’ve done up till now: installed bp member types plugin, created member type ‘tutor’ and added following code in bp-custom.php to restrict certain member type from accessing certain pages

    
    // Blocks pages from different users and users who aren't logged in
    function bp_redirect_pages() {
    	$current_user = wp_get_current_user();
    	// Declares a variable containing the current user's member type
    	$member_type = bp_get_member_type( $current_user->ID );
    	$url = $_SERVER['REQUEST_URI'];
    	$explode_url = explode("/", $url);
    	// Redirects members who are 'associate-member' types from access urls containing 'full-members'
    	if ( 'tutor' === $member_type && (in_array("compose", $explode_url)||in_array("view", $explode_url))) { 
    		wp_redirect( home_url() . '/shop/' ); 
    	}
    }
    add_action( 'template_redirect', 'bp_redirect_pages' );
    

    which is worked.
    i added your code below it.

    many thanks!

    • This reply was modified 6 years ago by billy.
  • Participant
    Level: Initiated
    Posts: 5
    billy on #14198

    problem solved on other posts here, thanks for you guys’ support!

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14205

    Hi Billy,
    Glad that you resolved it over the weekend.
    Thank you for being a valuable member here.

    Best Regards
    Brajesh

The topic ‘ [Resolved] BP-Member Type Default Type,with member type generator and hidden profile fields’ is closed to new replies.

This topic is: resolved