Created
September 25, 2015 23:47
-
-
Save greathmaster/1a07d80af99af3311f18 to your computer and use it in GitHub Desktop.
Send password through email after checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Send members password through email after checkout. | |
* Use PMPro Email Templates shortcode !!password!! in checkout emails. | |
* Remove password fields using custom checkout template to auto generate password. | |
*/ | |
function my_generate_passwords() | |
{ | |
if(!empty($_REQUEST['username']) && empty($_REQUEST['password'])) | |
{ | |
$_REQUEST['password'] = pmpro_getDiscountCode() . pmpro_getDiscountCode(); //using two random discount codes | |
$_REQUEST['password2'] = $_REQUEST['password']; | |
} | |
} | |
add_action("init", "my_generate_passwords"); | |
function my_email_password() | |
{ | |
global $gateway; | |
$password = $_REQUEST['password']; | |
$username = $_REQUEST['username']; | |
$transient_var = $username."_password"; | |
set_transient( $transient_var, $password, HOUR_IN_SECONDS); | |
} | |
add_action('pmpro_after_checkout', 'my_email_password'); | |
function my_pmpro_paypalexpress_session_vars() | |
{ | |
$username = $_SESSION['pmpro_signup_username']; | |
$password = $_SESSION['pmpro_signup_password']; | |
$transient_var = $username."_password"; | |
set_transient( $transient_var, $password, HOUR_IN_SECONDS); | |
} | |
add_action('pmpro_paypalexpress_session_vars', 'my_pmpro_paypalexpress_session_vars'); | |
function my_pmpro_email_data($data, $email) | |
{ | |
$password = get_transient($data['user_login'].'_password'); | |
if($password != false) | |
$data['password'] = $password; | |
return $data; | |
} | |
add_filter("pmpro_email_data", "my_pmpro_email_data", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment