通过前端注册表单在wordpress中创建多个用户角色

时间:2018-05-03 09:48:33

标签: wordpress

我创建了前端注册表单及其工作方式。我尝试创建2个具有2个用户角色的注册表单。但我无法通过前端创建2个用户,任何人都可以帮助我。

候选人登记表

<section class="job-seeker-reg-area body-bg">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="page-title page-title-border page-title-small">
                 <?php if ( $atts['show_title'] ) : ?>
                    <h1>><?php _e( 'CREATE JOB SEEKER PROFILE', 'test' ); ?></h1>
                <?php endif; ?>

            </div>
          </div>
          <div class="col-md-8 col-md-offset-2">
            <div class="social-login">
              <i class="fab fa-linkedin-in"></i>
              <a href="#">Sign in with LinkedIn</a>
            </div>
            <div class="login-wall">
              I already have a Job Seeker account. <a href="#">Sign me in</a>
            </div>
            <?php if ( count( $atts['errors'] ) > 0 ) : ?>
                <?php foreach ( $atts['errors'] as $error ) : ?>
                    <p>
                        <?php echo $error; ?>
                    </p>
                <?php endforeach; ?>
            <?php endif; ?>
            <form action="<?php echo wp_registration_url(); ?>" method="POST" id="signupform">
              <div class="form-group">
                <label for="name">Full Name</label>
                <input type="text" class="form-control" id="name" name="fullname">
              </div>
              <div class="form-group">
                <label for="email">Email *</label>
                <input type="email" class="form-control" id="email" required name="email">
              </div>
              <div class="form-group">
                <label for="password">Password *</label>
                <input type="password" class="form-control" id="password" required name="password">
              </div>
              <div class="form-group">
                <label for="con_password">Confirm Password *</label>
                <input type="password" class="form-control" id="con_password" required name="confirmpassword">
              </div>
              <div class="checkbox">
                <label>
                  <input type="checkbox" required name="check">  <a href="#">I agree to the terms of use *</a>
                </label>
              </div>
              <input type="submit" name="submit" class="btn btn-default btn-orange"
                   value="<?php _e( 'Register', 'test' ); ?>"/>
            </form>
          </div>
        </div>
      </div>
    </section>

对于候选人数据传递

private function register_user( $fullname, $email, $password, $confirmpassword ) {
            $errors = new WP_Error();

            // Email address is used as both username and email. It is also the only
            // parameter we need to validate
            if ( ! is_email( $email ) ) {
                $errors->add( 'email', $this->get_error_message( 'email' ) );
                return $errors;
            }

            if ( username_exists( $email ) || email_exists( $email ) ) {
                $errors->add( 'email_exists', $this->get_error_message( 'email_exists') );
                return $errors;
            }

            // Generate the password so that the subscriber will have to check email...
            // $password = wp_generate_password( 12, false );

            $user_data = array(
                'user_login'    => $email,
                'user_email'    => $email,
                'user_pass'     => $password,
                'role'          => 'candidate'
                // 'first_name'    => $first_name,
                // 'last_name'     => $last_name,
                // 'nickname'      => $first_name,
            );

            $user_id = wp_insert_user( $user_data );
            wp_new_user_notification( $user_id );

            return $user_id;
        }
 ------------- its working -------------------

