更新时间:2023-11-30 23:11:46
显然这是因为包含该函数的文件/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();
// ...
}