| | 336 | /** |
| | 337 | * Create the invitations database table if it does not exist. |
| | 338 | * Migrate outstanding group invitations if needed. |
| | 339 | * |
| | 340 | * @since 6.0.0 |
| | 341 | * |
| | 342 | * @return array |
| | 343 | */ |
| | 344 | function bp_admin_invitations_table() { |
| | 345 | global $wpdb; |
| | 346 | |
| | 347 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| | 348 | require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' ); |
| | 349 | |
| | 350 | $statement = __( 'Creating the Invitations database table if it does not exist… %s', 'buddypress' ); |
| | 351 | $result = __( 'Failed to create table!', 'buddypress' ); |
| | 352 | |
| | 353 | bp_core_install_invitations(); |
| | 354 | |
| | 355 | // Check for existence of invitations table. |
| | 356 | $bp_prefix = bp_core_get_table_prefix(); |
| | 357 | $table_name = "{$bp_prefix}bp_invitations"; |
| | 358 | $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
| | 359 | if ( ! $wpdb->get_var( $query ) == $table_name ) { |
| | 360 | // Early return a "create-only" failure message. |
| | 361 | return array( 2, sprintf( $statement, $result ) ); |
| | 362 | } else { |
| | 363 | $result = __( 'Created invitations table!', 'buddypress' ); |
| | 364 | } |
| | 365 | |
| | 366 | // Migrate group invitations if needed. |
| | 367 | if ( bp_is_active( 'groups' ) ) { |
| | 368 | $bp = buddypress(); |
| | 369 | $migrate_statement = __( 'Migrating group invitations… %s', 'buddypress' ); |
| | 370 | $migrate_result = __( 'Failed to migrate invitations!', 'buddypress' ); |
| | 371 | |
| | 372 | bp_groups_migrate_invitations(); |
| | 373 | |
| | 374 | // Check that there are no outstanding group invites in the group_members table. |
| | 375 | $records = $wpdb->get_results( "SELECT id, group_id, user_id, inviter_id, date_modified, comments, invite_sent FROM {$bp->groups->table_name_members} WHERE is_confirmed = 0 AND is_banned = 0" ); |
| | 376 | if ( empty( $records ) ) { |
| | 377 | $migrate_result = __( 'Migrated invitations!', 'buddypress' ); |
| | 378 | return array( 0, sprintf( $statement . ' ' . $migrate_statement , $result, $migrate_result ) ); |
| | 379 | } else { |
| | 380 | return array( 2, sprintf( $statement . ' ' . $migrate_statement , $result, $migrate_result ) ); |
| | 381 | } |
| | 382 | } |
| | 383 | |
| | 384 | // Return a "create-only" success message. |
| | 385 | return array( 0, sprintf( $statement, $result ) ); |
| | 386 | } |
| | 387 | |