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

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.