
Since the upgrade to WordPress 3.6, my multi-site installation has been plagued with the following error:
[28-Aug-2013 13:02:59 UTC] PHP Fatal error: Call to undefined function wp_get_current_user() in /public_html/wp-includes/capabilities.php on line 1281First, the error occurred when I deactivated the NextGen Gallery plugin on http://www.fontlife.com/. Deactivating the plugin caused the error to rear its ugly head which causes the site to fail to load.
Next, it happened when I disabled open registration using the S2Member plugin on this site. Deactivating open registration caused the S2Member general options screen to lose it's formatting and appear as one giant text file. When I attempted to visit the site, the site failed to load displaying the above error message instead.
After researching the error, I found several references to a fix that most writers were unsure that it is the proper fix or not. The fix requires modifying the wp-includes/capabilities.php file. This is a WordPress core file. Modifying any WordPress core file is generally a big no-no, but in this case, adding a single line to capabilities.php fixes a multitude of sins. The problem with modifying a WordPress core file is that once you do, you'll have to keep doing it every time there's an update issued for WordPress.
There are references to this problem that extend back to the release of WordPress 3.0.1. At least one WordPress Developer, Andrew Nacin, mentioned in a 2011 post that he thought the issue began with https://core.trac.wordpress.org/changeset/15452, released on 07/21/10. In that post, Nacin says:
pluggable.php doesn't get loaded until after all plugins are loaded. This cripples a lot of functions that then rely on, directly or indirectly, wp_get_current_user(), among others.
We don't even load the current user until just before the init hook. Doing anything to the current user before the init hook will not work.
The Fix
To apply the fix, you must comfortable with modifying a .php file. If you are not comfortable with this, stop now and ask someone who is for help.
Open capabilities.php in your favorite text editor and add the following line at the top of the file after the php opening tag:
Save the file and copy it back up to your wp-includes folder. That's all there is to it, until the next WordPress update that is. Anytime there is a new WordPress release, there's a chance that they'll release a new capabilities.php. You'll have to keep checking your error_log and make this change for each subsequent WordPress update unless you can find the plugin(s) that are calling wp_get_current_user() too early.
Awesome! Fixed just in few seconds :)
All I did was to go into the cPanel’s File Manager, went to /public_html/wp-content/plugins and deleted the folder that the broken plugin was in… I tried yours too but that didn’t work for my configuration.
You are a genius! I’ve been working on this issue for several days and your solution fixed it and totally makes sense… sometimes the simplest solutions are the beast!
Hi Aidan, you are indeed too much. I just did it the way say it and it worked and I have spent three days finding how to solve the problem. The most annoying of it all is that I informed my web host provider and told me to delete the whole wordpress installation and start not minding the time and efforts I have put into the site.
Thanks a million
Thank you so much.
Even in wordpress 4.2.2 I still have this problem with s2member plugin.
Thanks so much!
Genius. Your fix got me back in to the admin panel so that I could remove the offending plugin.
Thanks!
Glad I could help!