mirror of
https://ghproxy.net/https://github.com/AlxMedia/curver.git
synced 2025-08-28 09:25:45 +08:00
Update to Kirki 4.2.0
This commit is contained in:
parent
cbfd4f27e4
commit
77ecd4ca69
440 changed files with 6230 additions and 5211 deletions
21
functions/kirki/kirki-packages/field-multicolor/LICENSE
Normal file
21
functions/kirki/kirki-packages/field-multicolor/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 kirki-framework
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* Handles CSS output for multicolor fields.
|
||||
*
|
||||
* @package Kirki
|
||||
* @subpackage Controls
|
||||
* @copyright Copyright (c) 2023, Themeum
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 2.2.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Field\CSS;
|
||||
|
||||
use Kirki\Module\CSS\Output;
|
||||
|
||||
/**
|
||||
* Output overrides.
|
||||
*/
|
||||
class Multicolor extends Output {
|
||||
|
||||
/**
|
||||
* Processes a single item from the `output` array.
|
||||
*
|
||||
* @access protected
|
||||
* @param array $output The `output` item.
|
||||
* @param array $value The field's value.
|
||||
*/
|
||||
protected function process_output( $output, $value ) {
|
||||
|
||||
foreach ( $value as $key => $sub_value ) {
|
||||
|
||||
// If "element" is not defined, there's no reason to continue.
|
||||
if ( ! isset( $output['element'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the "choice" is not the same as the $key in our loop, there's no reason to proceed.
|
||||
if ( isset( $output['choice'] ) && $key !== $output['choice'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If "property" is not defined, fallback to the $key.
|
||||
$property = ( ! isset( $output['property'] ) || empty( $output['property'] ) ) ? $key : $output['property'];
|
||||
|
||||
// If "media_query" is not defined, use "global".
|
||||
if ( ! isset( $output['media_query'] ) || empty( $output['media_query'] ) ) {
|
||||
$output['media_query'] = 'global';
|
||||
}
|
||||
|
||||
// If "suffix" is defined, add it to the value.
|
||||
$output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
|
||||
|
||||
// Create the styles.
|
||||
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $sub_value . $output['suffix'];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
/**
|
||||
* Override field methods
|
||||
*
|
||||
* @package kirki-framework/control-multicolor
|
||||
* @copyright Copyright (c) 2023, Themeum
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Field;
|
||||
|
||||
use Kirki\Field;
|
||||
|
||||
/**
|
||||
* Field overrides.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Multicolor extends Field {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'kirki-multicolor';
|
||||
|
||||
/**
|
||||
* Extra logic for the field.
|
||||
*
|
||||
* Adds all sub-fields.
|
||||
*
|
||||
* @access public
|
||||
* @param array $args The arguments of the field.
|
||||
*/
|
||||
public function init( $args ) {
|
||||
|
||||
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
|
||||
|
||||
$parent_control_args = wp_parse_args(
|
||||
[
|
||||
'type' => 'kirki-generic',
|
||||
'default' => '',
|
||||
'wrapper_opts' => [
|
||||
'gap' => 'small',
|
||||
],
|
||||
'input_attrs' => '',
|
||||
'choices' => [
|
||||
'type' => 'hidden',
|
||||
'parent_type' => 'kirki-multicolor',
|
||||
],
|
||||
'sanitize_callback' => [ __CLASS__, 'sanitize' ],
|
||||
],
|
||||
$args
|
||||
);
|
||||
|
||||
/**
|
||||
* Add a hidden field, the label & description.
|
||||
*/
|
||||
new \Kirki\Field\Generic( $parent_control_args );
|
||||
|
||||
$total_colors = count( $args['choices'] );
|
||||
$loop_index = 0;
|
||||
|
||||
$use_alpha = $this->filter_preferred_choice_setting( 'alpha', null, $args ) ? true : false;
|
||||
$swatches = $this->filter_preferred_choice_setting( 'swatches', null, $args );
|
||||
$swatches = empty( $swatches ) ? $this->filter_preferred_choice_setting( 'palettes', null, $args ) : $swatches;
|
||||
$swatches = empty( $swatches ) ? [] : $swatches;
|
||||
|
||||
if ( empty( $swatches ) ) {
|
||||
$swatches = isset( $args['palettes'] ) && ! empty( $args['palettes'] ) ? $args['palettes'] : [];
|
||||
}
|
||||
|
||||
foreach ( $args['choices'] as $choice => $choice_label ) {
|
||||
$loop_index++;
|
||||
|
||||
$classnames = '{default_class} kirki-group-item';
|
||||
$classnames .= 1 === $loop_index ? ' kirki-group-start' : ( $loop_index === $total_colors ? ' kirki-group-end' : $classnames );
|
||||
|
||||
$use_alpha_per_choice = $this->filter_preferred_choice_setting( 'alpha', $choice, $args ) ? true : $use_alpha;
|
||||
$swatches_per_choice = $this->filter_preferred_choice_setting( 'swatches', $choice, $args );
|
||||
$swatches_per_choice = empty( $swatches_per_choice ) ? $this->filter_preferred_choice_setting( 'palettes', $choice, $args ) : $swatches_per_choice;
|
||||
$swatches_per_choice = empty( $swatches_per_choice ) ? $swatches : $swatches_per_choice;
|
||||
|
||||
$control_args = wp_parse_args(
|
||||
[
|
||||
'settings' => $args['settings'] . '[' . $choice . ']',
|
||||
'parent_setting' => $args['settings'],
|
||||
'label' => $choice_label,
|
||||
'description' => '',
|
||||
'default' => $this->filter_preferred_choice_setting( 'default', $choice, $args ),
|
||||
'wrapper_attrs' => [
|
||||
'data-kirki-parent-control-type' => 'kirki-multicolor',
|
||||
'class' => $classnames,
|
||||
],
|
||||
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $choice, $args ),
|
||||
'choices' => [
|
||||
'alpha' => $use_alpha_per_choice,
|
||||
'label_style' => 'tooltip',
|
||||
'swatches' => $swatches_per_choice,
|
||||
],
|
||||
'css_vars' => [],
|
||||
'output' => [],
|
||||
],
|
||||
$args
|
||||
);
|
||||
|
||||
foreach ( $control_args['choices'] as $control_choice_id => $control_choice_value ) {
|
||||
if ( isset( $control_args[ $control_choice_id ] ) ) {
|
||||
unset( $control_args[ $control_choice_id ] );
|
||||
} else {
|
||||
if ( 'swatches' === $control_choice_id || 'palettes' === $control_choice_id ) {
|
||||
if ( isset( $control_args['palettes'] ) ) {
|
||||
unset( $control_args['palettes'] );
|
||||
}
|
||||
|
||||
if ( isset( $control_args['swatches'] ) ) {
|
||||
unset( $control_args['swatches'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new \Kirki\Field\ReactColorful( $control_args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer control specific value over field value
|
||||
*
|
||||
* @access public
|
||||
* @since 4.0
|
||||
*
|
||||
* @param string $setting The argument key inside $args.
|
||||
* @param string $choice The choice key inside $args['choices'].
|
||||
* @param array $args The arguments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
|
||||
|
||||
// Fail early.
|
||||
if ( ! isset( $args[ $setting ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( null === $choice ) {
|
||||
$per_choice_found = false;
|
||||
|
||||
foreach ( $args['choices'] as $choice_id => $choice_label ) {
|
||||
if ( isset( $args[ $setting ][ $choice_id ] ) ) {
|
||||
$per_choice_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $per_choice_found ) {
|
||||
return $args[ $setting ];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// If a specific field for the choice is set.
|
||||
if ( isset( $args[ $setting ][ $choice ] ) ) {
|
||||
return $args[ $setting ][ $choice ];
|
||||
}
|
||||
|
||||
// Unset all other choices.
|
||||
foreach ( $args['choices'] as $id => $set ) {
|
||||
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
|
||||
unset( $args[ $setting ][ $id ] );
|
||||
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
|
||||
$args[ $setting ] = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $args[ $setting ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter arguments before creating the setting.
|
||||
*
|
||||
* @access public
|
||||
* @since 0.1
|
||||
* @param array $args The field arguments.
|
||||
* @param WP_Customize_Manager $wp_customize The customizer instance.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_setting_args( $args, $wp_customize ) {
|
||||
|
||||
if ( $args['settings'] !== $this->args['settings'] ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
// Set the sanitize-callback if none is defined.
|
||||
if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
|
||||
$args['sanitize_callback'] = [ __CLASS__, 'sanitize' ];
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes background controls
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param array $value The value.
|
||||
* @return array
|
||||
*/
|
||||
public static function sanitize( $value ) {
|
||||
|
||||
foreach ( $value as $key => $subvalue ) {
|
||||
$value[ $key ] = \Kirki\Field\Color::sanitize( $subvalue );
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent method. No need to register any setting.
|
||||
*
|
||||
* @access public
|
||||
* @since 0.1
|
||||
* @param WP_Customize_Manager $wp_customize The customizer instance.
|
||||
* @return void
|
||||
*/
|
||||
public function add_setting( $wp_customize ) {}
|
||||
|
||||
/**
|
||||
* Override the parent method. No need for a control.
|
||||
*
|
||||
* @access public
|
||||
* @since 0.1
|
||||
* @param WP_Customize_Manager $wp_customize The customizer instance.
|
||||
* @return void
|
||||
*/
|
||||
public function add_control( $wp_customize ) {}
|
||||
|
||||
/**
|
||||
* Adds a custom output class for typography fields.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param array $classnames The array of classnames.
|
||||
* @return array
|
||||
*/
|
||||
public function output_control_classnames( $classnames ) {
|
||||
$classnames['kirki-multicolor'] = '\Kirki\Field\CSS\Multicolor';
|
||||
return $classnames;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue