0

I have been playing arround for a day and didn't manage to achieve what I want. Is it possible to enqueue a script if user fails (username or password) to login? I checked and played arround with wp_login_failed but no luck so far!

I want to use this function in a popup login form. After login (success or failure) the page refreshes so I want to force pop up show automatically after a failure (user should not manually click the login button again) by adding javascript ( $('#login-dialog').show(); )

0

I worked out a way to conditionally print a script to the head of the page, but not to actually enqueue it.

The code depends on the presence of the wp_shake_js callback that is conditionally added to the login page on login failure. If that hook is present, the assumption is that the login failed.

Unfortunately, that callback is hooked to login_head which executes after login_enqueue_scripts so you need to print the script, rather than enqueue it.

add_action(
  'login_head',
  function() {
    if (has_action('login_head','wp_shake_js')) {
      echo '<script type="text/javascript">alert("howdy");</script>';
    }
  },
  13
);

I can't help but think there is a better way, but I can't find it (and I am running out of time for WPSE this morning :) ).

| improve this answer | |
  • Thanks for the reply dum, printing the script would work for me too but I need to print it ONLY if the logon fail. :) – ArgGeo Oct 14 '13 at 15:45
  • This should print for any login failure and not otherwise. Have you tested? Under what conditions does it behave incorrectly? – s_ha_dum Oct 14 '13 at 16:05
  • I want to use it in a popup login form. After login (success or failure) the page refreshes so I want to force pop up show automatically after a failure (user should not manually click the login button again) by adding javascript ( $('#login-dialog').show(); – ArgGeo Oct 14 '13 at 16:25
  • This sounds like there is a fair bit of information missing from the question. Please fill in the missing details. – s_ha_dum Oct 14 '13 at 20:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.