wordpress插件->调用未定义的函数wp_get_current_user() [英] wordpress plugin -> Call to undefined function wp_get_current_user()

查看:67
本文介绍了wordpress插件->调用未定义的函数wp_get_current_user()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用func wp_get_current_user()在插件中获取当前用户信息.但是越来越 Call to undefined function wp_get_current_user()

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()

显然是因为包含该函数的文件/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.

有人知道如何在我的插件中获取用户详细信息吗?

Anybody any ideas on how to get the user details in my plugin?

推荐答案

显然是因为包含插件的功能的文件/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钩上. (请参阅wp-settings.php文件)

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)

示例:

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

这篇关于wordpress插件->调用未定义的函数wp_get_current_user()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