简体   繁体   English

Wordpress:无法使用户登录

[英]Wordpress: unable to get the user logged in

The header.php in my project includes at the very beginning a php file with content like this: 我项目中的header.php一开始就包含一个php文件,其内容如下:

global $profile;
global $user;

if(is_user_logged_in()){
global $current_user;   
get_currentuserinfo();
$user = array();
$user['username'] = $current_user->user_login;
$user['email'] = $current_user->user_email;
.
.
}

On my page template file I am trying to get info from this user object, through the following code 在我的页面模板文件中,我试图通过以下代码从该用户对象获取信息

$.ajax({ url: path + '/gmail/user.php',
         type: 'post',
         success: function(status) {alert(status);} }
    });

which is calling 正在呼叫

<?php
print_r($user);
?>

and I get an empty alert. 我得到一个空警报。 I get this whether I log in or not. 无论我是否登录,都会收到此消息。 Why could this happen? 为什么会发生这种情况? Is there another solution to picking up the logged in user? 还有另一种解决方案来接住已登录的用户吗? maybe with sql? 也许与SQL?

on using the following code in the php file: 在php文件中使用以下代码:

global $current_user;  
get_currentuserinfo();
print_r($current_user);

I get call to undefined function error 我收到未定义函数错误的调用

Try put your code calling 尝试将您的代码调用

global $current_user;  
get_currentuserinfo();

After wp_head() call in the header. 在wp_head()之后,在标题中调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM