Since the upgrade to WordPress , my multi-site installation has been plagued with the following error:
PHP Fatal error: Call to undefined function wp_get_current_user() in /public_html/wp-includes/capabilities.php on line
First, the error occurred when I deactivated the NextGen Gallery plugin on http://www.domain.com/. Deactivating the plugin caused the error to rear its ugly head which causes the site to fail to load.
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 version x.x.x . 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/xx. 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.
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.
include_once(ABSPATH . 'wp-includes/pluggable.php');
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.