get_current_user_id()返回零0 [英] get_current_user_id() returning Zero 0
问题描述
get_current_user_id()
对于以下代码返回0。我确实尝试了一些在堆栈溢出时可用的解决方案,但不知怎么对我不起作用。我期待解释为什么它返回零以及如何解决?
get_current_user_id()
is returning 0 for following codes. I do tried some solution available on stack overflow but somehow not working for me. I'm expecting explanation why its returning zero and how to fix?
PS:我从外部php页面调用get_current_user_id()并包含 '../ wp-blog-header.php'
。
P.S: I'm calling get_current_user_id() from external php page and included '../wp-blog-header.php'
for that.
代码:
<?php
require('../wp-blog-header.php');
get_header();
$user_ID = get_current_user_id();
echo $user_ID;
?>
推荐答案
您必须调用用户身份验证的wordpress过程。尝试在 get_current_user_id();
之前添加以下代码,如果不能解决您的问题,则至少会为您指明正确的方向:
You have to call wordpress proccess of user authentication. Try adding the following code before get_current_user_id();
, if it doesn't solve your problem it'll at least point you the right direction:
$user_id = apply_filters( 'determine_current_user', false );
wp_set_current_user( $user_id );
希望有帮助!
这篇关于get_current_user_id()返回零0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!