Function that get the total number of conversations for the current user

[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.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer