bp_core_get_root_options

Fetch global BP options.

Description

(array) bp_core_get_root_options(); 

BuddyPress uses common options to store configuration settings. Many of these settings are needed at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch them all in one go.

Returns (array)

$root_blog_options_meta List of options.


Usage

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

Defined (1)

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

/bp-core/bp-core-options.php  
  1. function bp_core_get_root_options() { 
  2. global $wpdb; 
  3.  
  4. // Get all the BuddyPress settings, and a few useful WP ones too. 
  5. $root_blog_options = bp_get_default_options(); 
  6. $root_blog_options['registration'] = '0'; 
  7. $root_blog_options['avatar_default'] = 'mysteryman'; 
  8. $root_blog_option_keys = array_keys( $root_blog_options ); 
  9.  
  10. // Do some magic to get all the root blog options in 1 swoop 
  11. // Check cache first - We cache here instead of using the standard WP 
  12. // settings cache because the current blog may not be the root blog,  
  13. // and it's not practical to access the cache across blogs. 
  14. $root_blog_options_meta = wp_cache_get( 'root_blog_options', 'bp' ); 
  15.  
  16. if ( false === $root_blog_options_meta ) { 
  17. $blog_options_keys = "'" . join( "', '", (array) $root_blog_option_keys ) . "'"; 
  18. $blog_options_table = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'options'; 
  19. $blog_options_query = "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )"; 
  20. $root_blog_options_meta = $wpdb->get_results( $blog_options_query ); 
  21.  
  22. // On Multisite installations, some options must always be fetched from sitemeta. 
  23. if ( is_multisite() ) { 
  24.  
  25. /** 
  26. * Filters multisite options retrieved from sitemeta. 
  27. * @since 1.5.0 
  28. * @param array $value Array of multisite options from sitemeta table. 
  29. */ 
  30. $network_options = apply_filters( 'bp_core_network_options', array( 
  31. 'tags_blog_id' => '0',  
  32. 'sitewide_tags_blog' => '',  
  33. 'registration' => '0',  
  34. 'fileupload_maxk' => '1500' 
  35. ) ); 
  36.  
  37. $current_site = get_current_site(); 
  38. $network_option_keys = array_keys( $network_options ); 
  39. $sitemeta_options_keys = "'" . join( "', '", (array) $network_option_keys ) . "'"; 
  40. $sitemeta_options_query = $wpdb->prepare( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id ); 
  41. $network_options_meta = $wpdb->get_results( $sitemeta_options_query ); 
  42.  
  43. // Sitemeta comes second in the merge, so that network 'registration' value wins. 
  44. $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta ); 
  45.  
  46. // Loop through our results and make them usable. 
  47. foreach ( $root_blog_options_meta as $root_blog_option ) { 
  48. $root_blog_options[$root_blog_option->name] = $root_blog_option->value; 
  49.  
  50. // Copy the options no the return val. 
  51. $root_blog_options_meta = $root_blog_options; 
  52.  
  53. // Clean up our temporary copy. 
  54. unset( $root_blog_options ); 
  55.  
  56. wp_cache_set( 'root_blog_options', $root_blog_options_meta, 'bp' ); 
  57.  
  58. /** 
  59. * Filters the global BP options. 
  60. * @since 1.5.0 
  61. * @param array $root_blog_options_meta Array of global BP options. 
  62. */ 
  63. return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );