bbp_get_email_addresses_from_user_ids( array $user_ids = array() )

Return an array of user email addresses from an array of user IDs


Description Description


Parameters Parameters

$user_ids

(Optional)

Default value: array()


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/common/functions.php

function bbp_get_email_addresses_from_user_ids( $user_ids = array() ) {

	// Default return value
	$retval = array();

	// Maximum number of users to get per database query
	$limit = apply_filters( 'bbp_get_users_chunk_limit', 100 );

	// Only do the work if there are user IDs to query for
	if ( ! empty( $user_ids ) ) {

		// Get total number of sets
		$steps = ceil( count( $user_ids ) / $limit );
		$range = array_map( 'intval', range( 1, $steps ) );

		// Loop through users
		foreach ( $range as $loop ) {

			// Initial loop has no offset
			$offset = ( 1 === $loop )
				? 0
				: $limit * $loop;

			// Calculate user IDs to include
			$loop_ids = array_slice( $user_ids, $offset, $limit );

			// Skip if something went wrong
			if ( empty( $loop_ids ) ) {
				continue;
			}

			// Call get_users() in a way that users are cached
			$loop_users = get_users( array(
				'blog_id' => 0,
				'fields'  => 'all_with_meta',
				'include' => $loop_ids
			) );

			// Pluck emails from users
			$loop_emails = wp_list_pluck( $loop_users, 'user_email' );

			// Clean-up memory, for big user sets
			unset( $loop_users );

			// Merge users into return value
			if ( ! empty( $loop_emails ) ) {
				$retval = array_merge( $retval, $loop_emails );
			}
		}

		// No duplicates
		$retval = bbp_get_unique_array_values( $retval );
	}

	// Filter & return
	return apply_filters( 'bbp_get_email_addresses_from_user_ids', $retval, $user_ids, $limit );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.