BuddyPress

Main BuddyPress Class.

Defined (1)

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

/class-buddypress.php  
  1. class BuddyPress { 
  2.  
  3. /** Magic *****************************************************************/ 
  4.  
  5. /** 
  6. * BuddyPress uses many variables, most of which can be filtered to 
  7. * customize the way that it works. To prevent unauthorized access,  
  8. * these variables are stored in a private array that is magically 
  9. * updated using PHP 5.2+ methods. This is to prevent third party 
  10. * plugins from tampering with essential information indirectly, which 
  11. * would cause issues later. 
  12. * @see BuddyPress::setup_globals() 
  13. * @var array 
  14. */ 
  15. private $data; 
  16.  
  17. /** Not Magic *************************************************************/ 
  18.  
  19. /** 
  20. * @var array Primary BuddyPress navigation. 
  21. */ 
  22. public $bp_nav = array(); 
  23.  
  24. /** 
  25. * @var array Secondary BuddyPress navigation to $bp_nav. 
  26. */ 
  27. public $bp_options_nav = array(); 
  28.  
  29. /** 
  30. * @var array The unfiltered URI broken down into chunks. 
  31. * @see bp_core_set_uri_globals() 
  32. */ 
  33. public $unfiltered_uri = array(); 
  34.  
  35. /** 
  36. * @var array The canonical URI stack. 
  37. * @see bp_redirect_canonical() 
  38. * @see bp_core_new_nav_item() 
  39. */ 
  40. public $canonical_stack = array(); 
  41.  
  42. /** 
  43. * @var array Additional navigation elements (supplemental). 
  44. */ 
  45. public $action_variables = array(); 
  46.  
  47. /** 
  48. * @var string Current member directory type. 
  49. */ 
  50. public $current_member_type = ''; 
  51.  
  52. /** 
  53. * @var array Required components (core, members). 
  54. */ 
  55. public $required_components = array(); 
  56.  
  57. /** 
  58. * @var array Additional active components. 
  59. */ 
  60. public $loaded_components = array(); 
  61.  
  62. /** 
  63. * @var array Active components. 
  64. */ 
  65. public $active_components = array(); 
  66.  
  67. /** 
  68. * Whether autoload is in use. 
  69. * @since 2.5.0 
  70. * @var bool 
  71. */ 
  72. public $do_autoload = true; 
  73.  
  74. /** Option Overload *******************************************************/ 
  75.  
  76. /** 
  77. * @var array Optional Overloads default options retrieved from get_option(). 
  78. */ 
  79. public $options = array(); 
  80.  
  81. /** Singleton *************************************************************/ 
  82.  
  83. /** 
  84. * Main BuddyPress Instance. 
  85. * BuddyPress is great. 
  86. * Please load it only one time. 
  87. * For this, we thank you. 
  88. * Insures that only one instance of BuddyPress exists in memory at any 
  89. * one time. Also prevents needing to define globals all over the place. 
  90. * @since 1.7.0 
  91. * @static object $instance 
  92. * @see buddypress() 
  93. * @return BuddyPress The one true BuddyPress. 
  94. */ 
  95. public static function instance() { 
  96.  
  97. // Store the instance locally to avoid private static replication 
  98. static $instance = null; 
  99.  
  100. // Only run these methods if they haven't been run previously 
  101. if ( null === $instance ) { 
  102. $instance = new BuddyPress; 
  103. $instance->constants(); 
  104. $instance->setup_globals(); 
  105. $instance->legacy_constants(); 
  106. $instance->includes(); 
  107. $instance->setup_actions(); 
  108.  
  109. // Always return the instance 
  110. return $instance; 
  111.  
  112. // The last metroid is in captivity. The galaxy is at peace. 
  113.  
  114. /** Magic Methods *********************************************************/ 
  115.  
  116. /** 
  117. * A dummy constructor to prevent BuddyPress from being loaded more than once. 
  118. * @since 1.7.0 
  119. * @see BuddyPress::instance() 
  120. * @see buddypress() 
  121. */ 
  122. private function __construct() { /** Do nothing here */ } 
  123.  
  124. /** 
  125. * A dummy magic method to prevent BuddyPress from being cloned. 
  126. * @since 1.7.0 
  127. */ 
  128. public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 
  129.  
  130. /** 
  131. * A dummy magic method to prevent BuddyPress from being unserialized. 
  132. * @since 1.7.0 
  133. */ 
  134. public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 
  135.  
  136. /** 
  137. * Magic method for checking the existence of a certain custom field. 
  138. * @since 1.7.0 
  139. * @param string $key Key to check the set status for. 
  140. * @return bool 
  141. */ 
  142. public function __isset( $key ) { return isset( $this->data[$key] ); } 
  143.  
  144. /** 
  145. * Magic method for getting BuddyPress variables. 
  146. * @since 1.7.0 
  147. * @param string $key Key to return the value for. 
  148. * @return mixed 
  149. */ 
  150. public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; } 
  151.  
  152. /** 
  153. * Magic method for setting BuddyPress variables. 
  154. * @since 1.7.0 
  155. * @param string $key Key to set a value for. 
  156. * @param mixed $value Value to set. 
  157. */ 
  158. public function __set( $key, $value ) { $this->data[$key] = $value; } 
  159.  
  160. /** 
  161. * Magic method for unsetting BuddyPress variables. 
  162. * @since 1.7.0 
  163. * @param string $key Key to unset a value for. 
  164. */ 
  165. public function __unset( $key ) { if ( isset( $this->data[$key] ) ) unset( $this->data[$key] ); } 
  166.  
  167. /** 
  168. * Magic method to prevent notices and errors from invalid method calls. 
  169. * @since 1.7.0 
  170. * @param string $name 
  171. * @param array $args 
  172. * @return null 
  173. */ 
  174. public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; } 
  175.  
  176. /** Private Methods *******************************************************/ 
  177.  
  178. /** 
  179. * Bootstrap constants. 
  180. * @since 1.6.0 
  181. */ 
  182. private function constants() { 
  183.  
  184. // Place your custom code (actions/filters) in a file called 
  185. // '/plugins/bp-custom.php' and it will be loaded before anything else. 
  186. if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) ) { 
  187. require( WP_PLUGIN_DIR . '/bp-custom.php' ); 
  188.  
  189. // Path and URL 
  190. if ( ! defined( 'BP_PLUGIN_DIR' ) ) { 
  191. define( 'BP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 
  192.  
  193. if ( ! defined( 'BP_PLUGIN_URL' ) ) { 
  194. define( 'BP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 
  195.  
  196. // Only applicable to those running trunk 
  197. if ( ! defined( 'BP_SOURCE_SUBDIRECTORY' ) ) { 
  198. define( 'BP_SOURCE_SUBDIRECTORY', '' ); 
  199.  
  200. // Define on which blog ID BuddyPress should run 
  201. if ( ! defined( 'BP_ROOT_BLOG' ) ) { 
  202.  
  203. // Default to use current blog ID 
  204. // Fulfills non-network installs and BP_ENABLE_MULTIBLOG installs 
  205. $root_blog_id = get_current_blog_id(); 
  206.  
  207. // Multisite check 
  208. if ( is_multisite() ) { 
  209.  
  210. // Multiblog isn't enabled 
  211. if ( ! defined( 'BP_ENABLE_MULTIBLOG' ) || ( defined( 'BP_ENABLE_MULTIBLOG' ) && (int) constant( 'BP_ENABLE_MULTIBLOG' ) === 0 ) ) { 
  212. // Check to see if BP is network-activated 
  213. // We're not using is_plugin_active_for_network() b/c you need to include the 
  214. // /wp-admin/includes/plugin.php file in order to use that function. 
  215.  
  216. // get network-activated plugins 
  217. $plugins = get_site_option( 'active_sitewide_plugins'); 
  218.  
  219. // basename 
  220. $basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php'; 
  221.  
  222. // plugin is network-activated; use main site ID instead 
  223. if ( isset( $plugins[ $basename ] ) ) { 
  224. $current_site = get_current_site(); 
  225. $root_blog_id = $current_site->blog_id; 
  226.  
  227.  
  228. define( 'BP_ROOT_BLOG', $root_blog_id ); 
  229.  
  230. // The search slug has to be defined nice and early because of the way 
  231. // search requests are loaded 
  232. // 
  233. // @todo Make this better 
  234. if ( ! defined( 'BP_SEARCH_SLUG' ) ) { 
  235. define( 'BP_SEARCH_SLUG', 'search' ); 
  236.  
  237. /** 
  238. * Component global variables. 
  239. * @since 1.6.0 
  240. */ 
  241. private function setup_globals() { 
  242.  
  243. /** Versions **********************************************************/ 
  244.  
  245. $this->version = '2.8.2'; 
  246. $this->db_version = 11105; 
  247.  
  248. /** Loading ***********************************************************/ 
  249.  
  250. /** 
  251. * Should deprecated code be loaded? 
  252. * @since 2.0.0 Defaults to false always 
  253. * @since 2.8.0 Defaults to true on upgrades, false for new installs. 
  254. */ 
  255. $this->load_deprecated = false; 
  256.  
  257. /** Toolbar ***********************************************************/ 
  258.  
  259. /** 
  260. * @var string The primary toolbar ID. 
  261. */ 
  262. $this->my_account_menu_id = ''; 
  263.  
  264. /** URIs **************************************************************/ 
  265.  
  266. /** 
  267. * @var int The current offset of the URI. 
  268. * @see bp_core_set_uri_globals() 
  269. */ 
  270. $this->unfiltered_uri_offset = 0; 
  271.  
  272. /** 
  273. * @var bool Are status headers already sent? 
  274. */ 
  275. $this->no_status_set = false; 
  276.  
  277. /** Components ********************************************************/ 
  278.  
  279. /** 
  280. * @var string Name of the current BuddyPress component (primary). 
  281. */ 
  282. $this->current_component = ''; 
  283.  
  284. /** 
  285. * @var string Name of the current BuddyPress item (secondary). 
  286. */ 
  287. $this->current_item = ''; 
  288.  
  289. /** 
  290. * @var string Name of the current BuddyPress action (tertiary). 
  291. */ 
  292. $this->current_action = ''; 
  293.  
  294. /** 
  295. * @var bool Displaying custom 2nd level navigation menu (I.E a group). 
  296. */ 
  297. $this->is_single_item = false; 
  298.  
  299. /** Root **************************************************************/ 
  300.  
  301. /** 
  302. * Filters the BuddyPress Root blog ID. 
  303. * @since 1.5.0 
  304. * @const constant BP_ROOT_BLOG BuddyPress Root blog ID. 
  305. */ 
  306. $this->root_blog_id = (int) apply_filters( 'bp_get_root_blog_id', BP_ROOT_BLOG ); 
  307.  
  308. /** Paths**************************************************************/ 
  309.  
  310. // BuddyPress root directory 
  311. $this->file = constant( 'BP_PLUGIN_DIR' ) . 'bp-loader.php'; 
  312. $this->basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php'; 
  313. $this->plugin_dir = trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ); 
  314. $this->plugin_url = trailingslashit( constant( 'BP_PLUGIN_URL' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ); 
  315.  
  316. // Languages 
  317. $this->lang_dir = $this->plugin_dir . 'bp-languages'; 
  318.  
  319. // Templates (theme compatibility) 
  320. $this->themes_dir = $this->plugin_dir . 'bp-templates'; 
  321. $this->themes_url = $this->plugin_url . 'bp-templates'; 
  322.  
  323. // Themes (for bp-default) 
  324. $this->old_themes_dir = $this->plugin_dir . 'bp-themes'; 
  325. $this->old_themes_url = $this->plugin_url . 'bp-themes'; 
  326.  
  327. /** Theme Compat ******************************************************/ 
  328.  
  329. $this->theme_compat = new stdClass(); // Base theme compatibility class 
  330. $this->filters = new stdClass(); // Used when adding/removing filters 
  331.  
  332. /** Users *************************************************************/ 
  333.  
  334. $this->current_user = new stdClass(); 
  335. $this->displayed_user = new stdClass(); 
  336.  
  337. /** Post types and taxonomies *****************************************/ 
  338. $this->email_post_type = apply_filters( 'bp_email_post_type', 'bp-email' ); 
  339. $this->email_taxonomy_type = apply_filters( 'bp_email_tax_type', 'bp-email-type' ); 
  340.  
  341. /** 
  342. * Legacy BuddyPress constants. 
  343. * Try to avoid using these. Their values have been moved into variables 
  344. * in the instance, and have matching functions to get/set their values. 
  345. * @since 1.7.0 
  346. */ 
  347. private function legacy_constants() { 
  348.  
  349. // Define the BuddyPress version 
  350. if ( ! defined( 'BP_VERSION' ) ) { 
  351. define( 'BP_VERSION', $this->version ); 
  352.  
  353. // Define the database version 
  354. if ( ! defined( 'BP_DB_VERSION' ) ) { 
  355. define( 'BP_DB_VERSION', $this->db_version ); 
  356.  
  357. // Define if deprecated functions should be ignored 
  358. if ( ! defined( 'BP_IGNORE_DEPRECATED' ) ) { 
  359. define( 'BP_IGNORE_DEPRECATED', true ); 
  360.  
  361. /** 
  362. * Include required files. 
  363. * @since 1.6.0 
  364. */ 
  365. private function includes() { 
  366. spl_autoload_register( array( $this, 'autoload' ) ); 
  367.  
  368. // Load the WP abstraction file so BuddyPress can run on all WordPress setups. 
  369. require( $this->plugin_dir . 'bp-core/bp-core-wpabstraction.php' ); 
  370.  
  371. // Setup the versions (after we include multisite abstraction above) 
  372. $this->versions(); 
  373.  
  374. /** Update/Install ****************************************************/ 
  375.  
  376. // Theme compatibility 
  377. require( $this->plugin_dir . 'bp-core/bp-core-template-loader.php' ); 
  378. require( $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php' ); 
  379.  
  380. // Require all of the BuddyPress core libraries 
  381. require( $this->plugin_dir . 'bp-core/bp-core-dependency.php' ); 
  382. require( $this->plugin_dir . 'bp-core/bp-core-actions.php' ); 
  383. require( $this->plugin_dir . 'bp-core/bp-core-caps.php' ); 
  384. require( $this->plugin_dir . 'bp-core/bp-core-cache.php' ); 
  385. require( $this->plugin_dir . 'bp-core/bp-core-cssjs.php' ); 
  386. require( $this->plugin_dir . 'bp-core/bp-core-update.php' ); 
  387. require( $this->plugin_dir . 'bp-core/bp-core-options.php' ); 
  388. require( $this->plugin_dir . 'bp-core/bp-core-taxonomy.php' ); 
  389. require( $this->plugin_dir . 'bp-core/bp-core-filters.php' ); 
  390. require( $this->plugin_dir . 'bp-core/bp-core-attachments.php' ); 
  391. require( $this->plugin_dir . 'bp-core/bp-core-avatars.php' ); 
  392. require( $this->plugin_dir . 'bp-core/bp-core-widgets.php' ); 
  393. require( $this->plugin_dir . 'bp-core/bp-core-template.php' ); 
  394. require( $this->plugin_dir . 'bp-core/bp-core-adminbar.php' ); 
  395. require( $this->plugin_dir . 'bp-core/bp-core-buddybar.php' ); 
  396. require( $this->plugin_dir . 'bp-core/bp-core-catchuri.php' ); 
  397. require( $this->plugin_dir . 'bp-core/bp-core-functions.php' ); 
  398. require( $this->plugin_dir . 'bp-core/bp-core-moderation.php' ); 
  399. require( $this->plugin_dir . 'bp-core/bp-core-loader.php' ); 
  400. require( $this->plugin_dir . 'bp-core/bp-core-customizer-email.php' ); 
  401.  
  402. // Maybe load deprecated functionality (this double negative is proof positive!) 
  403. if ( ! bp_get_option( '_bp_ignore_deprecated_code', ! $this->load_deprecated ) ) { 
  404. require( $this->plugin_dir . 'bp-core/deprecated/1.2.php' ); 
  405. require( $this->plugin_dir . 'bp-core/deprecated/1.5.php' ); 
  406. require( $this->plugin_dir . 'bp-core/deprecated/1.6.php' ); 
  407. require( $this->plugin_dir . 'bp-core/deprecated/1.7.php' ); 
  408. require( $this->plugin_dir . 'bp-core/deprecated/1.9.php' ); 
  409. require( $this->plugin_dir . 'bp-core/deprecated/2.0.php' ); 
  410. require( $this->plugin_dir . 'bp-core/deprecated/2.1.php' ); 
  411. require( $this->plugin_dir . 'bp-core/deprecated/2.2.php' ); 
  412. require( $this->plugin_dir . 'bp-core/deprecated/2.3.php' ); 
  413. require( $this->plugin_dir . 'bp-core/deprecated/2.4.php' ); 
  414. require( $this->plugin_dir . 'bp-core/deprecated/2.5.php' ); 
  415. require( $this->plugin_dir . 'bp-core/deprecated/2.6.php' ); 
  416. require( $this->plugin_dir . 'bp-core/deprecated/2.7.php' ); 
  417.  
  418. /** 
  419. * Autoload classes. 
  420. * @since 2.5.0 
  421. * @param string $class 
  422. */ 
  423. public function autoload( $class ) { 
  424. $class_parts = explode( '_', strtolower( $class ) ); 
  425.  
  426. if ( 'bp' !== $class_parts[0] ) { 
  427. return; 
  428.  
  429. $components = array( 
  430. 'activity',  
  431. 'blogs',  
  432. 'core',  
  433. 'friends',  
  434. 'groups',  
  435. 'members',  
  436. 'messages',  
  437. 'notifications',  
  438. 'settings',  
  439. 'xprofile',  
  440. ); 
  441.  
  442. // These classes don't have a name that matches their component. 
  443. $irregular_map = array( 
  444. 'BP_Akismet' => 'activity',  
  445.  
  446. 'BP_Admin' => 'core',  
  447. 'BP_Attachment_Avatar' => 'core',  
  448. 'BP_Attachment_Cover_Image' => 'core',  
  449. 'BP_Attachment' => 'core',  
  450. 'BP_Button' => 'core',  
  451. 'BP_Component' => 'core',  
  452. 'BP_Customizer_Control_Range' => 'core',  
  453. 'BP_Date_Query' => 'core',  
  454. 'BP_Email_Delivery' => 'core',  
  455. 'BP_Email_Recipient' => 'core',  
  456. 'BP_Email' => 'core',  
  457. 'BP_Embed' => 'core',  
  458. 'BP_Media_Extractor' => 'core',  
  459. 'BP_Members_Suggestions' => 'core',  
  460. 'BP_PHPMailer' => 'core',  
  461. 'BP_Recursive_Query' => 'core',  
  462. 'BP_Suggestions' => 'core',  
  463. 'BP_Theme_Compat' => 'core',  
  464. 'BP_User_Query' => 'core',  
  465. 'BP_Walker_Category_Checklist' => 'core',  
  466. 'BP_Walker_Nav_Menu_Checklist' => 'core',  
  467. 'BP_Walker_Nav_Menu' => 'core',  
  468.  
  469. 'BP_Core_Friends_Widget' => 'friends',  
  470.  
  471. 'BP_Group_Extension' => 'groups',  
  472. 'BP_Group_Member_Query' => 'groups',  
  473.  
  474. 'BP_Core_Members_Template' => 'members',  
  475. 'BP_Core_Members_Widget' => 'members',  
  476. 'BP_Core_Recently_Active_Widget' => 'members',  
  477. 'BP_Core_Whos_Online_Widget' => 'members',  
  478. 'BP_Registration_Theme_Compat' => 'members',  
  479. 'BP_Signup' => 'members',  
  480. ); 
  481.  
  482. $component = null; 
  483.  
  484. // First check to see if the class is one without a properly namespaced name. 
  485. if ( isset( $irregular_map[ $class ] ) ) { 
  486. $component = $irregular_map[ $class ]; 
  487.  
  488. // Next chunk is usually the component name. 
  489. } elseif ( in_array( $class_parts[1], $components, true ) ) { 
  490. $component = $class_parts[1]; 
  491.  
  492. if ( ! $component ) { 
  493. return; 
  494.  
  495. // Sanitize class name. 
  496. $class = strtolower( str_replace( '_', '-', $class ) ); 
  497.  
  498. $path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php"; 
  499.  
  500. // Sanity check. 
  501. if ( ! file_exists( $path ) ) { 
  502. return; 
  503.  
  504. /** 
  505. * Sanity check 2 - Check if component is active before loading class. 
  506. * Skip if PHPUnit is running, or BuddyPress is installing for the first time. 
  507. */ 
  508. if ( 
  509. ! in_array( $component, array( 'core', 'members' ), true ) && 
  510. ! bp_is_active( $component ) && 
  511. ! function_exists( 'tests_add_filter' ) 
  512. ) { 
  513. return; 
  514.  
  515. require $path; 
  516.  
  517. /** 
  518. * Set up the default hooks and actions. 
  519. * @since 1.6.0 
  520. */ 
  521. private function setup_actions() { 
  522.  
  523. // Add actions to plugin activation and deactivation hooks 
  524. add_action( 'activate_' . $this->basename, 'bp_activation' ); 
  525. add_action( 'deactivate_' . $this->basename, 'bp_deactivation' ); 
  526.  
  527. // If BuddyPress is being deactivated, do not add any actions 
  528. if ( bp_is_deactivation( $this->basename ) ) { 
  529. return; 
  530.  
  531. // Array of BuddyPress core actions 
  532. $actions = array( 
  533. 'setup_theme', // Setup the default theme compat 
  534. 'setup_current_user', // Setup currently logged in user 
  535. 'register_post_types', // Register post types 
  536. 'register_post_statuses', // Register post statuses 
  537. 'register_taxonomies', // Register taxonomies 
  538. 'register_views', // Register the views 
  539. 'register_theme_directory', // Register the theme directory 
  540. 'register_theme_packages', // Register bundled theme packages (bp-themes) 
  541. 'load_textdomain', // Load textdomain 
  542. 'add_rewrite_tags', // Add rewrite tags 
  543. 'generate_rewrite_rules' // Generate rewrite rules 
  544. ); 
  545.  
  546. // Add the actions 
  547. foreach( $actions as $class_action ) { 
  548. if ( method_exists( $this, $class_action ) ) { 
  549. add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 ); 
  550.  
  551. /** 
  552. * Fires after the setup of all BuddyPress actions. 
  553. * Includes bbp-core-hooks.php. 
  554. * @since 1.7.0 
  555. * @param BuddyPress $this. Current BuddyPress instance. Passed by reference. 
  556. */ 
  557. do_action_ref_array( 'bp_after_setup_actions', array( &$this ) ); 
  558.  
  559. /** 
  560. * Private method to align the active and database versions. 
  561. * @since 1.7.0 
  562. */ 
  563. private function versions() { 
  564.  
  565. // Get the possible DB versions (boy is this gross) 
  566. $versions = array(); 
  567. $versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' ); 
  568.  
  569. // 1.6-single exists, so trust it 
  570. if ( !empty( $versions['1.6-single'] ) ) { 
  571. $this->db_version_raw = (int) $versions['1.6-single']; 
  572.  
  573. // If no 1.6-single exists, use the max of the others 
  574. } else { 
  575. $versions['1.2'] = get_site_option( 'bp-core-db-version' ); 
  576. $versions['1.5-multi'] = get_site_option( 'bp-db-version' ); 
  577. $versions['1.6-multi'] = get_site_option( '_bp_db_version' ); 
  578. $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' ); 
  579.  
  580. // Remove empty array items 
  581. $versions = array_filter( $versions ); 
  582. $this->db_version_raw = (int) ( !empty( $versions ) ) ? (int) max( $versions ) : 0; 
  583.  
  584. /** Public Methods ********************************************************/ 
  585.  
  586. /** 
  587. * Set up BuddyPress's legacy theme directory. 
  588. * Starting with version 1.2, and ending with version 1.8, BuddyPress 
  589. * registered a custom theme directory - bp-themes - which contained 
  590. * the bp-default theme. Since BuddyPress 1.9, bp-themes is no longer 
  591. * registered (and bp-default no longer offered) on new installations. 
  592. * Sites using bp-default (or a child theme of bp-default) will 
  593. * continue to have bp-themes registered as before. 
  594. * @since 1.5.0 
  595. * @todo Move bp-default to wordpress.org/extend/themes and remove this. 
  596. */ 
  597. public function register_theme_directory() { 
  598. if ( ! bp_do_register_theme_directory() ) { 
  599. return; 
  600.  
  601. register_theme_directory( $this->old_themes_dir ); 
  602.  
  603. /** 
  604. * Register bundled theme packages. 
  605. * Note that since we currently have complete control over bp-themes and 
  606. * the bp-legacy folders, it's fine to hardcode these here. If at a 
  607. * later date we need to automate this, an API will need to be built. 
  608. * @since 1.7.0 
  609. */ 
  610. public function register_theme_packages() { 
  611.  
  612. // Register the default theme compatibility package 
  613. bp_register_theme_package( array( 
  614. 'id' => 'legacy',  
  615. 'name' => __( 'BuddyPress Default', 'buddypress' ),  
  616. 'version' => bp_get_version(),  
  617. 'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ),  
  618. 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ) 
  619. ) ); 
  620.  
  621. // Register the basic theme stack. This is really dope. 
  622. bp_register_template_stack( 'get_stylesheet_directory', 10 ); 
  623. bp_register_template_stack( 'get_template_directory', 12 ); 
  624. bp_register_template_stack( 'bp_get_theme_compat_dir', 14 ); 
  625.  
  626. /** 
  627. * Set up the default BuddyPress theme compatibility location. 
  628. * @since 1.7.0 
  629. */ 
  630. public function setup_theme() { 
  631.  
  632. // Bail if something already has this under control 
  633. if ( ! empty( $this->theme_compat->theme ) ) { 
  634. return; 
  635.  
  636. // Setup the theme package to use for compatibility 
  637. bp_setup_theme_compat( bp_get_theme_package_id() );