in PHP, Tips, Tutorials, WordPress

How to Fix the WordPress Error ‘Fatal error: Call to undefined function wp_get_current_user()’

You may be seeing the following error on your WordPress site:

Fatal error: Call to undefined function wp_get_current_user()

It’s being caused by the wp_get_current_user() being called too early. You first have to wait for plugins_loaded.

If for example you were trying to do something like:

https://gist.github.com/bryceadams/0598a529118eab052180.js

…in a plugin, WordPress may throw back the above error.

To fix it, wrap it in a function and then add it to the plugins_loaded action, like so:

https://gist.github.com/bryceadams/e307a8fb3c9b17bb966a.js

Any questions, let me know!

Write a Comment

Comment