bp_core_install_extended_profiles()

Install database tables for the Profiles component.


Description Description


Source Source

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

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
function bp_core_install_extended_profiles() {
    global $wpdb;
 
    $sql             = array();
    $charset_collate = $GLOBALS['wpdb']->get_charset_collate();
    $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', _x( 'General', 'First field-group name', 'buddypress' ) );
    }
 
    if ( ! bp_get_option( 'bp-xprofile-fullname-field-name' ) ) {
        bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Display Name', 'Display name field', 'buddypress' ) );
    }
 
    $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
                id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
                name varchar(150) NOT NULL,
                description mediumtext NOT NULL,
                group_order bigint(20) NOT NULL DEFAULT '0',
                can_delete tinyint(1) NOT NULL,
                KEY can_delete (can_delete)
            ) {$charset_collate};";
 
    $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
                id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
                group_id bigint(20) unsigned NOT NULL,
                parent_id bigint(20) unsigned NOT NULL,
                type varchar(150) NOT NULL,
                name varchar(150) NOT NULL,
                description longtext NOT NULL,
                is_required tinyint(1) NOT NULL DEFAULT '0',
                is_default_option tinyint(1) NOT NULL DEFAULT '0',
                field_order bigint(20) NOT NULL DEFAULT '0',
                option_order bigint(20) NOT NULL DEFAULT '0',
                order_by varchar(15) NOT NULL DEFAULT '',
                can_delete tinyint(1) NOT NULL DEFAULT '1',
                KEY group_id (group_id),
                KEY parent_id (parent_id),
                KEY field_order (field_order),
                KEY can_delete (can_delete),
                KEY is_required (is_required)
            ) {$charset_collate};";
 
    $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
                id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
                field_id bigint(20) unsigned NOT NULL,
                user_id bigint(20) unsigned NOT NULL,
                value longtext NOT NULL,
                last_updated datetime NOT NULL,
                KEY field_id (field_id),
                KEY user_id (user_id)
            ) {$charset_collate};";
 
    $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
                object_id bigint(20) NOT NULL,
                object_type varchar(150) NOT NULL,
                meta_key varchar(255) DEFAULT NULL,
                meta_value longtext DEFAULT NULL,
                KEY object_id (object_id),
                KEY meta_key (meta_key(191))
            ) {$charset_collate};";
 
    dbDelta( $sql );
 
    // Insert the default group and fields.
    $insert_sql = array();
 
    if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) ) {
        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
    }
 
    if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) ) {
        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
 
        // Make sure the custom visibility is disabled for the default field.
        if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_meta WHERE id = 1" ) ) {
            $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_meta ( object_id, object_type, meta_key, meta_value ) VALUES ( 1, 'field', 'allow_custom_visibility', 'disabled' );";
        }
    }
 
    dbDelta( $insert_sql );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.