better_messages_before_message_send
REQUIREMENTS
To be able to implement this guide, you need to learn how to insert PHP snippets to your website.
You can find guide here: WP Beginner
Compatibility
This action compatible with Better Messages 2.0.64 or higher
This action allows to prevent message sending based on custom conditions.
This action only prevent new replies, to restrict new conversations use better_messages_before_new_thread
add_action( 'better_messages_before_message_send', 'custom_before_message_send', 20, 2 );
function custom_before_message_send( &$args, &$errors ){
// Sender User ID
$sender_id = (isset($args['sender_id'])) ? $args['sender_id'] : get_current_user_id();
// Message Content
$content = $args['content'];
// Conversation ID
$thread_id = $args['thread_id'];
$user_allowed_to_send = false;
if( ! $user_allowed_to_send ){
// Add new error to errors array. It will be displayed to user with error popup
$errors['my_custom_error_message'] = 'You are not allowed to send this';
}
}