cache_users()WP 3.0.0

Retrieves info for user lists to prevent multiple queries by get_userdata().

Pluggable function — this function can be replaced from a plugin. It means that this function is defined (works) only after all plugins are loaded (included), but before this moment this function has not defined. Therefore, you cannot call this and all functions depended on this function directly from a plugin code. They need to be called on plugins_loaded hook or later, for example on init hook.

Function replacement (override) — in must-use or regular plugin you can create a function with the same name, then it will replace this function.

No Hooks.

Return

null. Nothing (null).

Usage

cache_users( $user_ids );
$user_ids(int[]) (required)
User ID numbers list

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.0.0 Introduced.

cache_users() code WP 6.5.2

function cache_users( $user_ids ) {
	global $wpdb;

	update_meta_cache( 'user', $user_ids );

	$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)" );

	foreach ( $users as $user ) {
		update_user_caches( $user );
	}
}