2017-05-08 14 views
0

私はワードプレスジョブポータルで働いています。私が直面している問題はそれです。登録フォームとログインフォームの機能は次のとおりです。ユーザーが登録すると、登録された電子メールIDに自分のアカウントのパスワードを含む電子メールが生成されます。登録ユーザーはこれらの資格情報を使用してログインする必要がありますが、すべてのユーザーがサイトに登録した後、ユーザーが最初に登録した後にサイトを特定のページにリダイレクトするようにしたい。Wordpress Workscoutテーマの登録後にホームページにリダイレクト

登録機能

 function workscout_registration_form() { 

      // only show the registration form to non-logged-in members 
      if(!is_user_logged_in()) { 

       // check to make sure user registration is enabled 
       $registration_enabled = get_option('users_can_register'); 

       // only show the registration form if allowed 
       if($registration_enabled) { ?> 
        <form method="post" class="register workscout_form"> 

         <?php do_action('woocommerce_register_form_start'); ?> 

         <?php if ('no' === get_option('woocommerce_registration_generate_username')) : ?> 

          <p class="form-row form-row-wide"> 
           <label for="reg_username"><?php _e('Username', 'workscout'); ?> <span class="required">*</span> 
           <i class="ln ln-icon-Male"></i> 
           <input type="text" class="input-text" name="username" id="reg_username" value="<?php if (! empty($_POST['username'])) echo esc_attr($_POST['username']); ?>" /> 
           </label> 
          </p> 
         <?php endif; ?> 

         <p class="form-row form-row-wide"> 
          <label for="reg_email"><?php _e('Email address', 'workscout'); ?> <span class="required">*</span> 
          <i class="ln ln-icon-Mail"></i><input type="email" class="input-text" name="email" id="reg_email" value="<?php if (! empty($_POST['email'])) echo esc_attr($_POST['email']); ?>" /> 
          </label> 
         </p> 

         <?php if ('no' === get_option('woocommerce_registration_generate_password')) : ?> 

          <p class="form-row form-row-wide"> 
           <label for="reg_password"><?php _e('Password', 'workscout'); ?> <span class="required">*</span> 
           <i class="ln ln-icon-Lock-2"></i><input type="password" class="input-text" name="password" id="reg_password" /> 
           </label> 
          </p> 

         <?php endif; ?> 

         <!-- Spam Trap --> 
         <div style="<?php echo ((is_rtl()) ? 'right' : 'left'); ?>: -999em; position: absolute;"><label for="trap"><?php _e('Anti-spam', 'workscout'); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> 

         <?php do_action('woocommerce_register_form'); ?> 
         <?php do_action('register_form'); ?> 

         <p class="form-row"> 
          <?php wp_nonce_field('woocommerce-register'); ?> 
          <input type="submit" class="button" name="register" value="<?php esc_attr_e('Register', 'workscout'); ?>" /> 
         </p> 

         <?php do_action('woocommerce_register_form_end'); ?> 

        </form> 
       <?php } else { 
        _e('User registration is not enabled','workscout'); 
       } 

      } 
     } 
     add_shortcode('workscout_register_form', 'workscout_registration_form'); 

