コード例 #1
0
/**
 * 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.
        // Fall through.
        case 'inactive':
            $components = array_merge($submitted, $current_components);
            break;
        case 'all':
        case 'active':
        default:
            $components = $submitted;
            break;
    }
    return $components;
}
コード例 #2
0
 public static function check_bp_active_components($old_value, $new_value)
 {
     $options = array();
     if (!is_array($old_value) || !is_array($new_value)) {
         return;
     }
     foreach (self::get_changed_keys($old_value, $new_value, 0) as $field_key => $field_value) {
         $options[$field_key] = $field_value;
     }
     $components = bp_core_admin_get_components();
     $actions = array(true => __('activated', 'stream'), false => __('deactivated', 'stream'));
     foreach ($options as $option => $option_value) {
         if (!isset($components[$option], $actions[$option_value])) {
             continue;
         }
         self::log(sprintf(__('"%1$s" component %2$s', 'stream'), $components[$option]['title'], $actions[$option_value]), array('option' => $option, 'option_key' => 'bp-active-components', 'old_value' => maybe_serialize($old_value), 'value' => maybe_serialize($new_value)), null, 'components', $option_value ? 'activated' : 'deactivated');
     }
 }