Articles Comments

Marco Luthe Online! » WordPress Stuff » Call To Undefined Function get_currentuserinfo()

Call To Undefined Function get_currentuserinfo()

I just recently updated my WordPress plugins, and after I downloaded Maintenance Mode (v4.0) and uploaded it onto my WordPress blog, Filosofo Comments Preview threw an error that said:

Call to undefined function get_currentuserinfo()…

That was pretty odd, because both plugins worked fine before – now, after updating one of them, the other one threw an error.

After doing some research, I found this post on the WordPress support forum that says that get_currentuserinfo() is actually defined within pluggable.php which is loaded AFTER all plugins – that means that the function is not yet ready if you call it normally in your plugin.

I found the answer within the code of the Maintenance Mode plugin – you have to manually insert that pluggable.php using the require statement in php.

So, look for this code in Filosofo Comments Preview (should be line 638 in v1.5):

if ( !function_exists('wp_get_current_user') ) {
function wp_get_current_user() {
global $current_user;
get_currentuserinfo();
return $current_user;
}

Extend it to this:

if ( !function_exists('wp_get_current_user') ) {
function wp_get_current_user() {
// Insert pluggable.php before calling get_currentuserinfo()
require (ABSPATH . WPINC . '/pluggable.php');
global $current_user;
get_currentuserinfo();
return $current_user;
}
}

I can’t tell if you need require or require_once – all I can say is that both work fine.

Filed under: WordPress Stuff · Tags: , , , , ,

  • Mark

    Thanks for this wonderful piece of information that saved me losing anymore hair and sleep. After inserting require (ABSPATH . WPINC . ‘/pluggable.php’); before wp_get_current_user() the code worked like a charm. Two days I scoured the WP Codex and the Web.

  • http://wpmash.com/call-to-undefined-function-get_currentuserinfo-marco-luthe-online/ Call To Undefined Function get_currentuserinfo() | Marco Luthe Online! | WpMash – WordPress News

    [...] See the article here: Call To Undefined Function get_currentuserinfo() | Marco Luthe Online! [...]

  • Mohan

    Thanks for the info :)
    A quick google search bought me here.

  • http://www.soon7.com/developpements/gengo-comment-resoudre-lerreur-call-to-undefined-function-get_currentuserinfo-in-wp-contentpluginsgengogengo-php-on/ Gengo : comment résoudre l’erreur Call to undefined function get_currentuserinfo() in /wp-content/plugins/gengo/gengo.php on | Soon7 : Web, flash, stratégies ,Réseaux sociaux ,SEO en Martinique

    [...] solution à ce souci est relativement simple, et est donnée ici , et effectivement c’est logique [...]

  • Jürgen Schulze

    thanks

blog comments powered by Disqus