wordpress 获取当前用户 [英] wordpress get current user

查看:33
本文介绍了wordpress 获取当前用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 wordpress 目录中有一个用于某些模板应用程序的目录

I have a directory inside my wordpress directory for some template application

apacheWWW/wordpress/jtpc 

在我的应用程序中,我想要 wordpress 当前用户 ID

In my application i want the wordpress current user id

我可以在一页中执行此操作,但在另一页中出现错误

I am able to do this in one page but in the other I get an error

这是我为获取用户 ID 所做的:

This is what I am doing to get the user id:

require_once( '/../../wp-load.php' );
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;

但我在这一行遇到错误

 require_once( '/../../wp-load.php' );

错误说

 File does not exist: D:/programming/apacheWWW/wordpress/jtpc/ajaxHandlers/wp-admin, referrer: http://localhost/wordpress/?page_id=23

他想要 wp-admin 的剂量,以及为什么他在错误的目录中寻找它,应该是在

what dose he wants with the wp-admin , and why he is looking for it in the wrong directory , It's suppose to be under

   D:/programming/apacheWWW/wordpress/

它适用于一个页面,(我正在上传文件并为此用户 ID 创建一个目录)

It's working for one page, (I am uploading file and creating a directory for this user id)

但是对于另一个页面,我发送了一个 ajax 请求以根据用户请求删除文件所以我需要再次识别,但他抛出了错误

but for the other page I send an ajax request to delete files by user request so I need to id again, but there he throws the error

推荐答案

ok got i work i put

ok got i working i put

  require_once( '/../../wp-load.php' );

在页面顶部而不是在函数内部

at the top of the page and not inside the function

这篇关于wordpress 获取当前用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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