bb_cache_all_options

The BuddyPress bb cache all options function.

Description

bb_cache_all_options(); 

Usage

  1. if ( !function_exists( 'bb_cache_all_options' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-meta.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_cache_all_options(); 
  7.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-meta.php  
  1. function bb_cache_all_options() 
  2. $base_options = array( 
  3. 'site_id',  
  4. 'bb_db_version',  
  5. 'name',  
  6. 'description',  
  7. 'uri_ssl',  
  8. 'from_email',  
  9. 'bb_auth_salt',  
  10. 'bb_secure_auth_salt',  
  11. 'bb_logged_in_salt',  
  12. 'bb_nonce_salt',  
  13. 'page_topics',  
  14. 'edit_lock',  
  15. 'bb_active_theme',  
  16. 'active_plugins',  
  17. 'mod_rewrite',  
  18. 'datetime_format',  
  19. 'date_format',  
  20. 'avatars_show',  
  21. 'avatars_default',  
  22. 'avatars_rating',  
  23. 'wp_table_prefix',  
  24. 'user_bbdb_name',  
  25. 'user_bbdb_user',  
  26. 'user_bbdb_password',  
  27. 'user_bbdb_host',  
  28. 'user_bbdb_charset',  
  29. 'user_bbdb_collate',  
  30. 'custom_user_table',  
  31. 'custom_user_meta_table',  
  32. 'wp_siteurl',  
  33. 'wp_home',  
  34. 'cookiedomain',  
  35. 'usercookie',  
  36. 'passcookie',  
  37. 'authcookie',  
  38. 'cookiepath',  
  39. 'sitecookiepath',  
  40. 'secure_auth_cookie',  
  41. 'logged_in_cookie',  
  42. 'admin_cookie_path',  
  43. 'core_plugins_cookie_path',  
  44. 'user_plugins_cookie_path',  
  45. 'wp_admin_cookie_path',  
  46. 'wp_plugins_cookie_path',  
  47. 'wordpress_mu_primary_blog_id',  
  48. 'enable_loginless',  
  49. 'enable_subscriptions',  
  50. 'enable_xmlrpc',  
  51. 'enable_pingback',  
  52. 'throttle_time',  
  53. 'bb_xmlrpc_allow_user_switching',  
  54. 'bp_bbpress_cron',  
  55. 'email_login',  
  56. 'static_title',  
  57. 'plugin_cookie_paths',  
  58. 'wp_roles_map',  
  59. 'gmt_offset',  
  60. 'timezone_string',  
  61. 'name_link_profile',  
  62. 'bp_bbpress_cron_check',  
  63. ); 
  64.  
  65. // Check that these aren't already in the cache 
  66. $query_options = array(); 
  67. foreach ( $base_options as $base_option ) { 
  68. if ( isset( $bb->$base_option ) ) { 
  69. continue; 
  70. if ( wp_cache_get( $base_option, 'bb_option_not_set' ) ) { 
  71. continue; 
  72. if ( false === wp_cache_get( $base_option, 'bb_option' ) ) { 
  73. $query_options[] = $base_option; 
  74. wp_cache_set( $base_option, true, 'bb_option_not_set' ); 
  75. if ( !count( $query_options ) ) { 
  76. // It's all in cache 
  77. return true; 
  78.  
  79. $query_keys = "('" . join( "', '", $query_options ) . "')"; 
  80.  
  81. global $bbdb; 
  82. $results = $bbdb->get_results( "SELECT `meta_key`, `meta_value` FROM `$bbdb->meta` WHERE `object_type` = 'bb_option' AND `meta_key` IN $query_keys;" ); 
  83.  
  84. if ( count( $base_options ) === count( $query_options ) && ( !$results || !is_array( $results ) || !count( $results ) ) ) { 
  85. // Let's assume that the options haven't been populated from the old topicmeta table 
  86. if ( !BB_INSTALLING && ( !defined( 'BB_DO_NOT_UPGRADE_TOPICMETA' ) || !BB_DO_NOT_UPGRADE_TOPICMETA ) ) { 
  87. $topicmeta_exists = $bbdb->query( "SELECT * FROM $bbdb->topicmeta LIMIT 1" ); 
  88. if ($topicmeta_exists) { 
  89. require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' ); 
  90. // Create the meta table 
  91. $bbdb->query( $bb_queries['meta'] ); 
  92. // Copy options 
  93. $bbdb->query( "INSERT INTO `$bbdb->meta` (`meta_key`, `meta_value`) SELECT `meta_key`, `meta_value` FROM `$bbdb->topicmeta` WHERE `topic_id` = 0;" ); 
  94. // Copy topic meta 
  95. $bbdb->query( "INSERT INTO `$bbdb->meta` (`object_id`, `meta_key`, `meta_value`) SELECT `topic_id`, `meta_key`, `meta_value` FROM `$bbdb->topicmeta` WHERE `topic_id` != 0;" ); 
  96. // Entries with an object_id are topic meta at this stage 
  97. $bbdb->query( "UPDATE `$bbdb->meta` SET `object_type` = 'bb_topic' WHERE `object_id` != 0" ); 
  98. unset( $topicmeta_exists ); 
  99.  
  100. return bb_cache_all_options(); 
  101.  
  102. return false; 
  103. } else { 
  104. foreach ( $results as $options ) { 
  105. wp_cache_delete( $options->meta_key, 'bb_option_not_set' ); 
  106. wp_cache_set( $options->meta_key, maybe_unserialize( $options->meta_value ), 'bb_option' ); 
  107.  
  108. return true;