update_user_caches

函式
update_user_caches ( $user )
引數
  • (object|WP_User) $user User object or database row to be cached
    Required:
返回值
  • (void|false) Void on success, false on failure.
定義位置
相關方法
update_term_cacheupdate_site_cacheupdate_post_cachesupdate_post_cacheupdate_page_cache
引入
3.0.0
棄用
-

update_user_caches: 這個函式更新一個使用者的資料的快取。它通常在一個使用者的資料被更新後被呼叫,比如當一個使用者的角色被改變時。

更新所有使用者快取。

function update_user_caches( $user ) {
	if ( $user instanceof WP_User ) {
		if ( ! $user->exists() ) {
			return false;
		}

		$user = $user->data;
	}

	wp_cache_add( $user->ID, $user, 'users' );
	wp_cache_add( $user->user_login, $user->ID, 'userlogins' );
	wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' );

	if ( ! empty( $user->user_email ) ) {
		wp_cache_add( $user->user_email, $user->ID, 'useremail' );
	}
}

常見問題

FAQs
檢視更多 >