BBP_User_Engagements_User::get_users_for_object( int $object_id, string $meta_key = '', string $meta_type = 'post' )

Get users of an object


Description Description

The database queries in this function were cached in bbPress versions older than 2.6, but no longer are to avoid cache pollution.


Parameters Parameters

$object_id

(Required) The object id

$meta_key

(Optional) The key used to index this relationship

Default value: ''

$meta_type

(Optional) The type of meta to look in

Default value: 'post'


Top ↑

Return Return

(array) Returns ids of users


Top ↑

Source Source

File: includes/common/engagements.php

	public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {

		// Try to get user IDs from cache
		$user_ids = $this->cache_get( $meta_key, $object_id );

		// Cache is empty, so hit the database
		if ( false === $user_ids ) {
			$option_key = $this->get_user_option_key( $meta_key, $object_id, true );
			$bbp_db     = bbp_db();
			$user_ids   = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$option_key}' and FIND_IN_SET('{$object_id}', meta_value) > 0" );

			// Always cache results (even if empty, to prevent multiple misses)
			$this->cache_set( $meta_key, $object_id, $user_ids );
		}

		// Return parsed IDs
		return $this->parse_comma_list( $user_ids );
	}

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.