Completely block messages for specific plans

How can I block messaging access for both users and vendors completely. I want to create a membership plan that if user has this specific plan, don’t allow sending messages at all, even from previous interactions.

Thanks for your message — our team will reply shortly.

In the meantime, you can also get instant help from our AI Assistant, familiar with all the docs and solutions we’ve shared over the years.

Hi,
Please try using the code snippet below – it checks the message sender’s membership plans by ID and shows an error. You can replace 1, 2, 3 with plan IDs that should have messages disabled, also the error text is customizable.

add_filter(
	'hivepress/v1/models/message/errors',
	function( $errors, $message ) {
		if ( ! $message->get_sender__id() || user_can( $message->get_sender__id(), 'edit_others_posts' ) ) {
			return $errors;
		}

		$plan_ids = array_map(
			function( $membership ) {
				return $membership->get_plan__id();
			},
			\HivePress\Models\Membership::query()->filter(
				[
					'status' => 'publish',
					'user'   => $message->get_sender__id(),
				]
			)->get()->serialize()
		);

		if ( array_intersect( $plan_ids, [ 1, 2, 3 ] ) ) {
			$errors[] = 'error message here';
		}

		return $errors;
	},
	10,
	2
);

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.