public static final function mixinFactory($name, $config = array())
 {
     $mixins = CS()->config('controls/mixins');
     $type = $config['mixin'];
     unset($config['mixin']);
     if (!isset($mixins[$type])) {
         return new WP_Error('cornerstone', "Mixin '{$type}' not found.");
     }
     // Set a maximium merge depth. This allows top level keys to be merged,
     // but allows full arrays to be overriden at the control option level.
     $depth = 3;
     // For groups, we need an additional level of merge depth
     if (isset($config['group']) && $config['group'] === true || isset($mixins[$type]['group']) && $mixins[$type]['group'] === true) {
         $depth = 4;
     }
     return self::factory($name, cs_deep_array_merge($config, $mixins[$type], $depth));
 }
Ejemplo n.º 2
0
function cs_deep_array_merge(array &$defaults, array $data, $max_depth = -1)
{
    if ($max_depth-- == 1) {
        return $defaults;
    }
    foreach ($defaults as $key => &$value) {
        if (isset($data[$key]) && is_array($value) && is_array($data[$key])) {
            $data[$key] = cs_deep_array_merge($value, $data[$key], $max_depth);
            continue;
        }
        $data[$key] = $value;
    }
    return $data;
}