basename ) ) { $basename = $bp->basename; } // Bail if no basename if ( empty( $basename ) ) { return false; } // Is BuddyPress being activated? return in_array( $basename, $plugins ); } /** * Determine whether BuddyPress is in the process of being deactivated. * * @since BuddyPress (1.6.0) * * @uses buddypress() * * @return bool True if deactivating BuddyPress, false if not. */ function bp_is_deactivation( $basename = '' ) { $bp = buddypress(); $action = false; if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) ) { $action = $_REQUEST['action']; } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) ) { $action = $_REQUEST['action2']; } // Bail if not deactivating if ( empty( $action ) || !in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) ) { return false; } // The plugin(s) being deactivated if ( 'deactivate' == $action ) { $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array(); } else { $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); } // Set basename if empty if ( empty( $basename ) && !empty( $bp->basename ) ) { $basename = $bp->basename; } // Bail if no basename if ( empty( $basename ) ) { return false; } // Is bbPress being deactivated? return in_array( $basename, $plugins ); } /** * Update the BP version stored in the database to the current version. * * @since BuddyPress (1.6.0) * * @uses bp_get_db_version() To get BuddyPress's database version. * @uses bp_update_option() To update BuddyPress's database version. */ function bp_version_bump() { bp_update_option( '_bp_db_version', bp_get_db_version() ); } /** * Set up the BuddyPress updater. * * @since BuddyPress (1.6.0) */ function bp_setup_updater() { // Are we running an outdated version of BuddyPress? if ( ! bp_is_update() ) return; bp_version_updater(); } /** * Initialize an update or installation of BuddyPress. * * BuddyPress's version updater looks at what the current database version is, * and runs whatever other code is needed - either the "update" or "install" * code. * * This is most often used when the data schema changes, but should also be used * to correct issues with BuddyPress metadata silently on software update. * * @since BuddyPress (1.7.0) */ function bp_version_updater() { // Get the raw database version $raw_db_version = (int) bp_get_db_version_raw(); $default_components = apply_filters( 'bp_new_install_default_components', array( 'activity' => 1, 'members' => 1, 'settings' => 1, 'xprofile' => 1, 'notifications' => 1, ) ); require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' ); // Install BP schema and activate only Activity and XProfile if ( bp_is_install() ) { // Apply schema and set Activity and XProfile components as active bp_core_install( $default_components ); bp_update_option( 'bp-active-components', $default_components ); bp_core_add_page_mappings( $default_components, 'delete' ); // Upgrades } else { // Run the schema install to update tables bp_core_install(); // 1.5 if ( $raw_db_version < 1801 ) { bp_update_to_1_5(); bp_core_add_page_mappings( $default_components, 'delete' ); } // 1.6 if ( $raw_db_version < 6067 ) { bp_update_to_1_6(); } // 1.9 if ( $raw_db_version < 7553 ) { bp_update_to_1_9(); } // 1.9.2 if ( $raw_db_version < 7731 ) { bp_update_to_1_9_2(); } // 2.0 if ( $raw_db_version < 7892 ) { bp_update_to_2_0(); } // 2.0.1 if ( $raw_db_version < 8311 ) { bp_update_to_2_0_1(); } } /** All done! *************************************************************/ // Bump the version bp_version_bump(); } /** Upgrade Routines **********************************************************/ /** * Remove unused metadata from database when upgrading from < 1.5. * * Database update methods based on version numbers. * * @since BuddyPress (1.7.0) */ function bp_update_to_1_5() { // Delete old database version options delete_site_option( 'bp-activity-db-version' ); delete_site_option( 'bp-blogs-db-version' ); delete_site_option( 'bp-friends-db-version' ); delete_site_option( 'bp-groups-db-version' ); delete_site_option( 'bp-messages-db-version' ); delete_site_option( 'bp-xprofile-db-version' ); } /** * Remove unused metadata from database when upgrading from < 1.6. * * Database update methods based on version numbers. * * @since BuddyPress (1.7.0) */ function bp_update_to_1_6() { // Delete possible site options delete_site_option( 'bp-db-version' ); delete_site_option( '_bp_db_version' ); delete_site_option( 'bp-core-db-version' ); delete_site_option( '_bp-core-db-version' ); // Delete possible blog options delete_blog_option( bp_get_root_blog_id(), 'bp-db-version' ); delete_blog_option( bp_get_root_blog_id(), 'bp-core-db-version' ); delete_site_option( bp_get_root_blog_id(), '_bp-core-db-version' ); delete_site_option( bp_get_root_blog_id(), '_bp_db_version' ); } /** * Add the notifications component to active components. * * Notifications was added in 1.9.0, and previous installations will already * have the core notifications API active. We need to add the new Notifications * component to the active components option to retain existing functionality. * * @since BuddyPress (1.9.0) */ function bp_update_to_1_9() { // Setup hardcoded keys $active_components_key = 'bp-active-components'; $notifications_component_id = 'notifications'; // Get the active components $active_components = bp_get_option( $active_components_key ); // Add notifications if ( ! in_array( $notifications_component_id, $active_components ) ) { $active_components[ $notifications_component_id ] = 1; } // Update the active components option bp_update_option( $active_components_key, $active_components ); } /** * Perform database updates for BP 1.9.2 * * In 1.9, BuddyPress stopped registering its theme directory when it detected * that bp-default (or a child theme) was not currently being used, in effect * deprecating bp-default. However, this ended up causing problems when site * admins using bp-default would switch away from the theme temporarily: * bp-default would no longer be available, with no obvious way (outside of * a manual filter) to restore it. In 1.9.2, we add an option that flags * whether bp-default or a child theme is active at the time of upgrade; if so, * the theme directory will continue to be registered even if the theme is * deactivated temporarily. Thus, new installations will not see bp-default, * but legacy installations using the theme will continue to see it. * * @since BuddyPress (1.9.2) */ function bp_update_to_1_9_2() { if ( 'bp-default' === get_stylesheet() || 'bp-default' === get_template() ) { update_site_option( '_bp_retain_bp_default', 1 ); } } /** * 2.0 update routine. * * - Ensure that the activity tables are installed, for last_activity storage. * - Migrate last_activity data from usermeta to activity table * - Add values for all BuddyPress options to the options table * * @since BuddyPress (2.0.0) */ function bp_update_to_2_0() { /** Install activity tables for 'last_activity' ***************************/ bp_core_install_activity_streams(); /** Migrate 'last_activity' data ******************************************/ bp_last_activity_migrate(); /** Migrate signups data **************************************************/ if ( ! is_multisite() ) { // Maybe install the signups table bp_core_maybe_install_signups(); // Run the migration script bp_members_migrate_signups(); } /** Add BP options to the options table ***********************************/ bp_add_options(); } /** * 2.0.1 database upgrade routine * * @since BuddyPress (2.0.1) * * @return void */ function bp_update_to_2_0_1() { // We purposely call this during both the 2.0 upgrade and the 2.0.1 upgrade. // Don't worry; it won't break anything, and safely handles all cases. bp_core_maybe_install_signups(); } /** * Redirect user to BP's What's New page on first page load after activation. * * @since BuddyPress (1.7.0) * * @internal Used internally to redirect BuddyPress to the about page on activation. * * @uses set_transient() To drop the activation transient for 30 seconds. */ function bp_add_activation_redirect() { // Bail if activating from network, or bulk if ( isset( $_GET['activate-multi'] ) ) return; // Record that this is a new installation, so we show the right // welcome message if ( bp_is_install() ) { set_transient( '_bp_is_new_install', true, 30 ); } // Add the transient to redirect set_transient( '_bp_activation_redirect', true, 30 ); } /** Signups *******************************************************************/ /** * Check if the signups table needs to be created. * * @since BuddyPress (2.0.0) * * @global WPDB $wpdb * * @return bool If signups table exists */ function bp_core_maybe_install_signups() { // Bail if we are explicitly not upgrading global tables if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { return false; } global $wpdb; // The table to run queries against $signups_table = $wpdb->base_prefix . 'signups'; // Suppress errors because users shouldn't see what happens next $old_suppress = $wpdb->suppress_errors(); // Never use bp_core_get_table_prefix() for any global users tables $table_exists = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" ); // Table already exists, so maybe upgrade instead? if ( true === $table_exists ) { // Look for the 'signup_id' column $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" ); // 'signup_id' column doesn't exist, so run the upgrade if ( empty( $column_exists ) ) { bp_core_upgrade_signups(); } // Table does not exist, and we are a single site, so install the multisite // signups table using WordPress core's database schema. } elseif ( ! is_multisite() ) { bp_core_install_signups(); } // Restore previous error suppression setting $wpdb->suppress_errors( $old_suppress ); } /** Activation Actions ********************************************************/ /** * Fire activation hooks and events. * * Runs on BuddyPress activation. * * @since BuddyPress (1.6.0) * * @uses do_action() Calls 'bp_activation' hook. */ function bp_activation() { // Force refresh theme roots. delete_site_transient( 'theme_roots' ); // Add options bp_add_options(); // Use as of (1.6) do_action( 'bp_activation' ); // @deprecated as of (1.6) do_action( 'bp_loader_activate' ); } /** * Fire deactivation hooks and events. * * Runs on BuddyPress deactivation. * * @since BuddyPress (1.6.0) * * @uses do_action() Calls 'bp_deactivation' hook. */ function bp_deactivation() { // Force refresh theme roots. delete_site_transient( 'theme_roots' ); // Switch to WordPress's default theme if current parent or child theme // depend on bp-default. This is to prevent white screens of doom. if ( in_array( 'bp-default', array( get_template(), get_stylesheet() ) ) ) { switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); update_option( 'template_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) ); update_option( 'stylesheet_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) ); } // Use as of (1.6) do_action( 'bp_deactivation' ); // @deprecated as of (1.6) do_action( 'bp_loader_deactivate' ); } /** * Fire uninstall hook. * * Runs when uninstalling BuddyPress. * * @since BuddyPress (1.6.0) * * @uses do_action() Calls 'bp_uninstall' hook. */ function bp_uninstall() { do_action( 'bp_uninstall' ); }