Created
June 24, 2014 04:29
-
-
Save cartpauj/3fb64b7fa47ad88b62da to your computer and use it in GitHub Desktop.
Overrides a user's password in MemberPress signup (guests only) and emails them a new one instead
This file contains hidden or 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
<?php | |
function mepr_ignore_password_error($errors) { | |
if(!MeprUtils::is_user_logged_in() && !empty($errors)) { | |
foreach($errors as $i => $e) { | |
if(preg_match("#P?p?assword#", $e)) { //If this is an error about the password let's unset it -- we'll set the password later | |
$_POST['mepr_ignoring_password'] = true; //Artificially setting a POST var to ensure we only reset the proper passwords | |
unset($errors[$i]); | |
} | |
} | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'mepr_ignore_password_error'); | |
function mepr_override_password($product_price, $user, $mepr_product_id, $transaction_id) { | |
if(!isset($_POST['mepr_ignoring_password']) || $_POST['mepr_ignoring_password'] === false) | |
return; | |
$random_password = uniqid(); | |
wp_set_password($random_password, $user->ID); | |
wp_mail($user->user_email, 'Your password for SOME SITE', "Your password for SOME SITE is: {$random_password}<br/>You can <a href=\"http://somesite.com/login/\">login here</a>.", array('Content-Type: text/html')); | |
} | |
add_action('mepr-process-signup', 'mepr_override_password', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment