Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

hexagongirl on "Display error messages in custom login form"

$
0
0

I am using wp_login_form() to display a custom front-end login form.

I am then using the following code to ensure if the user inputs invalid login credentials or leaves username/password blank, they don't see the WP login page, but get re-directed to the current page.

add_action( 'wp_login_failed', 'hex_front_end_login_fail' ); // hook failed login

function hex_front_end_login_fail( $user ) {
  $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') && $user!=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', 'hex_front_end_blank_login');

function hex_front_end_blank_login(){
  $referrer = $_SERVER['HTTP_REFERER'];
  if ( !strstr($referrer,'wp-login') && $user==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;
  }
}

Problem: I am now trying to work out how to display the relevant error messages once the user has been re-directed. Have been pouring over it for hours & drawn a complete blank.

Any help gratefully received!
Thanks


Viewing all articles
Browse latest Browse all 8245

Trending Articles