WordPress添加前台注册功能的方法


当前第2页 返回上一页

php代码如下:

代码如下:
<?php
if( !emptyempty($_POST['ludou_reg']) ) {
$error = '';
$sanitized_user_login = sanitize_user( $_POST['user_login'] );
$user_email = apply_filters( 'user_registration_email', $_POST['user_email'] );
// Check the username
if ( $sanitized_user_login == '' ) {
$error .= '<strong>错误</strong>:请输入用户名。
';
} elseif ( ! validate_username( $user_login ) ) {
$error .= '<strong>错误</strong>:此用户名包含无效字符,请输入有效的用户名
。';
$sanitized_user_login = '';
} elseif ( username_exists( $sanitized_user_login ) ) {
$error .= '<strong>错误</strong>:该用户名已被注册,请再选择一个。
';
}
// Check the e-mail address
if ( $user_email == '' ) {
$error .= '<strong>错误</strong>:请填写电子邮件地址。
';
} elseif ( ! is_email( $user_email ) ) {
$error .= '<strong>错误</strong>:电子邮件地址不正确。!
';
$user_email = '';
} elseif ( email_exists( $user_email ) ) {
$error .= '<strong>错误</strong>:该电子邮件地址已经被注册,请换一个。
';
}

// Check the password
if(strlen($_POST['user_pass']) < 6)
$error .= '<strong>错误</strong>:密码长度至少6位!
';
elseif($_POST['user_pass'] != $_POST['user_pass2'])
$error .= '<strong>错误</strong>:两次输入的密码必须一致!
';

if($error == '') {
$user_id = wp_create_user( $sanitized_user_login, $_POST['user_pass'], $user_email );

if ( ! $user_id ) {
$error .= sprintf( '<strong>错误</strong>:无法完成您的注册请求... 请联系<a >管理员</a>!
', get_option( 'admin_email' ) );
}
else if (!is_user_logged_in()) {
$user = get_userdatabylogin($sanitized_user_login);
$user_id = $user->ID;

// 自动登录
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);
}
}
}

希望本文所述对大家WordPress建站有所帮助。


标签:WordPress

返回前面的内容

相关阅读 >>

基础的wordpress插件制作教程

输出wordpress数据库查询的具体内容 减少数据库查询次数

wordpress中函数get_term_link的参数设置问题

网站备份 wordpress博客备份及恢复数据详细教程

wordpress主题评论中添加回复的方法

wordpress获取当前页面url地址的方法

wordpress 显示文章日期的方法

菜鸟使用wordpress建站的几点心得

对帝国cms、dedecms、phpcms、discuz、phpwind、xiuno负载测试总结

wordpress速度优化-nginx fastcgi_cache缓存加速

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...