wordpress与自定义登录表单和自定义主题

时间:2015-04-21 11:49:20

标签: php wordpress login themes customization

我正在使用自定义主题打印自定义登录表单,但是当我提交用户凭据时,我总是会收到错误 - 即使它们是正确的。

这是我的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

我做错了什么?谢谢!

1 个答案:

答案 0 :(得分:1)

你忘记用它来检查$ username。 you can also check the complete guide here

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;
  }
}