bp_core_install_extended_profiles

Install database tables for the Profiles component.

Description

bp_core_install_extended_profiles(); 

Usage

  1. if ( !function_exists( 'bp_core_install_extended_profiles' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/admin/bp-core-admin-schema.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_install_extended_profiles(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/admin/bp-core-admin-schema.php  
  1. function bp_core_install_extended_profiles() { 
  2. global $wpdb; 
  3.  
  4. $sql = array(); 
  5. $charset_collate = $GLOBALS['wpdb']->get_charset_collate(); 
  6. $bp_prefix = bp_core_get_table_prefix(); 
  7.  
  8. // These values should only be updated if they are not already present. 
  9. if ( ! bp_get_option( 'bp-xprofile-base-group-name' ) ) { 
  10. bp_update_option( 'bp-xprofile-base-group-name', _x( 'General', 'First field-group name', buddypress ) ); 
  11.  
  12. if ( ! bp_get_option( 'bp-xprofile-fullname-field-name' ) ) { 
  13. bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Display Name', 'Display name field', buddypress ) ); 
  14.  
  15. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups ( 
  16. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,  
  17. name varchar(150) NOT NULL,  
  18. description mediumtext NOT NULL,  
  19. group_order bigint(20) NOT NULL DEFAULT '0',  
  20. can_delete tinyint(1) NOT NULL,  
  21. KEY can_delete (can_delete) 
  22. ) {$charset_collate};"; 
  23.  
  24. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields ( 
  25. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,  
  26. group_id bigint(20) unsigned NOT NULL,  
  27. parent_id bigint(20) unsigned NOT NULL,  
  28. type varchar(150) NOT NULL,  
  29. name varchar(150) NOT NULL,  
  30. description longtext NOT NULL,  
  31. is_required tinyint(1) NOT NULL DEFAULT '0',  
  32. is_default_option tinyint(1) NOT NULL DEFAULT '0',  
  33. field_order bigint(20) NOT NULL DEFAULT '0',  
  34. option_order bigint(20) NOT NULL DEFAULT '0',  
  35. order_by varchar(15) NOT NULL DEFAULT '',  
  36. can_delete tinyint(1) NOT NULL DEFAULT '1',  
  37. KEY group_id (group_id),  
  38. KEY parent_id (parent_id),  
  39. KEY field_order (field_order),  
  40. KEY can_delete (can_delete),  
  41. KEY is_required (is_required) 
  42. ) {$charset_collate};"; 
  43.  
  44. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data ( 
  45. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,  
  46. field_id bigint(20) unsigned NOT NULL,  
  47. user_id bigint(20) unsigned NOT NULL,  
  48. value longtext NOT NULL,  
  49. last_updated datetime NOT NULL,  
  50. KEY field_id (field_id),  
  51. KEY user_id (user_id) 
  52. ) {$charset_collate};"; 
  53.  
  54. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta ( 
  55. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,  
  56. object_id bigint(20) NOT NULL,  
  57. object_type varchar(150) NOT NULL,  
  58. meta_key varchar(255) DEFAULT NULL,  
  59. meta_value longtext DEFAULT NULL,  
  60. KEY object_id (object_id),  
  61. KEY meta_key (meta_key(191)) 
  62. ) {$charset_collate};"; 
  63.  
  64. dbDelta( $sql ); 
  65.  
  66. // Insert the default group and fields. 
  67. $insert_sql = array(); 
  68.  
  69. if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) ) { 
  70. $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 );"; 
  71.  
  72. if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) ) { 
  73. $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 );"; 
  74.  
  75. dbDelta( $insert_sql );