Route messages to admin for featured jobs

Hi! I need to route the message to the administrator for all featured listings instead of the listing author, it’s related to featured jobs to be exact - JobHive theme.

Talked to customer support, told me you can give me a PHP snippet that does that. I’ll need instructions on how to use it too :smiley:

Hi,

Sorry for the delay. Our developer will answer you within 24 hours or less.

Please try this code snippet, replace 123 with the admin user ID. It routes messages sent via the featured listings to the site admin (both the message and email notification):

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

		$listing = $message->get_listing();

		if ( ! $listing || ! $listing->is_featured() ) {
			return $errors;
		}

		$message->set_recipient( 123 );

		return $errors;
	},
	10,
	2
);

add_filter(
	'hivepress/v1/emails/message_send',
	function( $email ) {
		$message = isset( $email['tokens']['message'] ) ? $email['tokens']['message'] : null;

		if ( ! $message || ! $message->get_listing__id() ) {
			return $email;
		}

		$listing = $message->get_listing();

		if ( ! $listing || ! $listing->is_featured() ) {
			return $email;
		}

		$email['recipient'] = get_option( 'admin_email' );

		return $email;
	}
);

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