Last active
March 23, 2020 14:24
-
-
Save cartpauj/9fa8dff5065a7b720463 to your computer and use it in GitHub Desktop.
Unset the password fields errors from MemberPress and auto-generate the user pass 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 | |
//This file only unsets the errors | |
//You'll still need to override the app/views/checkout/form.php file to remove the password fields HTML | |
//You can find instructions on overriding template files here: https://www.memberpress.com/1.1.7 | |
function unset_password_validation_errors($errors) { | |
if(empty($errors)) { return $errors; } //Should never happen if the password fields are hidden | |
//Unset the password field errors | |
// IF YOU'VE TRANSLATED THE PLUGIN - YOU MAY NEED TO CHANGE THESE ENGLISH TEXTS TO YOUR LANGUAGE | |
foreach($errors as $i => $v) { | |
if($v == 'You must enter a Password.') { | |
unset($errors[$i]); | |
} | |
if($v == 'You must enter a Password Confirmation.') { | |
unset($errors[$i]); | |
} | |
if(stripslashes($v) == "Your Password and Password Confirmation don't match.") { | |
unset($errors[$i]); | |
} | |
} | |
//Artificially set a password here | |
$_POST['mepr_user_password'] = uniqid(); //Deprecated? | |
$_REQUEST['mepr_user_password'] = uniqid(); | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'unset_password_validation_errors'); |
How do you deliver the password to the user after they've successfully signed up? The code works for me otherwise but I'm not sure what the best flow would be for that.
Maybe this will help: https://gist.github.com/cartpauj/3fb64b7fa47ad88b62da
UPDATE: MP Has since created a setting to "Hide password fields" so this code is really no longer necessary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
functions.php should work fine. Also, a plugin like My Custom Functions could work well too.