Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hold Specific Member Types for Manual Activation


  • Andrew Tibbetts
    Participant

    @andrewgtibbetts

    I have a handful of member types that I would like to manually confirm by an admin.
    Users choose their member type upon registration so, regular members can register, confirm email and start using the site, but special member types I want to be able to register, confirm email and then get put into some kind of user confirmation status.
    Couple things:
    – maybe this can be done by hooking into bp_core_activate_account in bp_core_screen_activation()?
    – what are the meanings of the ints for user_status in the wp_users table? Seems like WordPress doesn’t use it and Buddypress uses it but only 0 and 2. Maybe use 1 as a custom pending status?

Viewing 2 replies - 1 through 2 (of 2 total)

  • Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Solution:

    There is an action to hook to inside bp_core_activate_signup() that fires right after activating the account ( user clicked the link in the email ), so when the user hits /activate this will fire and reset the user_status to 3 ( 1 is spammer I guess ). Now to figure out the rest…

    Here is the code ( the second function disallows the user from logging in with custom message ):

    add_action( 'bp_core_activated_user', 'custom_bp_core_activated_user' );
    function custom_bp_core_activated_user( $user ) {
    
    	if ( empty( $user ) ) {
    		
    		return false;
    	}
    
    	if ( is_array($user) ) {
    		
    		$user_id = $user['user_id'];
    	}
    	else {
    		
    		$user_id = $user;
    	}
    
    	$member_type = bp_get_member_type($user_id);
    	
    	if ( $member_type == 'member_type_to_manually_activate' ) {
    		
    		global $wpdb;
    		
    		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 3 WHERE ID = %d", $user_id ) );
    	}
    }
    
    add_filter( 'authenticate', 'custom_authenticate', 30 );
    function custom_authenticate( $user ) {
    
    	if ( is_wp_error( $user ) || empty( $user ) ) {
    
    		return $user;
    	}
    
    	if ( 3 == $user->user_status ) {
    
    		$member_type_name = bp_get_member_type($user->ID);
    		$member_type = bp_get_member_type_object($member_type_name);
    		
    		return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: All ' . $member_type->labels['name'] . ' accounts require manual confirmation from an admin. You might be contacted soon to verify your identity. You will recieve an email once your account is approved.', 'buddypress' ) );
    	}
    
    	return $user;
    }

    Gravitation®
    Participant

    @gravitationltd

    Hello! Can you please help me to realize this but with user roles. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar