[英]wordpress with cutom login form and custom theme
我正在打印具有自定義主題的自定義登錄表單,但是在提交用戶憑據時,總是會收到錯誤消息-即使它們是正確的。
這是我的functions.php
:
function rockport_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
// 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( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use
exit;
}
}
function rockport_blank_login() {
$referrer = $_SERVER['HTTP_REFERER'];
if ( !strstr($referrer, 'wp-login') ) { // login1 is the name of the loginpage.
if ( !strstr($referrer, '?login=failed') ) { // make sure we don’t append twice
wp_redirect( $referrer . '?login=failed' ); // let’s append some information (login=failed) to the URL for the theme to use
} else {
wp_redirect( $referrer );
}
exit;
}
}
add_action( 'authenticate', 'rockport_blank_login');
add_action( 'wp_login_failed', 'rockport_login_fail' ); // hook failed login
我究竟做錯了什么? 謝謝!
您忘記使用來檢查$ username。 您也可以在此處查看完整指南
add_action( 'wp_login_failed', 'rockport_login_fail' ); // hook failed login
function rockport_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER'];
// 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') && $username!=null ) {
if ( !strstr($referrer, '?login=failed' )) { // make sure we don’t append twice
wp_redirect( $referrer . '?login=failed'); // let’s append some information (login=failed) to the URL for the theme to use
} else {
wp_redirect( $referrer );
}
exit;
}
}
add_action( 'authenticate', 'rockport_blank_login');
function rockport_blank_login( $username ){
$referrer = $_SERVER['HTTP_REFERER'];
if ( !strstr($referrer,'wp-login') && $username==null ) { // login1 is the name of the loginpage.
if ( !strstr($referrer, '?login=failed') ) { // make sure we don’t append twice
wp_redirect( $referrer . '?login=failed' ); // let’s append some information (login=failed) to the URL for the theme to use
} else {
wp_redirect( $referrer );
}
exit;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.