Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#35340 closed defect (bug) (invalid)

PHP Fatal Error: Call to undefined method WP_Error::exists()

Reported by: crackhd's profile crackhd Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords:
Focuses: Cc:

Description (last modified by dd32)

This error happens since update to Wordpress 4.4.0,
my current version is 4.4.1 (not in the list in trac)


[Thu Jan 07 ... 2016] [:error] [pid 21932] [client...] PHP Fatal error: Call to undefined method WP_Error::exists() in /var/websites/s4mp/wp-includes/capabilities.php on line 505


On line 505 in capabilities.php, change user_can() function from:

if ( ! $user || ! $user->exists() )
	return false;


if ( ! $user || $user instanceof WP_Error || ! $user->exists() )
	return false;

When it happens?
Enable "WP Maintenance mode" (with known plugin), then request password reset email and follow link. On my current configuration (without changes to Wordpress code) it raises this error when clicking "Submit" and sending password reset form.

This of course not happens on clean Wordpress installation, this is list of my plugins (folder names):

404-error-logger                                      custom-css-js-php                  rvg-optimize-database
404-to-start                                          custom-sidebars                    site-plugin
are-you-robot-recaptcha                               disable-search                     slate-admin-theme
bbpress                                               easy-fancybox                      smart-donations
bbpress-auto-suggest-topics-based-on-new-topic-title  easy-wp-smtp                       super-socializer
bbpress-mark-as-read                                  email-users                        syntax-highlight
bbpress-members-only                                  enhanced-text-widget               tabby-responsive-tabs
bbpress-permalinks-with-id                            google-analytics-dashboard-for-wp  tablepress
bbpress-post-topics                                   hello.php                          twitter-tracker
bbpress-quotes                                        index.php                          user-access-manager
bbpress-report-content                                jetpack                            wordpress-seo
bwp-recent-comments                                   jetpack-only-for-admins            wp-security-audit-log
comments-widget-plus                                  login-with-username-or-email       zencache
crayon-syntax-highlighter                             maintenance

I could not find which of them causes problem exactly but error itself points to bug in wordpress, i think, because "$user" becomes an instance of "WP_Errror".

Change History (6)

#1 @dd32
8 years ago

  • Description modified (diff)

#2 @crackhd
8 years ago

  • Severity changed from normal to minor

Error is caused in my site plugin, sorry for bad report.

here is code that causes this error:

// Password reset redirection
add_action('login_headerurl', 'site_checkamail_check');
function site_checkamail_check()
    // Check if have submitted 
    $confirm = ( isset($_GET['checkemail'] ) ? $_GET['checkemail'] : '' );
    if( $confirm )

 * Redirect user after successful login.
function my_login_redirect( $redirect_to, $request, $user )
    // Check if have an user instance...
    global $user;
    if (isset($user))
        // Check for moderator access
        if (user_can($user, 'delete_others_posts'))
            // redirect them to admin console
            return home_url('/wp-admin/');
            // Others go to home page
            echo "normal user!";
            return home_url();
    echo "no user!";
    return $redirect_to;

add_filter( 'login_redirect', 'my_login_redirect', 999, 3 );

I am not sure, but it was working fine previosly, and i don't understand why "WP_Error" appears in $user global.

#3 @crackhd
8 years ago

Finally fix is in third function:

function wpse_lost_password_redirect()

//  Fixing error
global $user; 
if (isset($user) && $user != null && !($user instanceof WP_Error))
    add_action('password_reset', 'wpse_lost_password_redirect');

Sorry it was my mistake i didn't notice before, probably.

#4 @swissspidy
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

#5 @lordspace
8 years ago

  • Keywords needs-testing added
  • Severity changed from minor to major
  • Version 4.4 deleted

Hey folks,

I am getting the same error when trying to login with ThemeMyLogin plugin and the user doesn't exist. will submit this at the plugin support page as well.

Fatal error: Call to undefined method WP_Error::exists() in /home/myuser/aaaa_app/ on line 509

WP. 4.5.1

Update: It seems this error was happening in my code which was executing in 'login_redirect' filter. It was checking for:

current_user_can( 'manage_options' )
user_can( $user, 'manage_options' )

Last edited 8 years ago by lordspace (previous) (diff)

#6 @swissspidy
8 years ago

  • Keywords needs-testing removed
  • Severity changed from major to normal
  • Version set to 4.4
Note: See TracTickets for help on using tickets.