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

Remove a user id from an object


Description Description


Parameters Parameters

$object_id

(Required) The object id

$user_id

(Required) The user id

$meta_key

(Optional) The relationship key

Default value: ''

$meta_type

(Optional) The relationship type (usually 'post')

Default value: 'post'


Top ↑

Return Return

(bool) Returns true on success, false on failure


Top ↑

Source Source

File: includes/common/engagements.php

	public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
		$retval     = false;
		$option_key = $this->get_user_option_key( $meta_key, $object_id );
		$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
		$exists     = array_search( $object_id, $object_ids );

		// Exists, so remove it
		if ( false !== $exists ) {
			unset( $object_ids[ $exists ] );

			$object_ids = implode( ',', $this->parse_comma_list( $object_ids ) );
			$retval     = ! empty( $object_ids )
				? update_user_option( $user_id, $option_key, $object_ids )
				: delete_user_option( $user_id, $option_key );

			// Delete cache if successful (accounts for int & true)
			if ( false !== $retval ) {
				$this->cache_delete( $meta_key, $object_id );
			}
		}

		// Return true if removed, or false if not
		return $retval;
	}

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.