is_user_logged_in

函式
is_user_logged_in ( No parameters )
返回值
  • (bool) True if user is logged in, false if not logged in.
定義位置
相關方法
is_user_adminis_super_adminwp_ajax_logged_inis_serialized_stringis_login
引入
2.0.0
棄用
-

is_user_logged_in是一個WordPress函式,用來檢查當前使用者是否已經登入。如果使用者已經登入,它返回一個布林值true,否則返回false。

判斷當前訪問者是否為登入使用者。

關於這個和類似主題函式的更多資訊,請檢視《主題開發者手冊》中的{@link Conditional Tags}文章。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function is_user_logged_in() {
$user = wp_get_current_user();
return $user->exists();
}
endif;
if ( ! function_exists( 'auth_redirect' ) ) :
/**
* Checks if a user is logged in, if not it redirects them to the login page.
*
* When this code is called from a page, it checks to see if the user viewing the page is logged in.
* If the user is not logged in, they are redirected to the login page. The user is redirected
* in such a way that, upon logging in, they will be sent directly to the page they were originally
* trying to access.
*
* @since 1.5.0
*/
function is_user_logged_in() { $user = wp_get_current_user(); return $user->exists(); } endif; if ( ! function_exists( 'auth_redirect' ) ) : /** * Checks if a user is logged in, if not it redirects them to the login page. * * When this code is called from a page, it checks to see if the user viewing the page is logged in. * If the user is not logged in, they are redirected to the login page. The user is redirected * in such a way that, upon logging in, they will be sent directly to the page they were originally * trying to access. * * @since 1.5.0 */
function is_user_logged_in() {
		$user = wp_get_current_user();

		return $user->exists();
	}
endif;

if ( ! function_exists( 'auth_redirect' ) ) :
	/**
	 * Checks if a user is logged in, if not it redirects them to the login page.
	 *
	 * When this code is called from a page, it checks to see if the user viewing the page is logged in.
	 * If the user is not logged in, they are redirected to the login page. The user is redirected
	 * in such a way that, upon logging in, they will be sent directly to the page they were originally
	 * trying to access.
	 *
	 * @since 1.5.0
	 */

常見問題

FAQs
檢視更多 >