I’ve got a strange one going on here. Tried to implement is_wp_error in multiple situations, but it fails. Here’s the thing, illustrated with my last attempt:
I want to login a user by wp_signon()
, check if there are errors and if so, display them.
So I wrote the following lines of code:
$user = wp_signon();
if(is_wp_error($user)){
$result = 'Error-' .
$user->get_error_message();
} else {
$result = 'Login succeed';
}
echo $result;
The strange thing is, is_wp_error()
doesn’t return false (so there is an error). But $user->get_error_message();
is empty.
Tried it in different actions. When debugging, echo is_wp_error();
returns 0.
var_dump(wp_is_error());
returns empty arrays.
Furthermore, even when valid credentials are given, is_wp_error() still returns true. Also when testing in other circumstances (and on a clean WP installation)
Any thoughts?
I took a look through the
wp_signon()
code (located at http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/user.php#L0 )Looks like the error is blanked out if a blank username or password is passed in. (lines 56 and 57 of that file.)