BP_Messages_Thread::update_tables()

Upgrade method for the older BP message thread DB table.

Description

Return

(bool)

Source

File: bp-messages/classes/class-bp-messages-thread.php

1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
public static function update_tables() {
    global $wpdb;
 
    $bp_prefix = bp_core_get_table_prefix();
    $errors    = false;
    $threads   = $wpdb->get_results( "SELECT * FROM {$bp_prefix}bp_messages_threads" );
 
    // Nothing to update, just return true to remove the table.
    if ( empty( $threads ) ) {
        return true;
    }
 
    $bp = buddypress();
 
    foreach( (array) $threads as $thread ) {
        $message_ids = maybe_unserialize( $thread->message_ids );
 
        if ( ! empty( $message_ids ) ) {
            $message_ids = implode( ',', $message_ids );
 
            // Add the thread_id to the messages table.
            if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id ) ) ) {
                $errors = true;
            }
        }
    }
 
    return (bool) ! $errors;
}

Changelog

Changelog
Version Description
BuddyPress 1.2.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.