bp_admin_invitations_table()

Create the invitations database table if it does not exist.

Description

Migrate outstanding group invitations if needed.

Return

(array)

Source

File: bp-core/admin/bp-core-admin-tools.php

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
function bp_admin_invitations_table() {
    global $wpdb;
 
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 
    /* translators: %s: the result of the action performed by the repair tool */
    $statement = __( 'Creating the Invitations database table if it does not exist… %s', 'buddyboss' );
    $result    = __( 'Failed to create table!', 'buddyboss' );
 
    bp_core_install_invitations();
 
    // Check for existence of invitations table.
    $table_name = BP_Invitation_Manager::get_table_name();
    $query      = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
    if ( ! $wpdb->get_var( $query ) == $table_name ) {
        return array(
            'status'  => 2,
            'message' => sprintf( $statement, $result ),
        );
    } else {
        $result = __( 'Created invitations table!', 'buddyboss' );
    }
 
    // Migrate group invitations if needed.
    if ( bp_is_active( 'groups' ) ) {
        $bp = buddypress();
 
        /* translators: %s: the result of the action performed by the repair tool */
        $migrate_statement = __( 'Migrating group invitations… %s', 'buddyboss' );
        $migrate_result    = __( 'Failed to migrate invitations!', 'buddyboss' );
 
        bp_groups_migrate_invitations();
 
        // Check that there are no outstanding group invites in the group_members table.
        $records = $wpdb->get_results( "SELECT id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 0 AND is_banned = 0" );
        if ( empty( $records ) ) {
            $migrate_result = __( 'Migrated invitations!', 'buddyboss' );
 
            return array(
                'status'  => 0,
                'message' => sprintf( $statement . ' ' . $migrate_statement, $result, $migrate_result ),
            );
        } else {
            return array(
                'status'  => 2,
                'message' => sprintf( $statement . ' ' . $migrate_statement, $result, $migrate_result ),
            );
        }
    }
 
    // Return a "create-only" success message.
    return array(
        'status'  => 0,
        'message' => sprintf( $statement, $result ),
    );
}

Changelog

Changelog
Version Description
BuddyBoss 1.3.5 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.