带有联系表 7 的 wordpress 订阅者
wordpress subscriber with contact form 7
有谁知道联系表格 7 是否可以有一个复选框,当它被访问者激活时,这个访问者被注册为 wordpress 用户,订阅者?
经过Howard E的评论,问题变为...
如何使用表单数据wpcf7_before_send_mail
注册新用户?
大概是这样的,不知道是不是完全正确...
add_action( 'wpcf7_before_send_mail', 'register_user' );
function register_user($cf7) {
$form_id = $cf7->id();
if ($form_id == 300 || $form_id == 301 || $form_id == 302) {
$submission = WPCF7_Submission :: get_instance();
}
if ($submission) {
if (empty($posted_data)) { return; }
$accept = $posted_data['acceptance-register-yes']; //acceptance check to be registered
if (empty($accept)) { return; }
$email = $posted_data['your-email'];
$name1 = $posted_data['your-name'];
$name2 = $posted_data['your-last-name'];
$name = ''; //here will go function to delete spaces and generate user name from $name1 + $name2
$pass = ''; //here will go function to random password
function create_user($n,$p,$e){
if (!username_exists($n) && !email_exists($e)) {
$user_id = wp_create_user($n, $p, $e);
$user = new WP_User($user_id);
$user->set_role( 'subscriber' );
}
}
create_user($name,$pass,$email);
}
}
非常感谢
您可以像这样创建一个用户并连接到 wpcf7_before_send_mail
。
function wp_create_custom_account(){
// Get the WPCF7 Submission instance
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$posted_data = $submission->get_posted_data();
// Get the posted variables
$username = isset($posted_data['username'])?$posted_data['username']:'';
$password = isset($posted_data['password'])?$posted_data['password']:'';
$eml = isset($posted_data['eml'])?$posted_data['eml']:'';
// This can be radio or checkbox. Adjust your code accordingly
$radio = isset($posted_data['radio'][0])?$posted_data['radio'][0]:'';
if ($radio) {
$user = $username;
$pass = $password;
$email = eml;
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
}
}
}
}
add_action('wpcf7_before_send_mail','wp_create_custom_account');
有谁知道联系表格 7 是否可以有一个复选框,当它被访问者激活时,这个访问者被注册为 wordpress 用户,订阅者?
经过Howard E的评论,问题变为...
如何使用表单数据wpcf7_before_send_mail
注册新用户?
大概是这样的,不知道是不是完全正确...
add_action( 'wpcf7_before_send_mail', 'register_user' );
function register_user($cf7) {
$form_id = $cf7->id();
if ($form_id == 300 || $form_id == 301 || $form_id == 302) {
$submission = WPCF7_Submission :: get_instance();
}
if ($submission) {
if (empty($posted_data)) { return; }
$accept = $posted_data['acceptance-register-yes']; //acceptance check to be registered
if (empty($accept)) { return; }
$email = $posted_data['your-email'];
$name1 = $posted_data['your-name'];
$name2 = $posted_data['your-last-name'];
$name = ''; //here will go function to delete spaces and generate user name from $name1 + $name2
$pass = ''; //here will go function to random password
function create_user($n,$p,$e){
if (!username_exists($n) && !email_exists($e)) {
$user_id = wp_create_user($n, $p, $e);
$user = new WP_User($user_id);
$user->set_role( 'subscriber' );
}
}
create_user($name,$pass,$email);
}
}
非常感谢
您可以像这样创建一个用户并连接到 wpcf7_before_send_mail
。
function wp_create_custom_account(){
// Get the WPCF7 Submission instance
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$posted_data = $submission->get_posted_data();
// Get the posted variables
$username = isset($posted_data['username'])?$posted_data['username']:'';
$password = isset($posted_data['password'])?$posted_data['password']:'';
$eml = isset($posted_data['eml'])?$posted_data['eml']:'';
// This can be radio or checkbox. Adjust your code accordingly
$radio = isset($posted_data['radio'][0])?$posted_data['radio'][0]:'';
if ($radio) {
$user = $username;
$pass = $password;
$email = eml;
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
}
}
}
}
add_action('wpcf7_before_send_mail','wp_create_custom_account');