wordpress - 通过前端注册表单在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 ---------------------
解决方案
推荐阅读
- c# - 在此之后如何获取每个字符:
- c# - GetHashCode() - 不可变的值?
- visual-studio - 在一个解决方案中构建和运行两个项目
- image-processing - 如何在这张图片中分离这两个边界?
- php - 在ajax中使用设置间隔时滚动到顶部
- node.js - 当我需要导入像 const promise = require ('promise') 这样的承诺以具有 .then 的属性时
- c# - 将本机结构定义导出到托管代码
- regex - 用于在 Notepad++ 中基于另一个文本替换文本的正则表达式
- excel - 为什么 AutoSum 命令不起作用?
- python - 从脚本中的会话转移到在同一会话上打开 selenium 浏览器(和无头浏览器)