Fatal Error Call To Undefined Function Wp_get_current_user In /home
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta wp get current user role Discuss the workings and policies of this site About Us Learn more wp get current user name about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack call to undefined function wp_get_current_user() in plugin Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, wp_get_current_user() in wordpress helping each other. Join them; it only takes a minute: Sign up wordpress plugin -> Call to undefined function wp_get_current_user() up vote 12 down vote favorite 2 I'm trying to get the current user info in my plugin using the func wp_get_current_user(). But am getting Call to undefined function wp_get_current_user() Apparently this is happening because the file /wp-includes/pluggable
Capabilities.php Wordpress
which contains the function doesn't get loaded until after the plugins are loaded. Anybody any ideas on how to get the user details in my plugin? php wordpress-plugin wordpress share|improve this question edited Apr 26 at 23:32 madhead 7,97054787 asked May 25 '11 at 16:14 Daithí 2,41321526 add a comment| 5 Answers 5 active oldest votes up vote 16 down vote accepted 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(); // ... } share|improve this answer edited Sep 23 '15 at 7:29 answered May 25 '11 at 16:18 Denis de Bernardy 46.5k562106 3 worked like a charm. I was working of a class that loaded the user details on construct. So here's the code for anyone else. I now have: `add_action('plugins_loaded','construct_my_class'); function construct_my_class(){ $
Contact Work with us The Hub Log In Become a member New to the community? Start here Home Support Support Forums General wordpress Leonard Site Builder,
Wordpress Call To Undefined Function
Child of Zeus 56 pts 117 pts LEVEL 4 getting Fatal error: Call to wp_get_current_user not working undefined function wp_get_current_user() on client site a Day ago while working on a theme template I discovered that when attempting fatal error call to undefined function wordpress to update a plugin I now only get the following error when I attempt to go into the network admin areas of the system: Fatal error: Call to undefined function wp_get_current_user() in /home/k7707128/public_html/wp-includes/capabilities.php on http://stackoverflow.com/questions/6127559/wordpress-plugin-call-to-undefined-function-wp-get-current-user line 1356 I can only presume that either an updated item has added this call or it is in one of the documents I have added to the new theme I'm working on but the new theme does not have a call for wp_get_current_user() so where is this coming from it has locked me out of the administration area for the network. All General WordPress Plugins & https://premium.wpmudev.org/forums/topic/getting-fatal-error-call-to-undefined-function-wp_get_current_user-on-client-site Themes Multisite Features & Feedback Comments 2 Vinod Dalvi WP Unicorn 1,499 pts 17,482 pts LEVEL 29 Hi Leonard, Sorry to hear of the problem you are having. The function wp_get_current_user which is causing this issue is a default WordPress function so it is always defined in the WordPress and should not cause the undefined function error but it should only be used in the init or any subsequent action to call this function. Calling it outside of an action can lead to troubles. See #14024 for details. May be the plugin that you were updating is calling it incorrectly in its updated version. To recover from this issue disable the plugin that is causing this issue by renaming the plugin directory in the folder wp-content/plugins using FTP or any other File manager and use the older version of that plugin notifying the plugin author about the issue. Best Regards, Vinod Dalvi Leonard Site Builder, Child of Zeus 56 pts 117 pts LEVEL 4 Already done and issue is corrected thanks anyway. The additional info is a good tip. thanks FREE WordPress Tutorials, Tips and Tricks Subscribe JOIN 436048 HAPPY MEMBERS We pride ourselves on our level of customer support an
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings http://wordpress.stackexchange.com/questions/58429/how-do-i-call-wp-get-current-user-in-a-plugin-when-plugins-are-loaded-before-p and policies of this site About Us Learn more about Stack Overflow http://herbmiller.me/2014/01/14/fatal-error-call-undefined-function-wp_get_current_user-wp-includescapabilities-php-line-1344/ the company Business Learn more about hiring developers or posting ads with us WordPress Development Questions Tags Users Badges Unanswered Ask Question _ WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute: Sign up Here's how call to it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php? up vote 5 down vote favorite 3 The current result is "PHP Fatal error: Call to undefined function wp_get_current_user()" which makes sense, but doesn't help. call to undefined I need to use $current_user. Here is the code I'm currently using: $wp->init(); do_action( 'init' ); // Check site status $file='http://xxxxxxxx.com/wp-admin/wp_includes/pluggable.php'; if ( is_multisite() ) { if ( true !== ( $file = ms_site_check() ) ) { require( $file ); die(); } unset($file); } // Get the current user's info $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) ) return; echo $current_user->user_login; function paf_uname(){ return $current_user->user_login; } plugins php functions pluggable share|improve this question edited Jul 16 '12 at 15:32 EAMann♦ 25.5k455115 asked Jul 13 '12 at 20:54 PAFoster 2612 1 Plugins are loaded before pluggable, but there are hooks available well after that. Post the code that you're working with and we might be able to help you find a better hook. –EAMann♦ Jul 13 '12 at 23:31 $wp->init(); do_action( 'init' ); // Check site status $file='http://taddy.co.uk/wp-admin/wp_includes/pluggable.php'; if ( is_multisite() ) { if ( true !== ( $file = ms_site_check() ) ) { require( $file ); die(); } unset($file); } // Get the current user's info $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) ) re
in my development environment? Anything else in your development toolkit? Sites Fatal error: Call to undefined function wp_get_current_user() in \wp-includes\capabilities.php on line 1344Fatal error: Call to undefined function wp_get_current_user() in \wp-includes\capabilities.php on line 1344 Have you upgraded to WordPress 3.8 and received the following error? Fatal error: Call to undefined function wp_get_current_user() in \wp-includes\capabilities.php on line 1344 If so, and you want to understand one reason why you got this message, and how to recover from it, then read on. Short(ish) answer Code that worked in a previous version of WordPress doesn't work any more. What you should have done Whenever you upgrade WordPress, you are advised to take a backup of your database and files deactivate your plugins The reason for deactivating your plugins is to avoid getting fatal errors with code that no longer works. The theory being that you will discover which plugin doesn't work when you come to reactivating them. Unfortunately This process is not fail safe. It's possible that a broken plugin can be activated but it will cause a fatal error soon after. In this scenario you are then stuck; you will need to resort to using the control panel or FTP in order to fix the site. No matter what you try to do with WordPress you won't get anywhere. The generally accepted process involves deactivating plugins by renaming their folders or the main plugin file itself. Recover from a Fatal error using your site's control panel (cpanel) Technical explanation wp_get_current_user() is a pluggable function, defined in pluggable.php. Pluggable functions are routines that plugins may override. To allow this to happen pluggable.php is loaded AFTER the plugins. Extract from wp-settings.php: // Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin )
include_once