私はPHPの多くの知識を持っていない、私はここに追加した機能との間に少し混乱しています。

 function wc_custom_user_redirect($redirect, $user) { 
      // Get the first of all the roles assigned to the user 
      $role = $user->roles[0]; 
      $dashboard = admin_url(); 
      $myaccount = get_permalink(wc_get_page_id('myaccount')); 

      if($role == 'employer') { 

       if(get_option('job_manager_job_dashboard_page_id')) { 
        $redirect_to = get_permalink(get_option('job_manager_job_dashboard_page_id')); 
       } else { 
        $redirect_to= home_url(); 
       }; 
      } elseif ($role == 'candidate') { 
       if(get_option('resume_manager_candidate_dashboard_page_id')) { 
        $redirect_to = get_permalink(get_option('resume_manager_candidate_dashboard_page_id')); 
       } else { 
        $redirect_to= home_url(); 
       }; 
      } elseif ($role == 'customer' || $role == 'subscriber') { 
       //Redirect customers and subscribers to the "My Account" page 
       $redirect = $myaccount; 
      } else { 
       //Redirect any other role to the previous visited page or, if not available, to the home 
       $redirect = wp_get_referer() ? wp_get_referer() : home_url(); 
      } 
      return $redirect; 
     } 
     add_filter('woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2); 

私は、この機能にいくつかのリダイレクトコードを追加する必要がありますか、私はリダイレクトコードをコメントして追加しようとしたが、それは

if (! function_exists('workscout_add_new_member')) : 
     function workscout_add_new_member() { 

      $login_system = Kirki::get_option('workscout', 'pp_login_form_system'); 

      if($login_system == 'workscout') { 
       if (isset($_POST["workscout_register_check"]) && wp_verify_nonce($_POST['workscout_register_nonce'], 'workscout-register-nonce')) { 

        if (!isset($_POST['confirm_email']) || $_POST['confirm_email'] !== '') { 
         home_url('/'); 
         exit; 
        } 
        $user_login  = $_POST["workscout_user_login"]; 
        $user_email  = $_POST["workscout_user_email"]; 
        $user_role  = $_POST["workscout_user_role"]; 


        if(username_exists($user_login)) { 
         // Username already registered 
         workscout_form_errors()->add('username_unavailable', __('Username already taken','workscout')); 
        } 
        if(!validate_username($user_login)) { 
         // invalid username 
         workscout_form_errors()->add('username_invalid', __('Invalid username','workscout')); 
        } 
        if($user_login == '') { 
         // empty username 
         workscout_form_errors()->add('username_empty', __('Please enter a username','workscout')); 
        } 
        if(!is_email($user_email)) { 
         //invalid email 
         workscout_form_errors()->add('email_invalid', __('Invalid email','workscout')); 
        } 
        if(email_exists($user_email)) { 
         //Email address already registered 
         workscout_form_errors()->add('email_used', __('Email already registered','workscout')); 
        } 

        $password = wp_generate_password(); 
        $password_generated = true; 

        if(empty($user_role)) { 
         $user_role = 'candidate'; 
        } 

        $errors = workscout_form_errors()->get_error_messages(); 

        // only create the user in if there are no errors 
        if(empty($errors)) { 

         $new_user_id = wp_insert_user(array(
           'user_login'  => $user_login, 
           'user_pass'   => $password, 
           'user_email'  => $user_email, 
           'user_registered' => date('Y-m-d H:i:s'), 
           'role'    => $user_role, 
          ) 
         ); 
         if($new_user_id) { 
          // send an email to the admin alerting them of the registration 
          // 
          if (function_exists('sb_we_init')) { 
           wp_new_user_notification($new_user_id, null, 'both'); 
          } else { 
           workscout_wp_new_user_notification($new_user_id,$password); 
          } 

          // log the new user in 
          // $creds = array(); 
          // $creds['user_login'] = $user_login; 
          // $creds['user_password'] = $password; 
          // $creds['remember'] = true; 

          // $user = wp_signon($creds, false); 
          // send the newly created user to the home page after logging them in 
          if (is_wp_error($user)){ 
           echo $user->get_error_message(); 
          } else { 
           wp_safe_redirect( add_query_arg('success', 1, home_url('/')) ); 
          } 

          exit; 
         } 

        } 

       } 
      } 
     } 
     endif; 
     add_action('init', 'workscout_add_new_member'); 

を動作しませんでした私は、この追加のコードを見つけました。ホームURLはここに追加する必要があると思いますか?

function workscout_ajax_register(){ 

check_ajax_referer('ajax-register-nonce', 'security'); 

// Nonce is checked, get the POST data and sign user on 
$info = array(); 
$info['user_login'] = sanitize_user($_POST['username']); 
$info['user_email'] = sanitize_email($_POST['email']); 
$info['user_role'] = sanitize_email($_POST['role']); 
$valid = true; 
if(username_exists($info['user_login'])) { 
    // Username already registered 
    echo json_encode(array('loggedin'=>false, 'message'=>__('Username already taken','workscout'), 'type'=>"error notification ")); 
    $valid = false; 
    die(); 
} 
if(!validate_username($info['user_login'])) { 
    // invalid username 
    echo json_encode(array('loggedin'=>false, 'message'=>__('Invalid username','workscout'), 'type'=>"error notification ")); 
    $valid = false; 
    die(); 
} 
if($info['user_login'] == '') { 
    // empty username 
    echo json_encode(array('loggedin'=>false, 'message'=>__('Please enter a username','workscout'), 'type'=>"error notification ")); 
    $valid = false; 
    die(); 
} 
if(!is_email($info['user_email'])) { 
    //invalid email 
    echo json_encode(array('loggedin'=>false, 'message'=>__('Invalid email','workscout'), 'type'=>"error notification ")); 
    $valid = false; 
    die(); 
} 
if(email_exists($info['user_email'])) { 
    //Email address already registered 
    echo json_encode(array('loggedin'=>false, 'message'=>__('Email already registered','workscout'), 'type'=>"error notification ")); 
    $valid = false; 
    die(); 
} 

$password = wp_generate_password(); 
$password_generated = true; 
$info['user_pass'] = $password; 
// Register the user 
if($valid) { 
    $user_register = wp_insert_user($info); 
    if (is_wp_error($user_register)){ 
     $error = $user_register->get_error_codes() ; 

     if(in_array('empty_user_login', $error)) 
      echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_message('empty_user_login')), 'type'=>"error notification ")); 
     elseif(in_array('existing_user_login',$error)) 
      echo json_encode(array('loggedin'=>false, 'message'=>__('This username is already registered.','workscout'), 'type'=>"error notification ")); 
     elseif(in_array('existing_user_email',$error)) 
      echo json_encode(array('loggedin'=>false, 'message'=> __('This email address is already registered.','workscout'), 'type'=>"error notification ")); 

    } else { 
     if (function_exists('sb_we_init')) { 
      wp_new_user_notification($user_register, null, 'both'); 
     } else { 
      workscout_wp_new_user_notification($user_register,$password); 
     } 
     $creds = array(); 
     $creds['user_login'] = $info['user_login']; 
     $creds['user_password'] = $password; 
     $creds['remember'] = true; 

     $user_signon = wp_signon($creds, false); 
     if (is_wp_error($user_signon)){ 
      echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong username or password.','workscout'), 'type'=>"error notification ")); 
     } else { 
      wp_set_current_user($user_signon->ID); 
      $oUser = get_user_by('login', $creds['user_login']); 
      $aUser = get_object_vars($oUser); 
      $sRole = $aUser['roles'][0]; 
      echo json_encode(array('loggedin'=>true, 'message'=>__('Registration successful, redirecting...','workscout'), 'type'=>'success notification ', 'role'=> $sRole)); 
     } 
    } 
} 

die(); 
} 
endif; 

?> 

答えて

0

それが動作するかもしれないn個のチェック以下のようなコードを追加してください。このコード

add_filter('registration_redirect', 'my_redirect_home'); 
function my_redirect_home($registration_redirect) { 
    return home_url(); 
} 
+0

どこにコードを追加すればいいですか? – Dannyboi

+0

理想的には、それはfunctions.phpにあるべきです –

+0

私はfunction.phpでコードを追加しましたが、機能しません。 – Dannyboi

0

を試してみてください。

コメントを外して両方の位置で試してください。

<form> 
<p class="form-row"> 
<?php wp_nonce_field('woocommerce-register'); ?> 
<input type="submit" class="button" name="register" value="<?php esc_attr_e('Register', 'workscout'); ?>" /> 
//<?php wp_redirect(home_url());?> 
</p> 
<?php do_action('woocommerce_register_form_end'); ?> 
</form> 
//<?php wp_redirect(home_url()); ?> 
+0

ちょっと@vipin、私は両方のコードを試して、まだ動作していません。 – Dannyboi

+0

こんにちは@vidish、私はあなたも同様に働いていないあなたも試みました。 – Dannyboi

関連する問題