获取当前用户的ID
原型
get_current_user_id()
返回值
(int)
当前用户的ID,如果没有用户登录则为0。
源文件
路径:wp-includes/user.php
<?php
...
function get_current_user_id() {
if ( ! function_exists( 'wp_get_current_user' ) )
return 0;
$user = wp_get_current_user();
return ( isset( $user->ID ) ? (int) $user->ID : 0 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_current_user_id/