Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wp当前用户->;在自定义php文件中返回ID=0的ID_Php_Wordpress - Fatal编程技术网

wp当前用户->;在自定义php文件中返回ID=0的ID

wp当前用户->;在自定义php文件中返回ID=0的ID,php,wordpress,Php,Wordpress,在wordpress中,我正在编写一个自定义php文件,如下所示 require_once (ABSPATH.'/wp-includes/pluggable.php'); require_once(ABSPATH.'/wp-load.php'); global $current_user; echo 'ID= ' . $current_user->ID . '<br />'; #CUSTOM php CODE require_once(ABSPATH./wp includes

在wordpress中,我正在编写一个自定义php文件,如下所示

require_once (ABSPATH.'/wp-includes/pluggable.php');
require_once(ABSPATH.'/wp-load.php');
global $current_user;
echo 'ID= ' . $current_user->ID . '<br />';
#CUSTOM php CODE
require_once(ABSPATH./wp includes/pluggable.php');
需要_一次(ABSPATH./wp load.php');
全局$当前用户;
回显“ID=”$当前用户->ID'
; #自定义php代码
这段代码不在我的functions.php文件中,而是在[custom].php文件中,我需要这些信息来帮助加载/更新一些非WP数据库项


我的代码中的回显行上总是得到ID=0。我读过这篇文章,它与WP init操作的运行时间有关。但是,我不知道如何在自定义php文件中寻址。有什么建议吗?

如果错过了功能,请尝试此功能

调用get_currentuserinfo()将当前用户的信息放入$userdata中,在那里可以使用成员变量检索该信息

<?php global $current_user;
  get_currentuserinfo();

  echo 'Username: ' . $current_user->user_login . "\n";
  echo 'User email: ' . $current_user->user_email . "\n";
  echo 'User level: ' . $current_user->user_level . "\n";
  echo 'User first name: ' . $current_user->user_firstname . "\n";
  echo 'User last name: ' . $current_user->user_lastname . "\n";
  echo 'User display name: ' . $current_user->display_name . "\n";
  echo 'User ID: ' . $current_user->ID . "\n";
?>


请参阅

谢谢您的输入。我刚刚尝试了添加main函数的几种变体(包括链接引用中的内容),但是所有用户infor都是空的。还有其他建议吗?@tjp在WordPress中包含自定义PHP文件的路径。在我的自定义PHP文件中,我只包含我的原始帖子中列出的两个路径,即pluggable.PHP和wp-load.PHP。是否有其他路径需要我呼叫?