function jr_process_register_form( $success_redirect = '' ) { // if there's no redirect posted, send them to their job dashboard if (!$success_redirect) $success_redirect = get_permalink(get_option('jr_dashboard_page_id')); if ( get_option('users_can_register') ) : global $posted, $app_abbr; $posted = array(); $errors = new WP_Error(); $user_pass = wp_generate_password(); if (isset($_POST['register']) && $_POST['register']) { // include the WP registration core require_once( ABSPATH . WPINC . '/registration.php'); // process the reCaptcha request if it's been enabled if (get_option($app_abbr.'_captcha_enable') == 'yes') { require_once (TEMPLATEPATH . '/includes/lib/recaptchalib.php'); $resp = null; $error = null; // check and make sure the reCaptcha values match $resp = recaptcha_check_answer( get_option($app_abbr.'_captcha_private_key'), $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); } // Get (and clean) data $fields = array( 'your_username', 'your_email', 'your_password', 'your_password_2', 'role' ); foreach ($fields as $field) { if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = ''; } $user_login = sanitize_user( $posted['your_username'] ); $user_email = apply_filters( 'user_registration_email', $posted['your_email'] ); $user_role = 'job_lister'; // Check terms acceptance if (get_option('jr_terms_page_id')>0) : if (!isset($_POST['terms'])) $errors->add('empty_terms', __('Notice: You must accept our terms and conditions in order to register.', 'appthemes')); endif; // Check Role if (get_option('jr_allow_job_seekers')=='yes') : if (!isset($_POST['role'])) $errors->add('empty_role', __('Notice: Please select a role.', 'appthemes')); if (isset($_POST['role'])) : if ($posted['role']!='job_lister' && $posted['role']!='job_seeker') $errors->add('empty_role', __('Notice: Invalid Role!', 'appthemes')); else $user_role = $posted['role']; endif; else : endif; // Check the username if ( $posted['your_username'] == '' ) $errors->add('empty_username', __('ERROR: Please enter a username.', 'appthemes')); elseif ( !validate_username( $posted['your_username'] ) ) { $errors->add('invalid_username', __('ERROR: This username is invalid. Please enter a valid username.', 'appthemes')); $posted['your_username'] = ''; } elseif ( username_exists( $posted['your_username'] ) ) $errors->add('username_exists', __('ERROR: This username is already registered, please choose another one.', 'appthemes')); // Check the e-mail address if ($posted['your_email'] == '') { $errors->add('empty_email', __('ERROR: Please type your e-mail address.', 'appthemes')); } elseif ( !is_email( $posted['your_email'] ) ) { $errors->add('invalid_email', __('ERROR: The email address isn’t correct.', 'appthemes')); $posted['your_email'] = ''; } elseif ( email_exists( $posted['your_email'] ) ) $errors->add('email_exists', __('ERROR: This email is already registered, please choose another one.', 'appthemes')); if (get_option('jr_allow_registration_password')=='yes') : // Check Passwords match if ($posted['your_password'] == '') $errors->add('empty_password', __('ERROR: Please enter a password.', 'appthemes')); elseif ($posted['your_password_2'] == '') $errors->add('empty_password', __('ERROR: Please enter password twice.', 'appthemes')); elseif ($posted['your_password'] !== $posted['your_password_2']) $errors->add('wrong_password', __('ERROR: Passwords do not match.', 'appthemes')); $user_pass = $posted['your_password']; endif; // display the reCaptcha error msg if it's been enabled if (get_option($app_abbr.'_captcha_enable') == 'yes') { // Check reCaptcha match if (!$resp->is_valid) $errors->add('invalid_captcha', __('ERROR: The reCaptcha anti-spam response was incorrect.', 'appthemes')); //$error = $resp->error; } do_action('register_post', $posted['your_username'], $posted['your_email'], $errors); $errors = apply_filters( 'registration_errors', $errors, $posted['your_username'], $posted['your_email'] ); // if there are no errors, let's create the user account if ( !$errors->get_error_code() ) { $user_id = wp_create_user( $posted['your_username'], $user_pass, $posted['your_email'] ); if ( !$user_id ) { $errors->add('registerfail', sprintf(__('ERROR: Couldn’t register you... please contact the webmaster !', 'appthemes'), get_option('admin_email'))); return array( 'errors' => $errors, 'posted' => $posted); } // Change role wp_update_user( array ('ID' => $user_id, 'role' => $user_role) ) ; // send the user a confirmation and their login details app_new_user_notification($user_id, $user_pass); if (get_option('jr_allow_registration_password')=='yes') : // set the WP login cookie $secure_cookie = is_ssl() ? true : false; wp_set_auth_cookie($user_id, true, $secure_cookie); // redirect //wp_redirect($success_redirect); //wp_redirect( () ); $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : '?action=register&step=2'; wp_safe_redirect( $redirect_to ); exit; else : //create own password option is turned off so show a message that it's been emailed instead $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : '?checkemail=newpass'; wp_safe_redirect( $redirect_to ); exit(); endif; } else { // there were errors so go back and display them without creating new user return array( 'errors' => $errors, 'posted' => $posted); } } endif; }