array( 'title' => __( 'Extended Profiles', 'buddypress' ), 'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' ), ), 'settings' => array( 'title' => __( 'Account Settings', 'buddypress' ), 'description' => __( 'Allow your users to modify their account and notification settings directly from within their profiles.', 'buddypress' ), ), 'notifications' => array( 'title' => __( 'Notifications', 'buddypress' ), 'description' => __( 'Notify members of relevant activity with a toolbar bubble and/or via email, and allow them to customize their notification settings.', 'buddypress' ), ), ); $optional_components = bp_core_admin_get_components( 'optional' ); $required_components = bp_core_admin_get_components( 'required' ); $retired_components = bp_core_admin_get_components( 'retired' ); // Merge optional and required together. $all_components = $optional_components + $required_components; // If this is an upgrade from before BuddyPress 1.5, we'll have to convert // deactivated components into activated ones. if ( empty( $active_components ) ) { $deactivated_components = bp_get_option( 'bp-deactivated-components' ); if ( ! empty( $deactivated_components ) ) { // Trim off namespace and filename. $trimmed = array(); foreach ( array_keys( (array) $deactivated_components ) as $component ) { $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) ); } // Loop through the optional components to create an active component array. foreach ( array_keys( (array) $optional_components ) as $ocomponent ) { if ( ! in_array( $ocomponent, $trimmed, true ) ) { $active_components[ $ocomponent ] = 1; } } } } // On new install, set active components to default. if ( empty( $active_components ) ) { $active_components = $default_components; } // Core component is always active. $active_components['core'] = $all_components['core']; $inactive_components = array_diff( array_keys( $all_components ), array_keys( $active_components ) ); /** Display ************************************************************** */ // Get the total count of all plugins. $all_count = count( $all_components ); $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php'; $action = ! empty( $_GET['action'] ) ? $_GET['action'] : 'all'; switch ( $action ) { case 'all': $current_components = $all_components; break; case 'active': foreach ( array_keys( $active_components ) as $component ) { $current_components[ $component ] = $all_components[ $component ]; } break; case 'inactive': foreach ( $inactive_components as $component ) { $current_components[ $component ] = $all_components[ $component ]; } break; case 'mustuse': $current_components = $required_components; break; case 'retired': $current_components = $retired_components; break; } $component_views = array( array( 'action' => 'all', 'view' => sprintf( /* translators: %s: the number of installed components */ _nx( 'All (%s)', 'All (%s)', $all_count, 'plugins', 'buddypress' ), number_format_i18n( $all_count ) ), ), array( 'action' => 'active', 'view' => sprintf( /* translators: %s: the number of active components */ _n( 'Active (%s)', 'Active (%s)', count( $active_components ), 'buddypress' ), number_format_i18n( count( $active_components ) ) ), ), array( 'action' => 'inactive', 'view' => sprintf( /* translators: %s: the number of inactive components */ _n( 'Inactive (%s)', 'Inactive (%s)', count( $inactive_components ), 'buddypress' ), number_format_i18n( count( $inactive_components ) ) ), ), array( 'action' => 'mustuse', 'view' => sprintf( /* translators: %s: the number of must-Use components */ _n( 'Must-Use (%s)', 'Must-Use (%s)', count( $required_components ), 'buddypress' ), number_format_i18n( count( $required_components ) ) ), ), array( 'action' => 'retired', 'view' => sprintf( /* translators: %s: the number of retired components */ _n( 'Retired (%s)', 'Retired (%s)', count( $retired_components ), 'buddypress' ), number_format_i18n( count( $retired_components ) ) ), ), ); $component_anchor_url = function ( $component_action, $component_view ) use ( $page, $action ) { $component_url = add_query_arg( array( 'page' => 'bp-components', 'action' => $component_action, ), bp_get_admin_url( $page ) ); $css = $component_action === $action ? 'class="current"' : ''; return sprintf( '%s', esc_url( $component_url ), $css, wp_kses( $component_view, array( 'span' => array( 'class' => true ) ) ) ); } ?>

$labels ) : ?>
>
" name="" value="1" />

array( 'href' => true, ), 'del' => true, 'span' => array( 'class' => true, ), ) ); ?>

>
plugin_dir . '/bp-core/admin/bp-core-admin-schema.php'; $submitted = wp_unslash( $_POST['bp_components'] ); $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $submitted ); bp_core_install( $bp->active_components ); bp_core_add_page_mappings( $bp->active_components ); bp_update_option( 'bp-active-components', $bp->active_components ); // Force permalinks to be refreshed at next page load if one of the components is using a directory page. if ( array_intersect_key( $bp->active_components, bp_core_get_directory_page_ids( 'active' ) ) ) { bp_delete_rewrite_rules(); } } // Where are we redirecting to? $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'updated' => 'true', ), 'admin.php' ) ); // Redirect. wp_safe_redirect( $base_url ); exit; } add_action( 'bp_admin_init', 'bp_core_admin_components_settings_handler' ); /** * Calculates the components that should be active after save, based on submitted settings. * * The way that active components must be set after saving your settings must * be calculated differently depending on which of the Components subtabs you * are coming from: * - When coming from All or Active, the submitted checkboxes accurately * reflect the desired active components, so we simply pass them through * - When coming from Inactive, components can only be activated - already * active components will not be passed in the $_POST global. Thus, we must * parse the newly activated components with the already active components * saved in the $bp global * - When activating a Retired component, the situation is similar to Inactive. * - When deactivating a Retired component, no value is passed in the $_POST * global (because the component settings are checkboxes). So, in order to * determine whether a retired component is being deactivated, we retrieve a * list of retired components, and check each one to ensure that its checkbox * is not present, before merging the submitted components with the active * ones. * * @since 1.7.0 * * @param array $submitted This is the array of component settings coming from the POST * global. You should wp_unslash() before passing to this function. * @return array The calculated list of component settings */ function bp_core_admin_get_active_components_from_submitted_settings( $submitted ) { $current_action = 'all'; if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'active', 'inactive', 'retired' ), true ) ) { $current_action = $_GET['action']; } $current_components = buddypress()->active_components; $submitted = array_filter( (array) $submitted, function ( $value, $key ) { return is_string( $key ) && is_numeric( $value ); }, ARRAY_FILTER_USE_BOTH ); switch ( $current_action ) { case 'retired': $retired_components = bp_core_admin_get_components( 'retired' ); foreach ( array_keys( $retired_components ) as $retired_component ) { if ( ! isset( $submitted[ $retired_component ] ) ) { unset( $current_components[ $retired_component ] ); } } // Fall through. case 'inactive': $components = array_merge( $submitted, $current_components ); break; case 'all': case 'active': default: $components = $submitted; break; } return $components; } /** * Return a list of component information. * * We use this information both to build the markup for the admin screens, as * well as to do some processing on settings data submitted from those screens. * * @since 1.7.0 * * @param string $type Optional; Component type to fetch. Defaults to 'all'. * Possible values include 'all', 'optional', 'retired', and 'required'. * @return array Requested components' data. */ function bp_core_admin_get_components( $type = 'all' ) { $components = bp_core_get_components( $type ); /** * Filters the list of component information. * * @since 2.0.0 * * @param array $components Array of component information. * @param string $type Type of component list requested. * Possible values include 'all', 'optional', * 'retired', and 'required'. */ return apply_filters( 'bp_core_admin_get_components', $components, $type ); }