nsive'] ) { return true; } return $condition; } /** * Replace the default field init with custom init. * * @see wp-content/plugins/kirki-dev/packages/kirki-framework/field/src/Field.php * @since 1.0.0 * * @param Object $field The field object. * @param array $args The Kirki field args. * @param string $control_class The control class name if it exists. */ public function field_init( $field, $args, $control_class ) { // Stop if this field doesn't have the "responsive" argument. if ( ! isset( $args['responsive'] ) || ! $args['responsive'] ) { return; } $this->register_real_controls( $field, $args, $control_class ); } /** * Register the real controls. * * @since 1.0.0 * * @param Object $field The field object. * @param array $args The Kirki field args. * @param string $control_class The control class name if it exists. */ public function register_real_controls( $field, $args, $control_class = '' ) { $defaults = $this->parse_default_arg( $args ); $defaults = $defaults['default']; $defaults = array_reverse( $defaults ); $devices = []; $inside_horizontal_layout = property_exists( $field, 'type' ) && in_array( $field->type, $this->horizontal_types, true ) ? true : false; foreach ( $defaults as $device => $value ) { array_push( $devices, $device ); } $devices = array_reverse( $devices ); $devices_control_id = 'kirki_responsive__' . $args['settings']; $loop_count = 0; foreach ( $defaults as $device => $value ) { $loop_count++; if ( ! $inside_horizontal_layout && 1 === $loop_count ) { $this->add_devices_control( $devices_control_id, $args, $devices, $inside_horizontal_layout ); } $new_control_args = $args; $new_control_args['default'] = $value; $new_control_args['settings'] = $args['settings'] . '[' . $device . ']'; $new_control_args['device'] = $device; if ( ! isset( $new_control_args['wrapper_attrs'] ) ) { $new_control_args['wrapper_attrs'] = []; } $new_control_args['wrapper_attrs']['data-kirki-parent-responsive-id'] = $devices_control_id; $new_control_args['wrapper_attrs']['data-kirki-device-preview'] = $device; if ( isset( $new_control_args['label'] ) ) { unset( $new_control_args['label'] ); } if ( isset( $new_control_args['description'] ) ) { unset( $new_control_args['description'] ); } if ( isset( $new_control_args['responsive'] ) ) { unset( $new_control_args['responsive'] ); } $wrapper_class = ''; /** * If `$control_class` is empty, then we assume this is a "parent field" and not the "real controls". * A "parent field" here means: a parent of group of controls such as field-dimensions, field-typography, etc. */ if ( ! $control_class ) { $wrapper_class .= ' customize-control-kirki-hidden-field'; } if ( $inside_horizontal_layout ) { $wrapper_class .= ' customize-control-kirki-responsive-horizontal'; } if ( ! empty( $wrapper_class ) ) { if ( isset( $new_control_args['wrapper_attrs']['class'] ) ) { $new_control_args['wrapper_attrs']['class'] .= $wrapper_class; } else { $new_control_args['wrapper_attrs']['class'] = '{default_class}' . $wrapper_class; } } $new_control_args = $this->parse_output_arg( $new_control_args, $device ); $field_classname = get_class( $field ); new $field_classname( $new_control_args ); if ( $inside_horizontal_layout && count( $devices ) === $loop_count ) { $this->add_devices_control( $devices_control_id, $args, $devices, $inside_horizontal_layout ); } } } /** * Add devices control via $wp_customize. * * @param string $id The control's ID. * @param array $args The control arguments. * @param array $devices The specified devices. * @param bool $inside_horizontal_layout Whether or not this control is inside a horizontal layout. */ public function add_devices_control( $id, $args, $devices, $inside_horizontal_layout = false ) { unset( $args['responsive'] ); if ( isset( $args['default'] ) ) { unset( $args['default'] ); } if ( isset( $args['transport'] ) ) { unset( $args['transport'] ); } if ( isset( $args['output'] ) ) { unset( $args['output'] ); } if ( isset( $args['wrapper_attrs'] ) ) { if ( isset( $args['wrapper_attrs']['data-kirki-parent-responsive-id'] ) ) { unset( $args['wrapper_attrs']['data-kirki-parent-responsive-id'] ); } if ( isset( $args['wrapper_attrs']['data-kirki-device-preview'] ) ) { unset( $args['wrapper_attrs']['data-kirki-device-preview'] ); } } $args['settings'] = $id; $args['type'] = 'kirki-responsive'; if ( ! $inside_horizontal_layout ) { if ( ! isset( $args['wrapper_opts'] ) ) { $args['wrapper_opts'] = []; } $args['wrapper_opts']['gap'] = 'small'; } $args['choices'] = [ 'devices' => $devices, ]; new Responsive( $args ); } /** * Filter the value for responsive fields. * * @see wp-content/plugins/kirki-dev/packages/kirki-framework/data-option/src/Option.php * * @param mixed $value The field value. * @param string $field_name The field name. * @param mixed $default The default value. * @param string $type The option type (theme_mod or option). * * @return mixed The filtered value. */ public function kirki_get_value( $value = '', $field_name = '', $default = '', $type = 'theme_mod' ) { /** * The "option" will be handled by "kirki_get_value" method in * wp-content/plugins/kirki-dev/packages/kirki-framework/data-option/src/Option.php file. */ if ( 'option' === $type ) { return $value; } // If the field name doesn't contain a '[', then it's not a sub-item of another field. if ( false === strpos( $field_name, '[' ) ) { return $value; } // If this is not part of a responsive field, then return the value. if ( ! in_array( $field_name, Responsive::$sub_field_names, true ) ) { return $value; } /** * If we got here then this is part of an option array. * We need to get the 1st level, and then find the item inside that array. */ $parts = \explode( '[', $field_name ); $value = get_theme_mod( $parts[0], [] ); foreach ( $parts as $key => $part ) { /** * Skip the 1st item, it's already been dealt with * when we got the value initially right before this loop. */ if ( 0 === $key ) { continue; } $part = str_replace( ']', '', $part ); /** * If the item exists in the value, then change $value to the item. * This runs recursively for all parts until we get to the end. */ if ( is_array( $value ) && isset( $value[ $part ] ) ) { $value = $value[ $part ]; continue; } /** * If we got here, the item was not found in the value. * We need to change the value accordingly depending on whether * this is the last item in the loop or not. */ $value = ( isset( $parts[ $key + 1 ] ) ) ? [] : ''; } $value = empty( $value ) ? $default : $value; return $value; } } Shop - NPS-Machines d'impression maroc