set_current_user

函式
set_current_user ( $id, $name = '' )
引數
  • (int|null) $id User ID.
    Required:
  • (string) $name Optional. The user's username
    Required:
    Default: (empty)
返回值
  • (WP_User) returns wp_set_current_user()
相關
  • wp_set_current_user()
定義位置
相關方法
wp_set_current_userwp_get_current_userget_current_user_id_wp_get_current_userset_current_screen
引入
2.0.1
棄用
3.0.0

set_current_user: 這是一個WordPress的函式,用來設定當前的使用者物件。它通常用於以程式設計方式登入或登出一個使用者,或者切換到另一個使用者賬戶: 這個函式需要一個引數,它是要被設定為當前使用者的使用者ID或使用者物件。

通過ID或名字改變當前使用者。

如果你不知道一個使用者的ID,將$id設定為null,並指定一個名字。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function set_current_user($id, $name = '') {
_deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' );
return wp_set_current_user($id, $name);
}
function set_current_user($id, $name = '') { _deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' ); return wp_set_current_user($id, $name); }
function set_current_user($id, $name = '') {
	_deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' );
	return wp_set_current_user($id, $name);
}

常見問題

FAQs
檢視更多 >