WordPress: Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() / add_action() / get_header()
Code called a WordPress function before WordPress loaded, or a theme/plugin file was opened directly.
Seen on:
WordPress
Meaning
Plugins must hook into WordPress actions (init, plugins_loaded) rather than calling functions at file load. Loading a PHP file directly (bypassing WordPress) or pluggable functions used too early (wp_get_current_user before plugins_loaded) cause it.
Common causes
- Function called at plugin load time instead of in a hook
- PHP file accessed directly by URL
- Custom script without require wp-load.php
- Pluggable function used before it’s defined
⚡ Quick fix
- Move the call into an appropriate hook (init, wp_loaded)
- Never call theme/plugin files directly; use admin-ajax/REST
- For standalone scripts, use WP-CLI
Detailed fix by platform
WordPress
- php
add_action('init', function () { $user = wp_get_current_user(); });
How to diagnose
- Stack — File and line calling it
- Entry — Accessed directly?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Allowed memory size exhausted PHP Fatal error: Allowed memory size of X bytes exhausted
- ArgumentCountError Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected
- Call to member function on null Fatal error: Uncaught Error: Call to a member function x() on null
Most viewed in WordPress
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026