获取登录用户信息-调用未定义的函数(2)


Get logged in user info - call to undefined function (2)

我转发这个问题是因为问题没有解决。在一个相关的问题中,下面的答案可能是解决方案。

显然,之所以会发生这种情况,是因为包含该函数的文件/wp-includes/plugable直到加载插件之后才被加载。确实如此。因此,在函数中包装您正在做的任何事情,并将其挂接到plugins_loaded或init钩子上。(请参阅wp-settings.php文件)

我在哪里写add_action('plugins_loaded','my_function');命令在"wp-settings file"、"plugable"还是我自己的php文件中?我只想在一个php文件中显示用户信息,该文件加载在wordpress的页面中,但我经常收到同样的错误"调用未定义的函数"。我已经尝试过包含相关的php文件,但仍然不起作用。

 <?php 
 global $current_user;
 get_currentuserinfo();
 echo $current_user->user_login;
 ?>

这可能对您有用!!

require (ABSPATH . WPINC . '/pluggable.php');
global $current_user;
get_currentuserinfo();
echo $current_user->user_login;

您所要做的就是在插件中包含plugble.php文件。