Advertisements

cache_users

Definition:
function cache_users( $user_ids ) {}

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

Parameters

  • array $user_ids: User ID numbers list

Source code

function cache_users( $user_ids ) {

	global $wpdb;



	$clean = array();

	foreach ( $user_ids as $id ) {

		$id = (int) $id;

		if ( !wp_cache_get( $id, 'users' ) ) {

			$clean[] = $id;

		}

	}



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

}

577

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: