bp_messages_admin_repair_unread_messages_count()

Repair unread messages count.

Description

Source

File: bp-messages/bp-messages-filters.php

680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
function bp_messages_admin_repair_unread_messages_count() {
    global $wpdb;
 
    $offset           = isset( $_POST['offset'] ) ? (int) ( $_POST['offset'] ) : 0;
    $bp               = buddypress();
    $recipients_query = "SELECT DISTINCT thread_id FROM {$bp->messages->table_name_recipients} LIMIT 50 OFFSET $offset ";
    $recipients       = $wpdb->get_results( $recipients_query );
 
    if ( ! empty( $recipients ) ) {
        foreach ( $recipients as $recipient ) {
            $thread_id = (int) $recipient->thread_id;
            if ( ! empty( $thread_id ) ) {
                $is_valid = messages_is_valid_thread( $thread_id );
                if ( empty( $is_valid ) ) {
                    messages_delete_thread( $thread_id, bp_loggedin_user_id() );
                }
            }
            $offset ++;
        }
        $records_updated = sprintf( __( '%s thread updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );
 
        return array(
            'status'  => 'running',
            'offset'  => $offset,
            'records' => $records_updated,
        );
    } else {
        return array(
            'status'  => 1,
            'message' => __( 'thread update complete!', 'buddyboss' ),
        );
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.5.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.