-
-
Save viruthagiri/1761111 to your computer and use it in GitHub Desktop.
WordPress: Choose password at registration (Multisite)
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
<?php | |
//Plugin Name: Choose password at registration (Multisite) | |
//Description: Doesn't change the confirmation screen or email | |
add_action('signup_extra_fields', 'ask_for_password'); | |
function ask_for_password( $errors ) { | |
if ( $errmsg = $errors->get_error_message('bad_password') ) { | |
echo '<p class="error">'.$errmsg.'</p>'; | |
} | |
?> <p>You can set your password here. If left blank, a random one will be generated for you.</p> | |
<label>Password:</label><input type='password' name='password1' /> | |
<label>Password again:</label><input type='password' name='password2' /> | |
<?php | |
} | |
add_filter( 'wpmu_validate_user_signup', 'verify_password' ); | |
function verify_password( $result ) { | |
$password1 = $_POST['password1']; | |
$password2 = $_POST['password2']; | |
//don't require a password | |
//if empty, let WP use generated password | |
// if ( empty( $password1 ) ) { | |
// $result['errors']->add('bad_password', 'Please provide a password'); | |
// } | |
if ( $password1 != $password2 ) { | |
$result['errors']->add('bad_password', 'Passwords do not match'); | |
} | |
if ( strlen( $password1 ) > 0 && strlen( $password1 ) < 8 ) { | |
$result['errors']->add('bad_password', 'Password is too short'); | |
} | |
return $result; | |
} | |
add_filter( 'add_signup_meta', 'save_password_in_signup_meta' ); | |
function save_password_in_signup_meta( $meta ) { | |
$password1 = $_POST['password1']; | |
$meta['password'] = $password1; | |
return $meta; | |
} | |
add_action('wpmu_activate_user', 'apply_password_during_activation', 10, 3 ); | |
function apply_password_during_activation( $user_id, $password, $meta ) { | |
//if password was provided, use that | |
if ( strlen( $meta['password'] ) > 0) | |
wp_set_password( $meta['password'], $user_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment