wordpress plugin -> Call to undefined function wp_get_current_user()

Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn't get loaded until after the plugins are loaded.

Indeed it is. So wrap whichever thing you're doing in a function, and hook it onto the plugins_loaded or init hook. (see the wp-settings.php file)

Example:

add_action('init','do_stuff');
function do_stuff(){
  $current_user = wp_get_current_user();
  // ...
}

After the installation of wp 3.8 I had the same problem with a page I get with ajax. I fixed it with the following code:

if(!function_exists('wp_delete_user')) {
    include(ABSPATH . "wp-admin/includes/user.php.");
}

Apparently the function is moved from pluggable.php to user.php. Still I don't understand why it doesn't work after I included the wp-blog-header.php.


my issue solved with this code please

include_once(ABSPATH . 'wp-includes/pluggable.php');

You can use this,

<?php
if(!function_exists('wp_get_current_user')) {
    include(ABSPATH . "wp-includes/pluggable.php"); 
}
?>

this should fix your problem :)

Tags:

Php

Wordpress