bp_core_install_default_profiles_fields()

Install default profile fields.

Description

Source

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

function bp_core_install_default_profiles_fields() {
	global $wpdb;

	$bp_prefix       = bp_core_get_table_prefix();

	// These values should only be updated if they are not already present.
	if ( ! bp_get_option( 'bp-xprofile-base-group-name' ) ) {
		bp_update_option( 'bp-xprofile-base-group-name', __( 'General', 'buddyboss' ) );
	}

	if ( ! bp_get_option( 'bp-xprofile-firstname-field-name' ) ) {
		bp_update_option( 'bp-xprofile-firstname-field-name', __( 'First Name', 'buddyboss' ) );
	}

	if ( ! bp_get_option( 'bp-xprofile-lastname-field-name' ) ) {
		bp_update_option( 'bp-xprofile-lastname-field-name', __( 'Last Name', 'buddyboss' ) );
	}

	if ( ! bp_get_option( 'bp-xprofile-nickname-field-name' ) ) {
		bp_update_option( 'bp-xprofile-nickname-field-name', __( 'Nickname', 'buddyboss' ) );
	}

	// Insert the default group and fields.
	$insert_sql = array();

	$base_group_id = (int) bp_get_option( 'bp-xprofile-base-group-id', 1 );
	if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = {$base_group_id}" ) ) {

		$re = $wpdb->insert( "{$bp_prefix}bp_xprofile_groups", [
			'name'        => bp_get_option( 'bp-xprofile-base-group-name' ),
			'description' => '',
			'can_delete'  => 0,
		] );

		$base_group_id = $wpdb->insert_id;
		bp_update_option( 'bp-xprofile-base-group-id', $base_group_id );
	}

	// First name
	$first_name_id = (int) bp_get_option( 'bp-xprofile-firstname-field-id', 1 );
	if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = {$first_name_id}" ) ) {

		$re = $wpdb->insert( "{$bp_prefix}bp_xprofile_fields", [
			'group_id'    => $base_group_id,
			'parent_id'   => 0,
			'type'        => 'textbox',
			'name'        => bp_get_option( 'bp-xprofile-firstname-field-name' ),
			'description' => '',
			'is_required' => 1,
			'can_delete'  => 0,
		] );

		bp_update_option( 'bp-xprofile-firstname-field-id', $wpdb->insert_id );
	}

	// Last name
	$last_name_id = (int) bp_get_option( 'bp-xprofile-lastname-field-id' );
	if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = {$last_name_id}" ) ) {

		$re = $wpdb->insert( "{$bp_prefix}bp_xprofile_fields", [
			'group_id'    => $base_group_id,
			'parent_id'   => 0,
			'type'        => 'textbox',
			'name'        => bp_get_option( 'bp-xprofile-lastname-field-name' ),
			'description' => '',
			'is_required' => 1,
			'can_delete'  => 0,
		] );

		bp_update_option( 'bp-xprofile-lastname-field-id', $wpdb->insert_id );
	}

	// Nickname
	$nickname_id = (int) bp_get_option( 'bp-xprofile-nickname-field-id' );
	if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = {$nickname_id}" ) ) {

		$re = $wpdb->insert( "{$bp_prefix}bp_xprofile_fields", [
			'group_id'    => $base_group_id,
			'parent_id'   => 0,
			'type'        => 'textbox',
			'name'        => bp_get_option( 'bp-xprofile-nickname-field-name' ),
			'description' => '',
			'is_required' => 1,
			'can_delete'  => 0,
		] );

		bp_update_option( 'bp-xprofile-nickname-field-id', $wpdb->insert_id );
	}
}

Changelog

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