0

I want to return the Login Error Message even user key-in their privileges correctly. In other words, to terminate the login and show the error message.

When we key-in wrong passwords, wordpress shows:

There was an error authenticating your details.

ERROR: The password you entered for the username admin is incorrect. Lost your password?

.. on the login page. This is because of WP_Error Object is returned.

So my curious question is:

  • How to get/generate this WP_Error Object on my own, to return back? Is it Array?
1

How to get/generate this WP_Error Object on my own, to return back?

$error = new WP_Error;

It is fairly well documented in the Codex.

Once you instantiate the object there are methods for adding errors and for retrieving them, and functions like is_wp_error to check a variable to see if it is an error object or not.

  • Wow, like this?? Its cool!! $user = new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ), $username, wp_lostpassword_url() ) ); – 夏期劇場 May 14 '13 at 4:23

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.