[ad_1]
add_action( 'better_messages_before_new_thread', 'custom_restrict_new_thread', 10, 2 );
function custom_restrict_new_thread( &$args, &$errors ){
// User who creating thread
$user_id = get_current_user_id();
// Get array with recipients user ids, which user trying to start conversation with
$recipients = $args['recipients'];
/**
* Your logic to determine if this user can create thread
*/
if($user_id=1){ // limit this userid 1
if($total_numberof_conversations>3){
$can_create_thread = false;
}else{
$can_create_thread = true;
}
}else{ // other users can create new thread
$can_create_thread = true;
}
if( ! $can_create_thread ){
/**
* Adding error which will be shown to user
*/
$errors['uniqueErrorSlug'] = 'You cant start new thread now.';
}
}I need a function that output $total_numberof_conversations for the current user, can you advice? thank you very much.
