我正在尝试使用 func wp_get_current_user() 在我的插件中获取当前用户信息。但我越来越
调用未定义函数 wp_get_current_user()
显然这是因为包含该函数的文件 /wp-includes/pluggable
直到插件加载后才会被加载。
有人对如何在我的插件中获取用户详细信息有任何想法吗?
最佳答案
Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn't get loaded until after the plugins are loaded.
确实如此。因此,将你正在做的任何事情都包装在一个函数中,并将其挂接到 plugins_loaded 或 init 钩子(Hook)上。 (参见 wp-settings.php 文件)
示例:
add_action('init','do_stuff');
function do_stuff(){
$current_user = wp_get_current_user();
// ...
}
关于php - wordpress 插件 -> 调用未定义的函数 wp_get_current_user(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127559/