Wordpress&;PHP-get_currentuserinfo();
我已经搜索到互联网的尽头,似乎找不到任何对我的问题有帮助的东西。我有一个wordpress站点(继承的),我只是希望能够在用户登录时获得他们的信息。从我看到的文档中可以使用get_currentuserinfo(),但当我尝试使用它时,却一无所获 该文件位于我的主html目录中的一个文件夹中。内容如下:Wordpress&;PHP-get_currentuserinfo();,php,wordpress,Php,Wordpress,我已经搜索到互联网的尽头,似乎找不到任何对我的问题有帮助的东西。我有一个wordpress站点(继承的),我只是希望能够在用户登录时获得他们的信息。从我看到的文档中可以使用get_currentuserinfo(),但当我尝试使用它时,却一无所获 该文件位于我的主html目录中的一个文件夹中。内容如下: <?php include_once("../wp-includes/pluggable.php"); global $current_user; get_currentuse
<?php
include_once("../wp-includes/pluggable.php");
global $current_user;
get_currentuserinfo();
echo $current_user->user_login;
?>
我真的要为这件事发疯了。我还需要在顶部添加其他内容吗?我必须在wordpress中创建页面吗?您必须包含
wp load.php
才能在wordpress之外的php文件中使用wordpress函数
require_once("/path/to/wordpress/wp-load.php");
global $current_user;
get_currentuserinfo();
echo $current_user->user_login;
注意:如果在加载插件时调用get_currentuserinfo(),则该函数将不起作用,因为它尚未定义。该特定函数是在pluggable.php中定义的,它在插件加载之后加载。所以你的问题可能就在这里。所以请检查你的pluggable.php
您还可以使用“wp_get_current_user();”代替“get_currentuserinfo();”。下面介绍了使用“wp_get_current_user();”的方法
我似乎没有“wp load.php”文件。我能找到这个并把它添加到任何地方吗?我终于找到了这个文件,现在一切都正常了。谢谢你,迪内什!
<?php
$current_user = wp_get_current_user();
/**
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
* return;
*/
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
?>