雇主登记表

    <section class="job-seeker-reg-area body-bg">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="page-title page-title-border page-title-small">
               <?php if ( $atts['show_title'] ) : ?>
                    <h1>><?php _e( 'CREATE Employer PROFILE', 'test' ); ?></h1>
                <?php endif; ?>
            </div>
          </div>



          <div class="col-md-8 col-md-offset-2 col-sm-12">
            <div class="social-login">
              <i class="fab fa-linkedin-in"></i>
              <a href="#">Sign in with LinkedIn</a>
            </div>
            <div class="login-wall">
              I already have an Employer account. <a href="#">Sign me in</a>
            </div>

            <?php if ( count( $atts['errors'] ) > 0 ) : ?>
              <?php foreach ( $atts['errors'] as $error ) : ?>
                  <p>
                      <?php echo $error; ?>
                  </p>
              <?php endforeach; ?>
          <?php endif; ?>
            <form action="<?php echo wp_registration_url(); ?>" id="signupformemployer" method="POST">
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="name">Full Name</label>
                  <input type="text" class="form-control" id="name" name="fullnameemployer">
                </div>
              </div>
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="email">Email *</label>
                  <input type="email" class="form-control" id="email" required name="emailemployer">
                </div>
              </div>
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="password">Password *</label>
                  <input type="password" class="form-control" id="password" required name="passwordemployer">
                </div>
              </div>
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="con_password">Confirm Password *</label>
                  <input type="password" class="form-control" id="con_password" required name="confirmpasswordemployer">
                </div>
              </div>
              <div class="col-md-12 col-sm-6">
                <div class="form-group">
                  <label for="company_name">Company Name *</label>
                  <input type="text" class="form-control" id="company_name" required name="companyname">
                </div>
              </div>
              <div class="col-md-12 col-sm-6">
                <div class="form-group">
                  <label for="location">Company Type</label>
                  <select class="form-control" name="companytype">
                    <option>Select Company Type</option>
                    <option>Direct Employer</option>
                    <option>Recruitment Agency</option>
                    <option>Other</option>
                  </select>
                </div>
              </div>
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="location">Location</label>
                  <input type="text" class="form-control" id="location" name="companylocation">
                </div>
              </div>
              <div class="col-md-6 col-sm-6">
                <div class="form-group">
                  <label for="phone">Phone</label>
                  <input type="text" class="form-control" id="phone" name="companyphone">
                </div>
              </div>
              <div class="col-md-12 col-sm-12">
                <div class="form-group">
                  <label for="website">Website</label>
                  <input type="text" class="form-control" id="website" name="companywebsite">
                </div>
              </div>
              <div class="col-md-12 col-sm-12">
                <div class="form-group">
                  <label for="logo">Logo</label>
                  <input type="file" id="logo" name="companylogo">
                </div>
              </div>
              <div class="col-md-12 col-sm-12">
                <div class="form-group">
                  <textarea class="form-control" rows="10" name="companydesc"></textarea>
                </div>
              </div>
              <div class="col-md-12 col-sm-12">
                <div class="form-group">
                  <div class="checkbox" name="companycheckbox">
                    <label>
                      <input type="checkbox" required>  <a href="#">I agree to the terms of use *</a>
                    </label>
                  </div>
                </div>
              </div>
               <input type="submit" name="submitemployer" class="btn btn-default btn-orange"
                   value="<?php _e( 'Register', 'test' ); ?>"/>
            </form>
          </div>
        </div>
      </div>
    </section>

雇主数据传递

private function register_user_employer( $emfullname, $ememail, $empassword, $emconfirmpassword, $companyname, $companytype, $companylocation, $companyphone, $companywebsite, $companylogo, $companydesc, $companycheckbox ) {
            $errors = new WP_Error();

            // Email address is used as both username and email. It is also the only
            // parameter we need to validate
            if ( ! is_email( $ememail ) ) {
                $errors->add( 'email', $this->get_error_message( 'email' ) );
                return $errors;
            }

            if ( username_exists( $ememail ) || email_exists( $ememail ) ) {
                $errors->add( 'email_exists', $this->get_error_message( 'email_exists') );
                return $errors;
            }

            // Generate the password so that the subscriber will have to check email...
            // $password = wp_generate_password( 12, false );

            $user_data = array(
                'user_login'    => $ememail,
                'user_email'    => $ememail,
                'user_pass'     => $empassword,
                'role'          => 'employer'
                // 'first_name'    => $first_name,
                // 'last_name'     => $last_name,
                // 'nickname'      => $first_name,

            );

            $user_id = wp_insert_user( $user_data );
            wp_new_user_notification( $user_id );

            return $user_id;
        }
------------------ its not working ---------------------

0 个答案:

没有答案
相关问题