脚本宝典收集整理的这篇文章主要介绍了php – 如何在自定义登录表单中检索wp错误,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
add_action( 'wp_login_Failed','front_end_login_fail' ); function front_end_login_fail( $username ) { $_SESSION['uname'] = $username; // Getting URL of the login page $referrer = $_SERVER['HTTP_REFERER']; $login_Failed_error_codes = array( 'empty_password','empty_email','invalid_email','invalIDCombo','empty_username','invalid_username','incorrect_password' ); // if there's a valid referrer,and IT's not the default log-in screen if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) { wp_redirect( get_PErmalink( 93 ) . "?login=Failed" ); exit; } }
现在这个功能可以正常工作,但是现在按照wordpress功能,它提供如下:
1.如果用户输入真实用户名,但错误的密码会显示为“incorrect_password”
2.如果用户输入虚假用户名,但真实密码将显示错误为“invalid_username”
3.如果用户输入错误的用户名,但错误的密码会显示为“invalidcombo”
添加如此请在代码中检查变量$login_Failed_error_codes …
我已经做了一些@L_406_32@.我有一些类叫“WP_error”.但是我不知道它是如何与这个代码一起使用的.
我只是坚持如何将WP_error的对象从wp-login.PHP传递给我的csutom模板?
谢谢…任何帮助将是可敬的.
改用login_redirect过滤器:
add_filter('login_redirect','my_login_redirect',10,3); function my_login_redirect($redirect_to,$requested_redirect_to,$user) { if (is_wp_error($user)) { //Login Failed,find out why... $error_types = array_keys($user->errors); //Error type seems to be empty if none of the fields are filled out $error_type = 'both_empty'; //Otherwise just get the First error (as far as I kNow there //will only ever be one) if (is_array($error_types) && !empty($error_types)) { $error_type = $error_types[0]; } wp_redirect( get_permalink( 93 ) . "?login=Failed&reason=" . $error_type ); exit; } else { //Login OK - redirect to another page? return home_url(); } }
以上是脚本宝典为你收集整理的php – 如何在自定义登录表单中检索wp错误全部内容,希望文章能够帮你解决php – 如何在自定义登录表单中检索wp错误所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。