Call to undefined function (WordPress) WordPress Origin: Application & API OSI layer 7 · Application Last updated 12 Oct 2026

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.

Exact message you may see Call to undefined function wp_get_current_user()Call to undefined function add_action()Call to undefined function get_header()Call to undefined function is_user_logged_in()
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

  1. Move the call into an appropriate hook (init, wp_loaded)
  2. Never call theme/plugin files directly; use admin-ajax/REST
  3. For standalone scripts, use WP-CLI

Detailed fix by platform

WordPress

  1. php
    add_action('init', function () {
        $user = wp_get_current_user();
    });

How to diagnose

  1. Stack — File and line calling it
  2. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Allowed memory size exhausted — PHP Fatal error: Allowed memory size of X bytes exhausted (PHP)Allowed memory size e…ArgumentCountError — Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected (PHP)ArgumentCountErrorCall to member function on null — Fatal error: Uncaught Error: Call to a member function x() on null (PHP)Call to member functi…Call to undefined function — PHP Fatal error: Uncaught Error: Call to undefined function (PHP)Call to undefined fun…Call to undefined function create_function() — WordPress on PHP 8: Fatal error: Uncaught Error: Call to undefined function create_function() / each() (WordPress)Call to undefined fun…Cannot redeclare — Fatal error: Cannot redeclare function foo() (previously declared in …) (PHP)Cannot redeclareCannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …Critical error — WordPress: There Has Been a Critical Error on This Website (WordPress)Critical errorCall to u…

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.