I am trying to hook into the authenticate return value to display error message on custom login form. The $user object is not returned.

add_action( 'authenticate', 'my_login_check' );
function my_login_check( $user ){
    if( is_wp_error( $user ) ){
  • try add_filter('authenticate', 'my_login_check', 9999, 1); – Shazzad Feb 1 '14 at 21:33
  • 1
    Do you mean that $user is not passed into my_login_check? Or that it is not returned from that function? If the latter, that is because you haven't returned it. – s_ha_dum Feb 1 '14 at 23:25
  • 1
    I think you are using the wrong hook. The 'authenticate' hook is for authenticating the user - meaning you take the information passed by the hook via parameters and return a WP_User object. If the $user parameter is empty or !is_a($user, 'WP_User'), that means that the user has failed authenticating via other authentication methods. – user42826 Feb 2 '14 at 4:25
  • It sounds like you might want to use the hook 'wp_signon' - codex.wordpress.org/Function_Reference/wp_signon – user42826 Feb 2 '14 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.