Membership plugin needs to send activation email for free members

Hi. Thank you for this great plugin. I have one small problem. We have created a free account type for junior golfers but still require them to verify their email address (via the activation email) and fill out buddypress xprofile fields to access certain information. That becomes a fair exchange. HOWEVER when I activated the membership plugin my email did not send anymore plus I had the following in the child function.php

add_filter( 'bp_core_signup_send_validation_email_message', 'custom_buddypress_activation_message', 10, 3 );

function custom_buddypress_activation_message( $message, $user_id, $activate_url ) {
$user = get_userdata( $user_id );
return "Dear $user->user_login,
Thanks for joining the World Junior Golf Ranking at juniorgolfranking.org! In order to activate and complete your profile, simply click on the link below and follow the on screen instructions.
$activate_url

Once you complete your profile you will have access to excellent benefits which include:
1. Online Posting of your golf resume for all college golf coaches to see.
2. Unlimited access to the World Junior Golf Ranking results and Player Results.
3. FREE Forums where you can interact with other Junior Golfers and College Coaches.
Best Wishes,
The World Junior Golf Team";
}

can you guide me how to get this to work with the membership plugin for folks that register with free types using your membership plugin.

  • Ash

    Hello @G Lewis

    I hope you are well today and thanks for asking the question.

    Are you using buddypress registration from or membership registration form? If you use buddypress registration form, then the activation email should be sent.

    Please remove register page from Membership > Options > Membership pages and add register page in Settings > Buddypress > Pages.

    Please let me know if it works this time.

    Cheers
    Ash

  • G Lewis

    Hi Ashok,

    sorry, I assumed you knew that we had both free and paid memberships (why else would I need your plugin) and the activation email is needed for the free ones so we don't get bogus people signing up for free. get it?

    If I do this change that you suggest then the paid memberships won't work with the standard buddypress registration page... correct? If So then this won't work for me as I need the membership plugin to

    a) take money on the paid members and
    b) have a verification method that is automatic with their email if free
    C) protect the pages from certain user types

    a & c work out of the box with your membership however it looks like you guys have deactivated the automation email from the standard buddypress plugin. I understand why for paid members but really need that in there for free accounts.

    I see a ton of people asking about this in the forum but not seeing a solution. thus I am posting this question.

    btw - I can't reverse the process and they can't register and then signup for a membership because upon activation I need them going to their buddypress profile page and being forced to fill out the required fields via another plugin before accessing the site. understand?

    I just need the activation email for free reinserted and working with my original message code I posted above

  • G Lewis

    ok great ! thank you. I am stuck for sure. I went in and retraced all my step (reactivating plugins one at a time) and was shocked that it was this plugin as you guys do a great job with everything.

    After researching I see many threads like 'Double Opt In Membership Plugin' etc. We all are needing the same activation email for free accounts.

    I hope that my code above (or something similar) can be used with this work around so I can tweak the message but never-the-less the activation email is a must... We can't afford to get the buddypress trashed by spammers.

    this was what I referenced before...

    'custom_buddypress_activation_message', 10, 3 );
    function custom_buddypress_activation_message( $message, $user_id, $activate_url ) {
    $user = get_userdata( $user_id );
    return "Dear $user->user_login,

    please let me know......

    Best,
    G

  • Hoang Ngo

    Hi @G Lewis,

    I hope you are well today and I'm sorry about the issue.

    It seem in this version of membership, we don't have any way to fix this issue without modify the core code :slight_frown:.

    Please take a look at the file /membership/membershipincludes/classes/membershippublic.php line 1277(It's maybe different from my side and your side). You will the code look like this

    case 'validatepage1bp':
    					if ( $_SERVER['REQUEST_METHOD'] != 'POST' ) {
    						return;
    					}
    
    					$required = array(
    						'signup_username'         => __( 'Username', 'membership' ),
    						'signup_email'            => __( 'Email address', 'membership' ),
    						'signup_password'         => __( 'Password', 'membership' ),
    						'signup_password_confirm' => __( 'Password confirmation', 'membership' ),
    					);
    
    					$this->_register_errors = new WP_Error();
    
    					foreach ( $required as $key => $message ) {
    						if ( empty( $_POST[$key] ) ) {
    							$this->_register_errors->add( $key, __( 'Please ensure that the ', 'membership' ) . "<strong>" . $message . "</strong>" . __( ' information is completed.', 'membership' ) );
    						}
    					}
    
    					if ( $_POST['signup_password'] != $_POST['signup_password_confirm'] ) {
    						$this->_register_errors->add( 'passmatch', __( 'Please ensure the passwords match.', 'membership' ) );
    					}
    
    					if ( !validate_username( $_POST['signup_username'] ) ) {
    						$this->_register_errors->add( 'usernamenotvalid', __( 'The username is not valid, sorry.', 'membership' ) );
    					}
    
    					if ( username_exists( sanitize_user( $_POST['signup_username'] ) ) ) {
    						$this->_register_errors->add( 'usernameexists', __( 'That username is already taken, sorry.', 'membership' ) );
    					}
    
    					if ( !is_email( $_POST['signup_email'] ) ) {
    						$this->_register_errors->add( 'emailnotvalid', __( 'The email address is not valid, sorry.', 'membership' ) );
    					}
    
    					if ( email_exists( $_POST['signup_email'] ) ) {
    						$this->_register_errors->add( 'emailexists', __( 'That email address is already taken, sorry.', 'membership' ) );
    					}
    
    					// Initial fix provided by user: cmurtagh - modified to add extra checks and rejigged a bit
    					// Run the buddypress validation
    					do_action( 'bp_signup_validate' );
    
    					// Add any errors to the action for the field in the template for display.
    					if ( !empty( $bp->signup->errors ) ) {
    						foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) {
    							$this->_register_errors->add( $fieldname, $error_message );
    						}
    					}
    
    					$meta_array = array();
    
    					// xprofile required fields
    					/* Now we've checked account details, we can check profile information */
    					//if ( function_exists( 'xprofile_check_is_required_field' ) ) {
    					if ( function_exists( 'bp_is_active' ) && bp_is_active( 'xprofile' ) ) {
    
    						/* Make sure hidden field is passed and populated */
    						if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
    
    							/* Let's compact any profile field info into an array */
    							$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
    
    							/* Loop through the posted fields formatting any datebox values then validate the field */
    							foreach ( (array) $profile_field_ids as $field_id ) {
    								if ( !isset( $_POST['field_' . $field_id] ) ) {
    									if ( isset( $_POST['field_' . $field_id . '_day'] ) )
    										$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
    								}
    
    								/* Create errors for required fields without values */
    								if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) ) {
    									$field = new BP_Xprofile_Field( $field_id );
    									$this->_register_errors->add( $field->name, __( 'Please ensure that the ', 'membership' ) . "<strong>" . $field->name . "</strong>" . __( ' information is completed.', 'membership' ) );
    								}
    
    								$meta_array[$field_id] = $_POST['field_' . $field_id];
    							}
    						}
    					}
    
    					$this->_register_errors = apply_filters( 'membership_subscription_form_before_registration_process', $this->_register_errors );
    
    					// Hack for now - eeek
    					$anyerrors = $this->_register_errors->get_error_code();
    					if ( empty( $anyerrors ) ) {
    						// No errors so far - error reporting check for final add user *note $error should always be an error object becuase we created it as such.
    						$user_id = wp_create_user( sanitize_user( $_POST['signup_username'] ), $_POST['signup_password'], $_POST['signup_email'] );
    
    						if ( is_wp_error( $user_id ) ) {
    							$this->_register_errors->add( 'userid', $user_id->get_error_message() );
    						} else {
    							$member = Membership_Plugin::factory()->get_member( $user_id );
    							if ( !headers_sent() ) {
    								$user = @wp_signon( array(
    									'user_login'    => $_POST['signup_username'],
    									'user_password' => $_POST['signup_password'],
    									'remember'      => true
    								) );
    
    								if ( is_wp_error( $user ) && method_exists( $user, 'get_error_message' ) ) {
    									$this->_register_errors->add( 'userlogin', $user->get_error_message() );
    								} else {
    									// Set the current user up
    									wp_set_current_user( $user_id );
    								}
    							} else {
    								// Set the current user up
    								wp_set_current_user( $user_id );
    							}
    
    							if ( has_action( 'membership_susbcription_form_registration_notification' ) ) {
    								do_action( 'membership_susbcription_form_registration_notification', $user_id, $_POST['signup_password'] );
    							} else {
    								wp_new_user_notification( $user_id, $_POST['signup_password'] );
    							}
    
    							if ( function_exists( 'xprofile_set_field_data' ) ) {
    								// Add the bp filter for usermeta signup
    								$meta_array = apply_filters( 'bp_signup_usermeta', $meta_array );
    								foreach ( (array)$meta_array as $field_id => $field_content ) {
    									xprofile_set_field_data( $field_id, $user_id, $field_content );
    									$visibility_level = !empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
    									xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    								}
    
    								// Make sure the User Meta is updated with the xprofile name
    							 	$data = explode( ' ', xprofile_get_field_data( 'Name', $user_id, 'array' ) );
    								$firstname = array_shift( $data );
    								$lastname = implode( ' ', $data );
    								update_user_meta( $user_id, 'first_name', $firstname );
    								update_user_meta( $user_id, 'last_name', $lastname );
    							}
    						}
    
    						do_action( 'membership_subscription_form_registration_process', $this->_register_errors, $user_id );
    
    						// Hack for now - eeek
    						$anyerrors = $this->_register_errors->get_error_code();
    						if ( empty( $anyerrors ) ) {
    							// everything seems fine (so far), so we have our queued user so let's
    							// run the bp complete signup action
    							do_action( 'bp_complete_signup' );
    
    							// redirect to payments page
    							wp_redirect( add_query_arg( array(
    								'action'       => 'subscriptionsignup',
    								'subscription' => $subscription,
    							) ) );
    							exit;
    						}
    					} else {
    						do_action( 'membership_subscription_form_registration_process', $this->_register_errors, 0 );
    					}
    					break;

    This is the function handler the register, so we will need to modify this, to make this send verification email to client. I will check with the developer, for the feature request in future release about this.

    In this mean time, we can do like this, the action "membership_subscription_form_registration_process" will run after the create new user. Here is an example of usage

    add_action('membership_subscription_form_registration_process','add_verify_to_user',10,2);
    function add_verify_to_user($error,$user_id){
    if($user_id > 0){
    //logic here
    }
    }

    So from here, we will get the new register user by user_id, and set the status is 0 or any thing fit with your logic. Also we will set an activation_key too. Save the new user data.

    When user do the login, we can use the hook "wp_login", to check does this user have verify or not. If yes, we will redirect him to another page, which tell him to verify :slight_smile:.

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.