Advertisement
Guest User

jobroller register process

a guest
Apr 15th, 2012
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.03 KB | None | 0 0
  1. function jr_process_register_form( $success_redirect = '' ) {
  2.  
  3.         // if there's no redirect posted, send them to their job dashboard
  4.     if (!$success_redirect)
  5.             $success_redirect = get_permalink(get_option('jr_dashboard_page_id'));
  6.  
  7.    
  8.     if ( get_option('users_can_register') ) :
  9.        
  10.         global $posted, $app_abbr;
  11.        
  12.         $posted = array();
  13.         $errors = new WP_Error();
  14.         $user_pass = wp_generate_password();
  15.        
  16.         if (isset($_POST['register']) && $_POST['register']) {
  17.  
  18.                         // include the WP registration core
  19.             require_once( ABSPATH . WPINC . '/registration.php');
  20.  
  21.                         // process the reCaptcha request if it's been enabled
  22.             if (get_option($app_abbr.'_captcha_enable') == 'yes') {
  23.                             require_once (TEMPLATEPATH . '/includes/lib/recaptchalib.php');
  24.                             $resp = null;
  25.                             $error = null;
  26.  
  27.                             // check and make sure the reCaptcha values match
  28.                             $resp = recaptcha_check_answer(
  29.                                 get_option($app_abbr.'_captcha_private_key'),
  30.                                 $_SERVER['REMOTE_ADDR'],
  31.                                 $_POST['recaptcha_challenge_field'],
  32.                                 $_POST['recaptcha_response_field']
  33.                             );
  34.             }
  35.        
  36.             // Get (and clean) data
  37.             $fields = array(
  38.                 'your_username',
  39.                 'your_email',
  40.                 'your_password',
  41.                 'your_password_2',
  42.                 'role'
  43.             );
  44.             foreach ($fields as $field) {
  45.                 if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = '';
  46.             }
  47.        
  48.             $user_login = sanitize_user( $posted['your_username'] );
  49.             $user_email = apply_filters( 'user_registration_email', $posted['your_email'] );
  50.             $user_role = 'job_lister';
  51.            
  52.             // Check terms acceptance
  53.             if (get_option('jr_terms_page_id')>0) :
  54.                 if (!isset($_POST['terms'])) $errors->add('empty_terms', __('<strong>Notice</strong>: You must accept our terms and conditions in order to register.', 'appthemes'));
  55.             endif;
  56.            
  57.             // Check Role
  58.             if (get_option('jr_allow_job_seekers')=='yes') :
  59.                 if (!isset($_POST['role'])) $errors->add('empty_role', __('<strong>Notice</strong>: Please select a role.', 'appthemes'));
  60.                
  61.                 if (isset($_POST['role'])) :
  62.                     if ($posted['role']!='job_lister' && $posted['role']!='job_seeker')
  63.                         $errors->add('empty_role', __('<strong>Notice</strong>: Invalid Role!', 'appthemes'));
  64.                     else $user_role = $posted['role'];
  65.                 endif;
  66.             else :
  67.            
  68.             endif;
  69.            
  70.             // Check the username
  71.             if ( $posted['your_username'] == '' )
  72.                 $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'appthemes'));
  73.             elseif ( !validate_username( $posted['your_username'] ) ) {
  74.                 $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.', 'appthemes'));
  75.                 $posted['your_username'] = '';
  76.             } elseif ( username_exists( $posted['your_username'] ) )
  77.                 $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.', 'appthemes'));
  78.        
  79.             // Check the e-mail address
  80.             if ($posted['your_email'] == '') {
  81.                 $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.', 'appthemes'));
  82.             } elseif ( !is_email( $posted['your_email'] ) ) {
  83.                 $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.', 'appthemes'));
  84.                 $posted['your_email'] = '';
  85.             } elseif ( email_exists( $posted['your_email'] ) )
  86.                 $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.', 'appthemes'));
  87.            
  88.             if (get_option('jr_allow_registration_password')=='yes') :
  89.                 // Check Passwords match
  90.                 if ($posted['your_password'] == '')
  91.                     $errors->add('empty_password', __('<strong>ERROR</strong>: Please enter a password.', 'appthemes'));
  92.                 elseif ($posted['your_password_2'] == '')
  93.                     $errors->add('empty_password', __('<strong>ERROR</strong>: Please enter password twice.', 'appthemes'));
  94.                 elseif ($posted['your_password'] !== $posted['your_password_2'])
  95.                     $errors->add('wrong_password', __('<strong>ERROR</strong>: Passwords do not match.', 'appthemes'));
  96.                
  97.                 $user_pass = $posted['your_password'];
  98.             endif;
  99.            
  100.             // display the reCaptcha error msg if it's been enabled
  101.             if (get_option($app_abbr.'_captcha_enable') == 'yes') {
  102.                             // Check reCaptcha  match
  103.                             if (!$resp->is_valid)
  104.                                 $errors->add('invalid_captcha', __('<strong>ERROR</strong>: The reCaptcha anti-spam response was incorrect.', 'appthemes'));
  105.                                 //$error = $resp->error;
  106.             }
  107.            
  108.             do_action('register_post', $posted['your_username'], $posted['your_email'], $errors);
  109.             $errors = apply_filters( 'registration_errors', $errors, $posted['your_username'], $posted['your_email'] );
  110.        
  111.                         // if there are no errors, let's create the user account
  112.             if ( !$errors->get_error_code() ) {
  113.  
  114.                            
  115.                             $user_id = wp_create_user(  $posted['your_username'], $user_pass, $posted['your_email'] );
  116.                             if ( !$user_id ) {
  117.                                     $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'appthemes'), get_option('admin_email')));
  118.                                     return array( 'errors' => $errors, 'posted' => $posted);
  119.                             }
  120.  
  121.                             // Change role
  122.                             wp_update_user( array ('ID' => $user_id, 'role' => $user_role) ) ;
  123.  
  124.                             // send the user a confirmation and their login details
  125.                             app_new_user_notification($user_id, $user_pass);
  126.  
  127.                             if (get_option('jr_allow_registration_password')=='yes') :
  128.                            
  129.                                 // set the WP login cookie
  130.                                 $secure_cookie = is_ssl() ? true : false;
  131.                                 wp_set_auth_cookie($user_id, true, $secure_cookie);
  132.  
  133.                                 // redirect
  134.                                 //wp_redirect($success_redirect);
  135.                                 //wp_redirect( () );
  136.                                 $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : '?action=register&step=2';
  137.                                 wp_safe_redirect( $redirect_to );
  138.                                 exit;
  139.                            
  140.                             else :
  141.                            
  142.                                 //create own password option is turned off so show a message that it's been emailed instead
  143.                                 $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : '?checkemail=newpass';
  144.                                 wp_safe_redirect( $redirect_to );
  145.                                 exit();
  146.                            
  147.                             endif;
  148.  
  149.             } else {
  150.  
  151.                             // there were errors so go back and display them without creating new user
  152.                             return array( 'errors' => $errors, 'posted' => $posted);
  153.  
  154.             }
  155.         }
  156.        
  157.     endif;
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement