#35340 closed defect (bug) (invalid)
PHP Fatal Error: Call to undefined method WP_Error::exists()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | Users | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
This error happens since update to Wordpress 4.4.0,
my current version is 4.4.1 (not in the list in trac)
Log:
[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
Fix:
On line 505 in capabilities.php, change user_can() function from:
if ( ! $user || ! $user->exists() ) return false;
To:
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)
#3
@
8 years ago
Finally fix is in third function:
function wpse_lost_password_redirect() { wp_redirect(home_url('/login?msg=passwordchanged')); exit; } // 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
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#5
@
7 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/some-site.com/htdocs/wp-includes/capabilities.php 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' )
or
user_can( $user, 'manage_options' )
Error is caused in my site plugin, sorry for bad report.
here is code that causes this error:
I am not sure, but it was working fine previosly, and i don't understand why "WP_Error" appears in $user global.