[英]How To Get Wordpress User ID From External PHP Script?
I'm trying to validate WooCommerce subscriptions and I need the userid to do it but it keeps returning 0 from $current_user->ID. 我正在尝试验证WooCommerce订阅,我需要userid来执行它,但是它一直从$ current_user-> ID返回0。
<?php
include('../wp-load.php');
$current_user = wp_get_current_user();
$SubCheck = WC_Subscriptions_Manager::user_has_subscription( $current_user->ID, 9, 'active' );
?>
thy this... 你这个...
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
Try this way, why $current_user->ID 尝试这种方式, 为什么$ current_user-> ID
<?php $user_ID = get_current_user_id(); ?>
Returns (int)
The user's ID, if there is a current user; otherwise 0.
SEE: http://codex.wordpress.org/Function_Reference/get_current_user_id 查看: http : //codex.wordpress.org/Function_Reference/get_current_user_id
EDIT: 编辑:
<?php
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
} else {
// Logged in.
}
?>
EDIT2: 编辑2:
<?php global $current_user;
get_currentuserinfo();
echo 'User ID: ' . $current_user->ID;
?>
OR 要么
<?php
global $current_user;
$current_user = wp_get_current_user();
$current_user->ID
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.