clean_user_cache

函数
clean_user_cache ( $user )
参数
  • (WP_User|int) $user User object or ID to be cleaned from the cache
    Required:
定义位置
相关方法
clean_term_cacheclean_post_cacheclean_page_cacheclean_network_cacheclean_category_cache
引入
3.0.0
弃用
-

clean_user_cache: 这个函数用于清除用户的缓存: 当这个函数被调用时,它清除了所有用户数据的缓存。

清理所有用户缓存。

function clean_user_cache( $user ) {
	if ( is_numeric( $user ) ) {
		$user = new WP_User( $user );
	}

	if ( ! $user->exists() ) {
		return;
	}

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

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

	/**
	 * Fires immediately after the given user's cache is cleaned.
	 *
	 * @since 4.4.0
	 *
	 * @param int     $user_id User ID.
	 * @param WP_User $user    User object.
	 */
	do_action( 'clean_user_cache', $user->ID, $user );
}

常见问题

FAQs
查看更多 >