/bp-core/bp-core-update.php

  1. <?php 
  2. /** 
  3. * BuddyPress Updater. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage Updater 
  7. * @since 1.6.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Is this a fresh installation of BuddyPress? 
  15. * 
  16. * If there is no raw DB version, we infer that this is the first installation. 
  17. * 
  18. * @since 1.7.0 
  19. * 
  20. * @return bool True if this is a fresh BP install, otherwise false. 
  21. */ 
  22. function bp_is_install() { 
  23. return ! bp_get_db_version_raw(); 
  24.  
  25. /** 
  26. * Is this a BuddyPress update? 
  27. * 
  28. * Determined by comparing the registered BuddyPress version to the version 
  29. * number stored in the database. If the registered version is greater, it's 
  30. * an update. 
  31. * 
  32. * @since 1.6.0 
  33. * 
  34. * @return bool True if update, otherwise false. 
  35. */ 
  36. function bp_is_update() { 
  37.  
  38. // Current DB version of this site (per site in a multisite network). 
  39. $current_db = bp_get_option( '_bp_db_version' ); 
  40. $current_live = bp_get_db_version(); 
  41.  
  42. // Compare versions (cast as int and bool to be safe). 
  43. $is_update = (bool) ( (int) $current_db < (int) $current_live ); 
  44.  
  45. // Return the product of version comparison. 
  46. return $is_update; 
  47.  
  48. /** 
  49. * Determine whether BuddyPress is in the process of being activated. 
  50. * 
  51. * @since 1.6.0 
  52. * 
  53. * @param string $basename BuddyPress basename. 
  54. * @return bool True if activating BuddyPress, false if not. 
  55. */ 
  56. function bp_is_activation( $basename = '' ) { 
  57. $bp = buddypress(); 
  58. $action = false; 
  59.  
  60. if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) ) { 
  61. $action = $_REQUEST['action']; 
  62. } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) ) { 
  63. $action = $_REQUEST['action2']; 
  64.  
  65. // Bail if not activating. 
  66. if ( empty( $action ) || !in_array( $action, array( 'activate', 'activate-selected' ) ) ) { 
  67. return false; 
  68.  
  69. // The plugin(s) being activated. 
  70. if ( $action == 'activate' ) { 
  71. $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array(); 
  72. } else { 
  73. $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
  74.  
  75. // Set basename if empty. 
  76. if ( empty( $basename ) && !empty( $bp->basename ) ) { 
  77. $basename = $bp->basename; 
  78.  
  79. // Bail if no basename. 
  80. if ( empty( $basename ) ) { 
  81. return false; 
  82.  
  83. // Is BuddyPress being activated? 
  84. return in_array( $basename, $plugins ); 
  85.  
  86. /** 
  87. * Determine whether BuddyPress is in the process of being deactivated. 
  88. * 
  89. * @since 1.6.0 
  90. * 
  91. * @param string $basename BuddyPress basename. 
  92. * @return bool True if deactivating BuddyPress, false if not. 
  93. */ 
  94. function bp_is_deactivation( $basename = '' ) { 
  95. $bp = buddypress(); 
  96. $action = false; 
  97.  
  98. if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) ) { 
  99. $action = $_REQUEST['action']; 
  100. } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) ) { 
  101. $action = $_REQUEST['action2']; 
  102.  
  103. // Bail if not deactivating. 
  104. if ( empty( $action ) || !in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) ) { 
  105. return false; 
  106.  
  107. // The plugin(s) being deactivated. 
  108. if ( 'deactivate' == $action ) { 
  109. $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array(); 
  110. } else { 
  111. $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
  112.  
  113. // Set basename if empty. 
  114. if ( empty( $basename ) && !empty( $bp->basename ) ) { 
  115. $basename = $bp->basename; 
  116.  
  117. // Bail if no basename. 
  118. if ( empty( $basename ) ) { 
  119. return false; 
  120.  
  121. // Is bbPress being deactivated? 
  122. return in_array( $basename, $plugins ); 
  123.  
  124. /** 
  125. * Update the BP version stored in the database to the current version. 
  126. * 
  127. * @since 1.6.0 
  128. */ 
  129. function bp_version_bump() { 
  130. bp_update_option( '_bp_db_version', bp_get_db_version() ); 
  131.  
  132. /** 
  133. * Set up the BuddyPress updater. 
  134. * 
  135. * @since 1.6.0 
  136. */ 
  137. function bp_setup_updater() { 
  138.  
  139. // Are we running an outdated version of BuddyPress? 
  140. if ( ! bp_is_update() ) { 
  141. return; 
  142.  
  143. bp_version_updater(); 
  144.  
  145. /** 
  146. * Initialize an update or installation of BuddyPress. 
  147. * 
  148. * BuddyPress's version updater looks at what the current database version is,  
  149. * and runs whatever other code is needed - either the "update" or "install" 
  150. * code. 
  151. * 
  152. * This is most often used when the data schema changes, but should also be used 
  153. * to correct issues with BuddyPress metadata silently on software update. 
  154. * 
  155. * @since 1.7.0 
  156. */ 
  157. function bp_version_updater() { 
  158.  
  159. // Get the raw database version. 
  160. $raw_db_version = (int) bp_get_db_version_raw(); 
  161.  
  162. /** 
  163. * Filters the default components to activate for a new install. 
  164. * 
  165. * @since 1.7.0 
  166. * 
  167. * @param array $value Array of default components to activate. 
  168. */ 
  169. $default_components = apply_filters( 'bp_new_install_default_components', array( 
  170. 'activity' => 1,  
  171. 'members' => 1,  
  172. 'settings' => 1,  
  173. 'xprofile' => 1,  
  174. 'notifications' => 1,  
  175. ) ); 
  176.  
  177. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  178. require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' ); 
  179. $switched_to_root_blog = false; 
  180.  
  181. // Make sure the current blog is set to the root blog. 
  182. if ( ! bp_is_root_blog() ) { 
  183. switch_to_blog( bp_get_root_blog_id() ); 
  184. bp_register_taxonomies(); 
  185.  
  186. $switched_to_root_blog = true; 
  187.  
  188. // Install BP schema and activate only Activity and XProfile. 
  189. if ( bp_is_install() ) { 
  190.  
  191. // Apply schema and set Activity and XProfile components as active. 
  192. bp_core_install( $default_components ); 
  193. bp_update_option( 'bp-active-components', $default_components ); 
  194. bp_core_add_page_mappings( $default_components, 'delete' ); 
  195. bp_core_install_emails(); 
  196.  
  197. // Upgrades. 
  198. } else { 
  199.  
  200. // Run the schema install to update tables. 
  201. bp_core_install(); 
  202.  
  203. // Version 1.5.0. 
  204. if ( $raw_db_version < 1801 ) { 
  205. bp_update_to_1_5(); 
  206. bp_core_add_page_mappings( $default_components, 'delete' ); 
  207.  
  208. // Version 1.6.0. 
  209. if ( $raw_db_version < 6067 ) { 
  210. bp_update_to_1_6(); 
  211.  
  212. // Version 1.9.0. 
  213. if ( $raw_db_version < 7553 ) { 
  214. bp_update_to_1_9(); 
  215.  
  216. // Version 1.9.2. 
  217. if ( $raw_db_version < 7731 ) { 
  218. bp_update_to_1_9_2(); 
  219.  
  220. // Version 2.0.0. 
  221. if ( $raw_db_version < 7892 ) { 
  222. bp_update_to_2_0(); 
  223.  
  224. // Version 2.0.1. 
  225. if ( $raw_db_version < 8311 ) { 
  226. bp_update_to_2_0_1(); 
  227.  
  228. // Version 2.2.0. 
  229. if ( $raw_db_version < 9181 ) { 
  230. bp_update_to_2_2(); 
  231.  
  232. // Version 2.3.0. 
  233. if ( $raw_db_version < 9615 ) { 
  234. bp_update_to_2_3(); 
  235.  
  236. // Version 2.5.0. 
  237. if ( $raw_db_version < 10440 ) { 
  238. bp_update_to_2_5(); 
  239.  
  240. // Version 2.7.0. 
  241. if ( $raw_db_version < 11105 ) { 
  242. bp_update_to_2_7(); 
  243.  
  244. /** All done! *************************************************************/ 
  245.  
  246. // Bump the version. 
  247. bp_version_bump(); 
  248.  
  249. if ( $switched_to_root_blog ) { 
  250. restore_current_blog(); 
  251.  
  252. /** 
  253. * Perform database operations that must take place before the general schema upgrades. 
  254. * 
  255. * `dbDelta()` cannot handle certain operations - like changing indexes - so we do it here instead. 
  256. * 
  257. * @since 2.3.0 
  258. */ 
  259. function bp_pre_schema_upgrade() { 
  260. global $wpdb; 
  261.  
  262. $raw_db_version = (int) bp_get_db_version_raw(); 
  263. $bp_prefix = bp_core_get_table_prefix(); 
  264.  
  265. // 2.3.0: Change index lengths to account for utf8mb4. 
  266. if ( $raw_db_version < 9695 ) { 
  267. // Map table_name => columns. 
  268. $tables = array( 
  269. $bp_prefix . 'bp_activity_meta' => array( 'meta_key' ),  
  270. $bp_prefix . 'bp_groups_groupmeta' => array( 'meta_key' ),  
  271. $bp_prefix . 'bp_messages_meta' => array( 'meta_key' ),  
  272. $bp_prefix . 'bp_notifications_meta' => array( 'meta_key' ),  
  273. $bp_prefix . 'bp_user_blogs_blogmeta' => array( 'meta_key' ),  
  274. $bp_prefix . 'bp_xprofile_meta' => array( 'meta_key' ),  
  275. ); 
  276.  
  277. foreach ( $tables as $table_name => $indexes ) { 
  278. foreach ( $indexes as $index ) { 
  279. if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", bp_esc_like( $table_name ) ) ) ) { 
  280. $wpdb->query( "ALTER TABLE {$table_name} DROP INDEX {$index}" ); 
  281.  
  282. /** Upgrade Routines **********************************************************/ 
  283.  
  284. /** 
  285. * Remove unused metadata from database when upgrading from < 1.5. 
  286. * 
  287. * Database update methods based on version numbers. 
  288. * 
  289. * @since 1.7.0 
  290. */ 
  291. function bp_update_to_1_5() { 
  292.  
  293. // Delete old database version options. 
  294. delete_site_option( 'bp-activity-db-version' ); 
  295. delete_site_option( 'bp-blogs-db-version' ); 
  296. delete_site_option( 'bp-friends-db-version' ); 
  297. delete_site_option( 'bp-groups-db-version' ); 
  298. delete_site_option( 'bp-messages-db-version' ); 
  299. delete_site_option( 'bp-xprofile-db-version' ); 
  300.  
  301. /** 
  302. * Remove unused metadata from database when upgrading from < 1.6.0. 
  303. * 
  304. * Database update methods based on version numbers. 
  305. * 
  306. * @since 1.7.0 
  307. */ 
  308. function bp_update_to_1_6() { 
  309.  
  310. // Delete possible site options. 
  311. delete_site_option( 'bp-db-version' ); 
  312. delete_site_option( '_bp_db_version' ); 
  313. delete_site_option( 'bp-core-db-version' ); 
  314. delete_site_option( '_bp-core-db-version' ); 
  315.  
  316. // Delete possible blog options. 
  317. delete_blog_option( bp_get_root_blog_id(), 'bp-db-version' ); 
  318. delete_blog_option( bp_get_root_blog_id(), 'bp-core-db-version' ); 
  319. delete_site_option( bp_get_root_blog_id(), '_bp-core-db-version' ); 
  320. delete_site_option( bp_get_root_blog_id(), '_bp_db_version' ); 
  321.  
  322. /** 
  323. * Add the notifications component to active components. 
  324. * 
  325. * Notifications was added in 1.9.0, and previous installations will already 
  326. * have the core notifications API active. We need to add the new Notifications 
  327. * component to the active components option to retain existing functionality. 
  328. * 
  329. * @since 1.9.0 
  330. */ 
  331. function bp_update_to_1_9() { 
  332.  
  333. // Setup hardcoded keys. 
  334. $active_components_key = 'bp-active-components'; 
  335. $notifications_component_id = 'notifications'; 
  336.  
  337. // Get the active components. 
  338. $active_components = bp_get_option( $active_components_key ); 
  339.  
  340. // Add notifications. 
  341. if ( ! in_array( $notifications_component_id, $active_components ) ) { 
  342. $active_components[ $notifications_component_id ] = 1; 
  343.  
  344. // Update the active components option. 
  345. bp_update_option( $active_components_key, $active_components ); 
  346.  
  347. /** 
  348. * Perform database updates for BP 1.9.2. 
  349. * 
  350. * In 1.9, BuddyPress stopped registering its theme directory when it detected 
  351. * that bp-default (or a child theme) was not currently being used, in effect 
  352. * deprecating bp-default. However, this ended up causing problems when site 
  353. * admins using bp-default would switch away from the theme temporarily: 
  354. * bp-default would no longer be available, with no obvious way (outside of 
  355. * a manual filter) to restore it. In 1.9.2, we add an option that flags 
  356. * whether bp-default or a child theme is active at the time of upgrade; if so,  
  357. * 
  358. * the theme directory will continue to be registered even if the theme is 
  359. * deactivated temporarily. Thus, new installations will not see bp-default,  
  360. * but legacy installations using the theme will continue to see it. 
  361. * 
  362. * @since 1.9.2 
  363. */ 
  364. function bp_update_to_1_9_2() { 
  365. if ( 'bp-default' === get_stylesheet() || 'bp-default' === get_template() ) { 
  366. update_site_option( '_bp_retain_bp_default', 1 ); 
  367.  
  368. /** 
  369. * 2.0 update routine. 
  370. * 
  371. * - Ensure that the activity tables are installed, for last_activity storage. 
  372. * - Migrate last_activity data from usermeta to activity table. 
  373. * - Add values for all BuddyPress options to the options table. 
  374. * 
  375. * @since 2.0.0 
  376. */ 
  377. function bp_update_to_2_0() { 
  378.  
  379. /** Install activity tables for 'last_activity' ***************************/ 
  380.  
  381. bp_core_install_activity_streams(); 
  382.  
  383. /** Migrate 'last_activity' data ******************************************/ 
  384.  
  385. bp_last_activity_migrate(); 
  386.  
  387. /** Migrate signups data **************************************************/ 
  388.  
  389. if ( ! is_multisite() ) { 
  390.  
  391. // Maybe install the signups table. 
  392. bp_core_maybe_install_signups(); 
  393.  
  394. // Run the migration script. 
  395. bp_members_migrate_signups(); 
  396.  
  397. /** Add BP options to the options table ***********************************/ 
  398.  
  399. bp_add_options(); 
  400.  
  401. /** 
  402. * 2.0.1 database upgrade routine. 
  403. * 
  404. * @since 2.0.1 
  405. */ 
  406. function bp_update_to_2_0_1() { 
  407.  
  408. // We purposely call this during both the 2.0 upgrade and the 2.0.1 upgrade. 
  409. // Don't worry; it won't break anything, and safely handles all cases. 
  410. bp_core_maybe_install_signups(); 
  411.  
  412. /** 
  413. * 2.2.0 update routine. 
  414. * 
  415. * - Add messages meta table. 
  416. * - Update the component field of the 'new members' activity type. 
  417. * - Clean up hidden friendship activities. 
  418. * 
  419. * @since 2.2.0 
  420. */ 
  421. function bp_update_to_2_2() { 
  422.  
  423. // Also handled by `bp_core_install()`. 
  424. if ( bp_is_active( 'messages' ) ) { 
  425. bp_core_install_private_messaging(); 
  426.  
  427. if ( bp_is_active( 'activity' ) ) { 
  428. bp_migrate_new_member_activity_component(); 
  429.  
  430. if ( bp_is_active( 'friends' ) ) { 
  431. bp_cleanup_friendship_activities(); 
  432.  
  433. /** 
  434. * 2.3.0 update routine. 
  435. * 
  436. * - Add notifications meta table. 
  437. * 
  438. * @since 2.3.0 
  439. */ 
  440. function bp_update_to_2_3() { 
  441.  
  442. // Also handled by `bp_core_install()`. 
  443. if ( bp_is_active( 'notifications' ) ) { 
  444. bp_core_install_notifications(); 
  445.  
  446. /** 
  447. * 2.5.0 update routine. 
  448. * 
  449. * - Add emails. 
  450. * 
  451. * @since 2.5.0 
  452. */ 
  453. function bp_update_to_2_5() { 
  454. bp_core_install_emails(); 
  455.  
  456. /** 
  457. * 2.7.0 update routine. 
  458. * 
  459. * - Add email unsubscribe salt. 
  460. * - Save legacy directory titles to the corresponding WP pages. 
  461. * - Add ignore deprecated code option (false for updates). 
  462. * 
  463. * @since 2.7.0 
  464. */ 
  465. function bp_update_to_2_7() { 
  466. bp_add_option( 'bp-emails-unsubscribe-salt', base64_encode( wp_generate_password( 64, true, true ) ) ); 
  467.  
  468. // Update post_titles 
  469. bp_migrate_directory_page_titles(); 
  470.  
  471. /** 
  472. * Add `parent_id` column to groups table. 
  473. * Also handled by `bp_core_install()`. 
  474. */ 
  475. if ( bp_is_active( 'groups' ) ) { 
  476. bp_core_install_groups(); 
  477.  
  478. // Invalidate all cached group objects. 
  479. global $wpdb; 
  480. $bp = buddypress(); 
  481.  
  482. $group_ids = $wpdb->get_col( "SELECT id FROM {$bp->groups->table_name}" ); 
  483.  
  484. foreach ( $group_ids as $group_id ) { 
  485. wp_cache_delete( $group_id, 'bp_groups' ); 
  486.  
  487. // Do not ignore deprecated code for existing installs. 
  488. bp_add_option( '_bp_ignore_deprecated_code', false ); 
  489.  
  490. /** 
  491. * Updates the component field for new_members type. 
  492. * 
  493. * @since 2.2.0 
  494. * 
  495. * @global $wpdb 
  496. */ 
  497. function bp_migrate_new_member_activity_component() { 
  498. global $wpdb; 
  499. $bp = buddypress(); 
  500.  
  501. // Update the component for the new_member type. 
  502. $wpdb->update( 
  503. // Activity table. 
  504. $bp->members->table_name_last_activity,  
  505. array( 
  506. 'component' => $bp->members->id,  
  507. ),  
  508. array( 
  509. 'component' => 'xprofile',  
  510. 'type' => 'new_member',  
  511. ),  
  512. // Data sanitization format. 
  513. array( 
  514. '%s',  
  515. ),  
  516. // WHERE sanitization format. 
  517. array( 
  518. '%s',  
  519. '%s' 
  520. ); 
  521.  
  522. /** 
  523. * Remove all hidden friendship activities. 
  524. * 
  525. * @since 2.2.0 
  526. */ 
  527. function bp_cleanup_friendship_activities() { 
  528. bp_activity_delete( array( 
  529. 'component' => buddypress()->friends->id,  
  530. 'type' => 'friendship_created',  
  531. 'hide_sitewide' => true,  
  532. ) ); 
  533.  
  534. /** 
  535. * Update WP pages so that their post_title matches the legacy component directory title. 
  536. * 
  537. * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,  
  538. * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these 
  539. * WP posts with the formerly hardcoded titles. 
  540. * 
  541. * @since 2.7.0 
  542. */ 
  543. function bp_migrate_directory_page_titles() { 
  544. $bp_pages = bp_core_get_directory_page_ids( 'all' ); 
  545.  
  546. $default_titles = bp_core_get_directory_page_default_titles(); 
  547.  
  548. $legacy_titles = array( 
  549. 'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),  
  550. 'blogs' => _x( 'Sites', 'component directory title', 'buddypress' ),  
  551. 'groups' => _x( 'Groups', 'component directory title', 'buddypress' ),  
  552. 'members' => _x( 'Members', 'component directory title', 'buddypress' ),  
  553. ); 
  554.  
  555. foreach ( $bp_pages as $component => $page_id ) { 
  556. if ( ! isset( $legacy_titles[ $component ] ) ) { 
  557. continue; 
  558.  
  559. $page = get_post( $page_id ); 
  560. if ( ! $page ) { 
  561. continue; 
  562.  
  563. // If the admin has changed the default title, don't touch it. 
  564. if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) { 
  565. continue; 
  566.  
  567. // If the saved page title is the same as the legacy title, there's nothing to do. 
  568. if ( $legacy_titles[ $component ] == $page->post_title ) { 
  569. continue; 
  570.  
  571. // Update the page with the legacy title. 
  572. wp_update_post( array( 
  573. 'ID' => $page_id,  
  574. 'post_title' => $legacy_titles[ $component ],  
  575. ) ); 
  576.  
  577. /** 
  578. * Redirect user to BP's What's New page on first page load after activation. 
  579. * 
  580. * @since 1.7.0 
  581. * 
  582. * @internal Used internally to redirect BuddyPress to the about page on activation. 
  583. */ 
  584. function bp_add_activation_redirect() { 
  585.  
  586. // Bail if activating from network, or bulk. 
  587. if ( isset( $_GET['activate-multi'] ) ) { 
  588. return; 
  589.  
  590. // Record that this is a new installation, so we show the right 
  591. // welcome message. 
  592. if ( bp_is_install() ) { 
  593. set_transient( '_bp_is_new_install', true, 30 ); 
  594.  
  595. // Add the transient to redirect. 
  596. set_transient( '_bp_activation_redirect', true, 30 ); 
  597.  
  598. /** Signups *******************************************************************/ 
  599.  
  600. /** 
  601. * Check if the signups table needs to be created or upgraded. 
  602. * 
  603. * @since 2.0.0 
  604. * 
  605. * @global WPDB $wpdb 
  606. */ 
  607. function bp_core_maybe_install_signups() { 
  608. global $wpdb; 
  609.  
  610. // The table to run queries against. 
  611. $signups_table = $wpdb->base_prefix . 'signups'; 
  612.  
  613. // Suppress errors because users shouldn't see what happens next. 
  614. $old_suppress = $wpdb->suppress_errors(); 
  615.  
  616. // Never use bp_core_get_table_prefix() for any global users tables. 
  617. $table_exists = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" ); 
  618.  
  619. // Table already exists, so maybe upgrade instead? 
  620. if ( true === $table_exists ) { 
  621.  
  622. // Look for the 'signup_id' column. 
  623. $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" ); 
  624.  
  625. // 'signup_id' column doesn't exist, so run the upgrade 
  626. if ( empty( $column_exists ) ) { 
  627. bp_core_upgrade_signups(); 
  628.  
  629. // Table does not exist, and we are a single site, so install the multisite 
  630. // signups table using WordPress core's database schema. 
  631. } elseif ( ! is_multisite() ) { 
  632. bp_core_install_signups(); 
  633.  
  634. // Restore previous error suppression setting. 
  635. $wpdb->suppress_errors( $old_suppress ); 
  636.  
  637. /** Activation Actions ********************************************************/ 
  638.  
  639. /** 
  640. * Fire activation hooks and events. 
  641. * 
  642. * Runs on BuddyPress activation. 
  643. * 
  644. * @since 1.6.0 
  645. */ 
  646. function bp_activation() { 
  647.  
  648. // Force refresh theme roots. 
  649. delete_site_transient( 'theme_roots' ); 
  650.  
  651. // Add options. 
  652. bp_add_options(); 
  653.  
  654. /** 
  655. * Fires during the activation of BuddyPress. 
  656. * 
  657. * Use as of 1.6.0. 
  658. * 
  659. * @since 1.6.0 
  660. */ 
  661. do_action( 'bp_activation' ); 
  662.  
  663. // @deprecated as of 1.6.0 
  664. do_action( 'bp_loader_activate' ); 
  665.  
  666. /** 
  667. * Fire deactivation hooks and events. 
  668. * 
  669. * Runs on BuddyPress deactivation. 
  670. * 
  671. * @since 1.6.0 
  672. */ 
  673. function bp_deactivation() { 
  674.  
  675. // Force refresh theme roots. 
  676. delete_site_transient( 'theme_roots' ); 
  677.  
  678. // Switch to WordPress's default theme if current parent or child theme 
  679. // depend on bp-default. This is to prevent white screens of doom. 
  680. if ( in_array( 'bp-default', array( get_template(), get_stylesheet() ) ) ) { 
  681. switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); 
  682. update_option( 'template_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) ); 
  683. update_option( 'stylesheet_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) ); 
  684.  
  685. /** 
  686. * Fires during the deactivation of BuddyPress. 
  687. * 
  688. * Use as of 1.6.0. 
  689. * 
  690. * @since 1.6.0 
  691. */ 
  692. do_action( 'bp_deactivation' ); 
  693.  
  694. // @deprecated as of 1.6.0 
  695. do_action( 'bp_loader_deactivate' ); 
  696.  
  697. /** 
  698. * Fire uninstall hook. 
  699. * 
  700. * Runs when uninstalling BuddyPress. 
  701. * 
  702. * @since 1.6.0 
  703. */ 
  704. function bp_uninstall() { 
  705.  
  706. /** 
  707. * Fires during the uninstallation of BuddyPress. 
  708. * 
  709. * @since 1.6.0 
  710. */ 
  711. do_action( 'bp_uninstall' ); 
.