eta_key' => 'allow_custom_visibility', 'meta_value' => 'disabled' ), array( '%d', '%s', '%s', '%s' ) ); bp_core_install_invitations(); if ( bp_is_active( 'groups' ) ) { bp_groups_migrate_invitations(); } } /** * 8.0.0 update routine. * * - Edit the `new_avatar` activity type's component to `members`. * - Upgrade Primary xProfile Group's fields to signup fields. * * @since 8.0.0 */ function bp_update_to_8_0() { global $wpdb; $bp_prefix = bp_core_get_table_prefix(); // Install welcome email to email list. add_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' ); bp_core_install_emails(); remove_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' ); // Update the `new_avatar` activity type's component to `members`. $wpdb->update( $bp_prefix . 'bp_activity', array( 'component' => 'members', ), array( 'type' => 'new_avatar', ), array( '%s', ), array( '%s', ) ); // Check if we need to create default signup fields. $field_id = bp_get_fullname_field_id_for_update(); $has_signup_position = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$bp_prefix}bp_xprofile_meta WHERE meta_key = 'signup_position' AND object_type = 'field' AND object_id = %d", $field_id ) ); if ( bp_get_signup_allowed() && ! $has_signup_position ) { // Get the Primary Group's fields. $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" ); // Migrate potential signup fields. if ( $signup_fields ) { $signup_position = 0; foreach ( $signup_fields as $signup_field_id ) { $signup_position += 1; $wpdb->insert( $bp_prefix . 'bp_xprofile_meta', array( 'object_id' => $signup_field_id, 'object_type' => 'field', 'meta_key' => 'signup_position', 'meta_value' => $signup_position, ), array( '%d', '%s', '%s', '%d', ) ); } } } bp_core_install_nonmember_opt_outs(); } /** * Select only the emails that need to be installed with version 8.0. * * @since 8.0.0 * * @param array $emails The array of emails schema. */ function bp_core_get_8_0_upgrade_email_schema( $emails ) { $new_emails = array(); if ( isset( $emails['core-user-activation'] ) ) { $new_emails['core-user-activation'] = $emails['core-user-activation']; } if ( isset( $emails['bp-members-invitation'] ) ) { $new_emails['bp-members-invitation'] = $emails['bp-members-invitation']; } return $new_emails; } /** * 10.0.0 update routine. * * - Install new BP Emails for membership requests. * * @since 10.0.0 */ function bp_update_to_10_0() { // Install membership request emails. add_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' ); bp_core_install_emails(); remove_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' ); } /** * Select only the emails that need to be installed with version 10.0. * * @since 10.0.0 * * @param array $emails The array of emails schema. */ function bp_core_get_10_0_upgrade_email_schema( $emails ) { $new_emails = array(); if ( isset( $emails['members-membership-request'] ) ) { $new_emails['members-membership-request'] = $emails['members-membership-request']; } if ( isset( $emails['members-membership-request-rejected'] ) ) { $new_emails['members-membership-request-rejected'] = $emails['members-membership-request-rejected']; } return $new_emails; } /** * 11.0.0 update routine. * * - Install new BP Emails for group membership requests which is completed by admin. * * @since 11.0.0 */ function bp_update_to_11_0() { bp_delete_option( '_bp_ignore_deprecated_code' ); add_filter( 'bp_email_get_schema', 'bp_core_get_11_0_upgrade_email_schema' ); bp_core_install_emails(); remove_filter( 'bp_email_get_schema', 'bp_core_get_11_0_upgrade_email_schema' ); } /** * Select only the emails that need to be installed with version 11.0. * * @since 11.0.0 * * @param array $emails The array of emails schema. */ function bp_core_get_11_0_upgrade_email_schema( $emails ) { $new_emails = array(); if ( isset( $emails['groups-membership-request-accepted-by-admin'] ) ) { $new_emails['groups-membership-request-accepted-by-admin'] = $emails['groups-membership-request-accepted-by-admin']; } if ( isset( $emails['groups-membership-request-rejected-by-admin'] ) ) { $new_emails['groups-membership-request-rejected-by-admin'] = $emails['groups-membership-request-rejected-by-admin']; } return $new_emails; } /** * 11.4.0 update routine. * * @since 11.4.0 */ function bp_update_to_11_4() { $unread = array( 'bp114-prepare-for-rewrites' ); // Check if 10.0 notice was dismissed. $old_dismissed = (bool) bp_get_option( 'bp-dismissed-notice-bp100-welcome-addons', false ); if ( ! $old_dismissed ) { $unread[] = 'bp100-welcome-addons'; } // Remove the dismissible option. bp_delete_option( 'bp-dismissed-notice-bp100-welcome-addons' ); // Create unread Admin notifications. bp_update_option( 'bp_unread_admin_notifications', $unread ); } /** * 12.0.0 update routine. * * - Swith directory page post type from "page" to "buddypress". * - Remove Legacy Widgets option. * - Add the default community visibility value. * * @since 12.0.0 */ function bp_update_to_12_0() { /* * Only perform the BP Rewrites API & Legacy Widgets upgrade tasks * when the BP Classic plugin is not active. */ if ( ! function_exists( 'bp_classic' ) ) { $post_type = bp_core_get_directory_post_type(); if ( 'page' !== $post_type ) { $directory_pages = bp_core_get_directory_pages(); $nav_menu_item_ids = array(); // Do not check post slugs nor post types. remove_filter( 'wp_unique_post_slug', 'bp_core_set_unique_directory_page_slug', 10 ); // Update Directory pages post types. foreach ( $directory_pages as $directory_page ) { $nav_menu_item_ids[] = $directory_page->id; // Switch the post type. wp_update_post( array( 'ID' => $directory_page->id, 'post_type' => $post_type, 'post_status' => 'publish', ) ); } // Update nav menu items! $nav_menus = wp_get_nav_menus( array( 'hide_empty' => true ) ); foreach ( $nav_menus as $nav_menu ) { $items = wp_get_nav_menu_items( $nav_menu->term_id ); foreach ( $items as $item ) { if ( 'page' !== $item->object || ! in_array( $item->object_id, $nav_menu_item_ids, true ) ) { continue; } wp_update_nav_menu_item( $nav_menu->term_id, $item->ID, array( 'menu-item-db-id' => $item->db_id, 'menu-item-object-id' => $item->object_id, 'menu-item-object' => $post_type, 'menu-item-parent-id' => $item->menu_item_parent, 'menu-item-position' => $item->menu_order, 'menu-item-type' => 'post_type', 'menu-item-title' => $item->title, 'menu-item-url' => $item->url, 'menu-item-description' => $item->description, 'menu-item-attr-title' => $item->attr_title, 'menu-item-target' => $item->target, 'menu-item-classes' => implode( ' ', (array) $item->classes ), 'menu-item-xfn' => $item->xfn, 'menu-item-status' => 'publish', ) ); } } // Force permalinks to be refreshed at next page load. bp_delete_rewrite_rules(); } // Widgets. $widget_options = array( 'widget_bp_core_login_widget', 'widget_bp_core_members_widget', 'widget_bp_core_whos_online_widget', 'widget_bp_core_recently_active_widget', 'widget_bp_groups_widget', 'widget_bp_messages_sitewide_notices_widget', ); foreach ( $widget_options as $widget_option ) { bp_delete_option( $widget_option ); } } // Community visibility. bp_update_option( '_bp_community_visibility', array( 'global' => 'anyone' ) ); /** * Fires once BuddyPress achieved 12.0 upgrading tasks. * * @since 12.0.0 */ do_action( 'bp_updated_to_12_0' ); } /** * Updates the component field for new_members type. * * @since 2.2.0 * * @global wpdb $wpdb WordPress database object. */ function bp_migrate_new_member_activity_component() { global $wpdb; $bp = buddypress(); // Update the component for the new_member type. $wpdb->update( // Activity table. $bp->members->table_name_last_activity, array( 'component' => $bp->members->id, ), array( 'component' => 'xprofile', 'type' => 'new_member', ), // Data sanitization format. array( '%s', ), // WHERE sanitization format. array( '%s', '%s' ) ); } /** * Remove all hidden friendship activities. * * @since 2.2.0 */ function bp_cleanup_friendship_activities() { bp_activity_delete( array( 'component' => buddypress()->friends->id, 'type' => 'friendship_created', 'hide_sitewide' => true, ) ); } /** * Update WP pages so that their post_title matches the legacy component directory title. * * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object, * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these * WP posts with the formerly hardcoded titles. * * @since 2.7.0 */ function bp_migrate_directory_page_titles() { $bp_pages = bp_core_get_directory_page_ids( 'all' ); $default_titles = bp_core_get_directory_page_default_titles(); $legacy_titles = array( 'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ), 'blogs' => _x( 'Sites', 'component directory title', 'buddypress' ), 'groups' => _x( 'Groups', 'component directory title', 'buddypress' ), 'members' => _x( 'Members', 'component directory title', 'buddypress' ), ); foreach ( $bp_pages as $component => $page_id ) { if ( ! isset( $legacy_titles[ $component ] ) ) { continue; } $page = get_post( $page_id ); if ( ! $page ) { continue; } // If the admin has changed the default title, don't touch it. if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) { continue; } // If the saved page title is the same as the legacy title, there's nothing to do. if ( $legacy_titles[ $component ] == $page->post_title ) { continue; } // Update the page with the legacy title. wp_update_post( array( 'ID' => $page_id, 'post_title' => $legacy_titles[ $component ], ) ); } } /** * Redirect user to BP's What's New page on first page load after activation. * * @since 1.7.0 * * @internal Used internally to redirect BuddyPress to the about page on activation. */ 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 or upgraded. * * @since 2.0.0 * * @global wpdb $wpdb WordPress database object. */ function bp_core_maybe_install_signups() { 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 1.6.0 */ function bp_activation() { // Force refresh theme roots. delete_site_transient( 'theme_roots' ); // Add options. bp_add_options(); /** * Fires during the activation of BuddyPress. * * Use as of 1.6.0. * * @since 1.6.0 */ do_action( 'bp_activation' ); // @deprecated as of 1.6.0 do_action( 'bp_loader_activate' ); } /** * Fire deactivation hooks and events. * * Runs on BuddyPress deactivation. * * @since 1.6.0 */ function bp_deactivation() { /** * Fires during the deactivation of BuddyPress. * * Use as of 1.6.0. * * @since 1.6.0 */ do_action( 'bp_deactivation' ); // @deprecated as of 1.6.0 do_action_deprecated( 'bp_loader_deactivate', array(), '1.6.0' ); } /** * Fire uninstall hook. * * Runs when uninstalling BuddyPress. * * @since 1.6.0 */ function bp_uninstall() { /** * Fires during the uninstallation of BuddyPress. * * @since 1.6.0 */ do_action( 'bp_uninstall' ); }