Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created December 20, 2011 21:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trepmal/1503478 to your computer and use it in GitHub Desktop.
Save trepmal/1503478 to your computer and use it in GitHub Desktop.
WordPress: Choose password at registration (Multisite)
<?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 );
}
@guoxiangke
Copy link

wp 3.9.2 ,I put those code to theme functions.php & not work....
when debug,I found that the wp-signup.php file no use, because I delete it ,wp reister still work.
and the function show_user_form contain do_action( 'signup_extra_fields', $errors ); not called.

@matteocontrini
Copy link

Thank you! Good input point for complex registrations on WP MS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment