Advertisement
malum

SimpleModal Login set password at registration

Jan 10th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.02 KB | None | 0 0
  1. <?php
  2. /* The code below is a combination of code snippets provided by:
  3. // Eric Martin, the creator of the SimpleModal Login plugin http://wordpress.org/extend/plugins/simplemodal-login/
  4. // and Slobodan Manic https://gist.github.com/slobodan
  5. // Tested, verified to work for me - Your mileage may vary.
  6. */
  7. add_filter('simplemodal_registration_form', 'mytheme_registration_form');
  8. function mytheme_registration_form($form) {
  9.     $options = get_option('simplemodal_login_options');
  10.  
  11.     $output = sprintf('
  12. <form name="registerform" id="registerform" action="%s" method="post">
  13.     <div class="title">%s</div>
  14.     <div class="simplemodal-login-fields">
  15.     <p>
  16.         <label>%s<br />
  17.         <input type="text" name="user_login" class="user_login input" value="" size="20" tabindex="10" /></label>
  18.     </p>
  19.     <p>
  20.         <label for="password">%s<br/>
  21.         <input id="password" class="user_pass input" type="password" tabindex="15" size="25" value="" name="password" />
  22.         </label>
  23.     </p>
  24.     <p>
  25.         <label for="repeat_password">%s<br/>
  26.         <input id="repeat_password" class="user_pass input" type="password" tabindex="30" size="25" value="" name="repeat_password" />
  27.         </label>
  28.     </p>
  29.     <p>
  30.         <label>%s<br />
  31.         <input type="text" name="user_email" class="user_email input" value="" size="25" tabindex="35" /></label>
  32.     </p>',
  33.         site_url('wp-login.php?action=register', 'login_post'),
  34.         __('Register', 'simplemodal-login'),
  35.         __('Username', 'simplemodal-login'),
  36.         __('Password', 'simplemodal-login'),
  37.         __('Repeat Password', 'simplemodal-login'),
  38.         __('E-mail', 'simplemodal-login')
  39.     );
  40.  
  41.     ob_start();
  42.     do_action('register_form');
  43.     $output .= ob_get_clean();
  44.  
  45.     $output .= sprintf('
  46.     <p class="reg_passmail">%s</p>
  47.     <p class="submit">
  48.         <input type="submit" name="wp-submit" value="%s" tabindex="100" />
  49.         <input type="button" class="simplemodal-close" value="%s" tabindex="101" />
  50.     </p>
  51.     <p class="nav">
  52.         <a class="simplemodal-login" href="%s">%s</a>',
  53.         __('A password will be e-mailed to you.', 'simplemodal-login'),
  54.         __('Register', 'simplemodal-login'),
  55.         __('Cancel', 'simplemodal-login'),
  56.         site_url('wp-login.php', 'login'),
  57.         __('Log in', 'simplemodal-login')
  58.     );
  59.  
  60.     if ($options['reset']) {
  61.         $output .= sprintf(' | <a class="simplemodal-forgotpw" href="%s" title="%s">%s</a>',
  62.             site_url('wp-login.php?action=lostpassword', 'login'),
  63.             __('Password Lost and Found', 'simplemodal-login'),
  64.             __('Lost your password?', 'simplemodal-login')
  65.         );
  66.     }
  67.  
  68.     $output .= '
  69.     </p>
  70.     </div>
  71.     <div class="simplemodal-login-activity" style="display:none;"></div>
  72. </form>';
  73.  
  74.     return $output;
  75. }
  76.  
  77. // Add password fields for submit
  78. add_action( 'user_register', 'ts_register_extra_fields', 100 );
  79. function ts_register_extra_fields( $user_id ){
  80.     $userdata = array();
  81.  
  82.     $userdata['ID'] = $user_id;
  83.     if ( $_POST['password'] !== '' ) {
  84.         $userdata['user_pass'] = $_POST['password'];
  85.     }
  86.     $new_user_id = wp_update_user( $userdata );
  87. }
  88.  
  89. // Check password match and length requirement
  90. add_action( 'register_post', 'ts_check_extra_register_fields', 10, 3 );
  91. function ts_check_extra_register_fields($login, $email, $errors) {
  92.         if ( $_POST['password'] !== $_POST['repeat_password'] ) {
  93.                 $errors->add( 'passwords_not_matched', "<strong>ERROR</strong>: Passwords must match" );
  94.         }
  95.         if ( strlen( $_POST['password'] ) < 6 ) {
  96.                 $errors->add( 'password_too_short', "<strong>ERROR</strong>: Passwords must be at least eight characters long" );
  97.         }
  98. }
  99.  
  100. // Change password e-mail text
  101. add_filter( 'gettext', 'ts_edit_password_email_text' );
  102. function ts_edit_password_email_text ( $text ) {
  103.     if ( $text == 'A password will be e-mailed to you.' ) {
  104.         $text = 'Password must be at least six characters long.';
  105.     }
  106.     return $text;
  107. }
  108.  
  109. // Change sucess email text
  110. add_filter( 'gettext', 'ts_edit_login_email_text' );
  111. function ts_edit_login_email_text ( $text ) {
  112.         if ( $text == 'Registration complete. Please check your e-mail.' ) {                $text = 'Registration complete, please log in.';
  113.         }
  114.         return $text;
  115. }
  116.  
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement