php – WordPress两步注册表
我正在努力实现以下目标,我不知道从哪里开始.
我正在尝试通过两个步骤创建注册/注册表单. 第一步:要有2个输入字段(名称,电子邮件),用户提交后,将发送一个电子邮件,并链接到第二步. 第二步:用户输入发送到他的电子邮件的链接,输入第二个表单的页面.它具有使用的电子邮件和名称的价值,以及他将访问某些页面的其他2个字段(用户名,密码). 我找不到从哪里开始,没有插件符合以下要求. 问候, 穆斯塔法.
步骤1
首先,您应该创建两个单独的模板(每个步骤一个). <?php /* ** Template Name: Step 1 */ get_header(); if ( !empty( $_POST['firstname'] ) && !empty( $_POST['email'] ) ) { $link = 'http://my-site/step-2'; $link = add_query_arg( array( 'firstname' => $_POST['firstname'],'email' => $_POST['email'],),$link ); $subject = 'New user registration'; $message = 'Please click on the following link to complete your registration: ' . $link; $headers = array('Content-Type: text/html; charset=UTF-8'); $result = wp_mail( $_POST['email'],$subject,$message,$headers ); if ( $result ) { $message = 'Please check your email address to complete the registration'; } else { $message = 'Something went wrong. Please contact the administrator'; } echo $message; } else { ?> <form method="POST" action=""> <input type="text" name="firstname" placeholder="First Name"> <input type="email" name="email" placeholder="Email address"> <input type="submit" value="Submit"> </form> <?php } get_footer(); 我们创建一个简单的检查,如果表单被提交,所有的字段都被填充. 第2步 我们将创建一个单独的模板,我们将使用$_GET填充第一个数据,我们将添加两个将为空的新字段(用户名和密码). <?php /* ** Template Name: Step 2 */ get_header(); if ( !empty( $_POST['firstname'] ) && !empty( $_POST['email'] ) && !empty( $_POST['password'] ) ) { $user_id = username_exists( $_POST['username'] ); if ( !$user_id and email_exists($_POST['email']) == false ) { $user_id = wp_create_user( $_POST['username'],$_POST['password'],$_POST['email'] ); if ( $user_id ) { update_user_meta($user_id,'first_name',$_POST['firstname']); $message = 'User has been created'; } } else { $message = 'User already exists!'; } echo $message; } else { ?> <form method="POST" action=""> <input type="text" name="firstname" value="<?php echo ( !empty( $_GET['firstname'] ) ) ? $_GET['firstname'] : '' ; ?>" placeholder="First Name"> <input type="email" name="email" value="<?php echo ( !empty( $_GET['email'] ) ) ? $_GET['email'] : '' ; ?>" placeholder="Email Address"> <input type="text" name="username" placeholder="Username"> <input type="password" name="password" placeholder="Password"> <input type="submit" value="Submit"> </form> <?php } get_footer(); 如果第二个表单被提交,并且一切正常,我们可以创建用户. 您可以对我的代码进行无限的修改,但这是基础.例如,我们可以使字段需要,我们可以检查密码强度,名称长度等. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |