I want to login in wordpress with username , email id and phone number.
where I am inserting phone number in User meta at the time of User registration.
Is there any hook where I can access user meta and validate it with password for login.
https://wordpress.org/plugins/wp-email-login/
I came to know that this plugin is used for username and email id validation at the login time. So, I can login with username and email id but my main issue was phone nmber which is in user meta table.
我想在wordpress中使用用户名,电子邮件ID和电话号码登录
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- douba5540 2016-03-15 06:38关注
This is not the preferred solutions as we need to create a custom login form for achieving this
You need to create a template at front end to be displayed like this :
<form id="login" name="form" action="<?php echo home_url(); ?>/login/" method="post"> <input id="username" type="text" placeholder="Username" name="username"> <input id="user_phone" type="text" placeholder="Phone Number" name="user_phone"> <input id="password" type="password" placeholder="Password" name="password"> <input id="submit" type="submit" name="submit" value="Submit"> </form>
Above that write this php code which will work on form
I am getting the User ID of the user by its username and then getting User Phone in the user_meta table by User ID and then matching it with submitted user phone number.
You can make changes in the below code for validating the phone number separately.
I have assumed the meta_key and input type name both as "user_phone"
if($_POST) { global $wpdb; //We shall SQL escape all inputs $user_phone = $wpdb->escape($_REQUEST['user_phone']); $username = $wpdb->escape($_REQUEST['username']); $password = $wpdb->escape($_REQUEST['password']); $remember = $wpdb->escape($_REQUEST['rememberme']); $user = get_userdatabylogin($username); if($remember) $remember = "true"; else $remember = "false"; $login_data = array(); $login_data['user_login'] = $username; $login_data['user_password'] = $password; $login_data['remember'] = $remember; //get user phone number from DB $org_phone = get_user_meta($user->ID , 'user_phone',1); $user_verify = wp_signon( $login_data, false ); if ( is_wp_error($user_verify) && $org_phone == $user_phone) { header("Location: " . home_url() . "/login/error/"); // Note, I have created a page called "Error" that is a child of the login page to handle errors. This can be anything, but it seemed a good way to me to handle errors. } else { echo "<script type='text/javascript'>window.location='". home_url() ."'</script>"; exit(); } } else { // No login details entered - you should probably add some more user feedback here, but this does the bare minimum echo "Invalid login details"; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
- ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
- ¥15 CSAPPattacklab
- ¥15 一直显示正在等待HID—ISP
- ¥15 Python turtle 画图
- ¥15 关于大棚监测的pcb板设计
- ¥15 stm32开发clion时遇到的编译问题
- ¥15 lna设计 源简并电感型共源放大器
- ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
- ¥15 Vue3地图和异步函数使用