bp_core_install_default_profiles_fields()

Install default profile fields.

Description

Source

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

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
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.