get_current_user_id

函式
get_current_user_id ( No parameters )
返回值
  • (int) The current user's ID, or 0 if no user is logged in.
定義位置
相關方法
set_current_userwp_get_current_userget_currentuserinfoget_current_network_id_wp_get_current_user
引入
-
棄用
-

get_current_user_id是一個WordPress函式,用於獲取當前登入使用者的id: 此函式不接受任何引數,只返回當前在WordPress系統中驗證的使用者的ID。

獲取當前使用者的ID。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >