plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
$submitted = stripslashes_deep( $_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 );
}
// Where are we redirecting to?
$base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'updated' => 'true' ), 'admin.php' ) );
// Redirect.
wp_redirect( $base_url );
die();
}
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 stripslashes_deep() 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' ) ) ) {
$current_action = $_GET['action'];
}
$current_components = buddypress()->active_components;
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. Default value is 'all', or 'optional', 'retired', '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', 'required'.
*/
return apply_filters( 'bp_core_admin_get_components', $components, $type );
}