Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created January 15, 2018 09:59
Show Gist options
  • Save andrewlimaza/f2e8fec34ddb748098bb5e6094314dc4 to your computer and use it in GitHub Desktop.
Save andrewlimaza/f2e8fec34ddb748098bb5e6094314dc4 to your computer and use it in GitHub Desktop.
Send validation email when assigning membership level via code Paid Memberships Pro
<?php
/**
* Send validation email when assigning a membership level to a user using PHP code.
* Extended from example - https://www.paidmembershipspro.com/give-users-a-default-membership-level-at-registration/
* Adjust code accordingly to your needs, add to PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
add_filter("pmpro_login_redirect", "__return_false");
function my_pmpro_default_registration_level( $user_id ) {
// Give all members who register membership level 1
pmpro_changeMembershipLevel( 1, $user_id );
$key = pmproec_getValidationKey( $user_id );
update_user_meta( $user_id, 'pmpro_email_confirmation_key', $key );
// Validation URL for email
$url = home_url("?ui=" . $user_id . "&validate=" . $key);
// Get user data
$user = get_user_by( 'ID', $user_id );
// Let's send an email to the user now to validate their account.
$pmpro_email = new PMProEmail();
$pmpro_email->template = 'my_custom_validate_template';
$pmpro_email->subject = 'Please verify your email address';
$pmpro_email->body = 'Please validate your email here: ' . $url;
$pmpro_email->sendEmail( $user->user_email );
}
add_action('user_register', 'my_pmpro_default_registration_level');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment