Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. // logs a member in after submitting a form
  2. if ( ! function_exists( 'jobhunt_login_member' ) ) {
  3. function jobhunt_login_member() {
  4. if( isset( $_POST['jobhunt_login_check'] ) && wp_verify_nonce( $_POST['jobhunt_login_nonce'], 'jobhunt-login-nonce') ) {
  5.  
  6. // this returns the user ID and other info from the user name
  7. if ( is_email( $_POST['jobhunt_user_login'] ) ) {
  8. $user = get_user_by( 'email', $_POST['jobhunt_user_login'] );
  9. } else {
  10. $user = get_user_by( 'login', $_POST['jobhunt_user_login'] );
  11. }
  12.  
  13. if( ! $user ) {
  14. // if the user name doesn't exist
  15. jobhunt_form_errors()->add('empty_username', esc_html__('Invalid username or email address','jobhunt'));
  16. }
  17.  
  18. if( ! isset($_POST['jobhunt_user_pass']) || $_POST['jobhunt_user_pass'] == '' ) {
  19. // if no password was entered
  20. jobhunt_form_errors()->add('empty_password', esc_html__('Please enter a password','jobhunt'));
  21. }
  22.  
  23. if( isset( $_POST['jobhunt_user_pass'] ) && ! empty( $_POST['jobhunt_user_pass'] ) ){
  24. // check the user's login with their password
  25. if( ! wp_check_password( $_POST['jobhunt_user_pass'], $user->user_pass, $user->ID ) ) {
  26. // if the password is incorrect for the specified user
  27. jobhunt_form_errors()->add('empty_password', esc_html__('Incorrect password','jobhunt'));
  28. }
  29. }
  30.  
  31. // retrieve all error messages
  32. $errors = jobhunt_form_errors()->get_error_messages();
  33.  
  34. // only log the user in if there are no errors
  35. if( empty( $errors ) ) {
  36.  
  37. $creds = array();
  38. $creds['user_login'] = $user->user_login;
  39. $creds['user_password'] = $_POST['jobhunt_user_pass'];
  40. $creds['remember'] = true;
  41.  
  42. $user = wp_signon( $creds, false );
  43. // send the newly created user to the home page after logging them in
  44. if ( is_wp_error($user) ){
  45. echo wp_kses_post( $user->get_error_message() );
  46. } else {
  47. $oUser = get_user_by( 'login', $creds['user_login'] );
  48. $aUser = get_object_vars( $oUser );
  49. $sRole = $aUser['roles'][0];
  50.  
  51. if( jobhunt_is_woocommerce_activated() && get_option( 'woocommerce_myaccount_page_id' ) && apply_filters( 'jobhunt_employer_myaccount_redirect', false ) ) {
  52. $job_url = get_permalink( get_option('woocommerce_myaccount_page_id') );
  53. } elseif( get_option( 'job_manager_job_dashboard_page_id' ) ) {
  54. $job_url = get_permalink( get_option( 'job_manager_job_dashboard_page_id' ) );
  55. } else {
  56. $job_url = home_url( '/' );
  57. }
  58.  
  59. if( jobhunt_is_woocommerce_activated() && get_option( 'woocommerce_myaccount_page_id' ) && apply_filters( 'jobhunt_candidate_myaccount_redirect', false ) ) {
  60. $resume_url = get_permalink( get_option('woocommerce_myaccount_page_id') );
  61. } elseif( get_option( 'resume_manager_candidate_dashboard_page_id' ) ) {
  62. $resume_url = get_permalink( get_option( 'resume_manager_candidate_dashboard_page_id' ) );
  63. } else {
  64. $resume_url= home_url( '/' );
  65. }
  66.  
  67. if( jobhunt_is_woocommerce_activated() && get_option( 'woocommerce_myaccount_page_id' ) && apply_filters( 'jobhunt_default_myaccount_redirect', true ) ) {
  68. $default_url = get_permalink( get_option('woocommerce_myaccount_page_id') );
  69. } else {
  70. $default_url= home_url( '/' );
  71. }
  72.  
  73. switch( $sRole ) {
  74. case 'candidate':
  75. $redirect_url = $resume_url;
  76. break;
  77. case 'employer':
  78. $redirect_url = $job_url;
  79. break;
  80. default:
  81. $redirect_url = $default_url;
  82. break;
  83. }
  84.  
  85. wp_safe_redirect( $redirect_url );
  86. }
  87. exit;
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement