检索用户列表的信息以防止get_userdata()进行多次查询

原型

cache_users( array $user_ids )

参数

$user_ids (array) (Required) 用户ID号列表

源文件

路径:wp-includes/pluggable.php

<?php
...
function cache_users( $user_ids ) {
	global $wpdb;
	$clean = _get_non_cached_ids( $user_ids, 'users' );
	if ( empty( $clean ) )
		return;
	$list = implode( ',', $clean );
	$users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
	$ids = array();
	foreach ( $users as $user ) {
		update_user_caches( $user );
		$ids[] = $user->ID;
	}
	update_meta_cache( 'user', $ids );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/cache_users/