Update to Kirki 4.0.22

This commit is contained in:
AlxMedia 2022-03-15 14:25:47 +01:00
parent 89e6987b0a
commit 0d1a321554
492 changed files with 29668 additions and 39884 deletions

View file

@ -0,0 +1,110 @@
<?php
/**
* Customizer Control: kirki-generic.
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Control;
use Kirki\Control\Base;
use Kirki\URL;
/**
* A generic and pretty abstract control.
* Allows for great manipulation using the field's "choices" argumnent.
*
* @since 1.0
*/
class Generic extends Base {
/**
* The control type.
*
* @access public
* @var string
*/
public $type = 'kirki-generic';
/**
* The version. Used in scripts & styles for cache-busting.
*
* @static
* @access public
* @since 1.0
* @var string
*/
public static $control_ver = '1.0.2';
/**
* Enqueue control related scripts/styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue() {
parent::enqueue();
// Enqueue the script.
wp_enqueue_script( 'kirki-control-generic', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
}
/**
* An Underscore (JS) template for this control's content (but not its container).
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*
* @access protected
* @since 1.1
* @return void
*/
protected function content_template() {
?>
<label class="customize-control-label" for="{{ ! data.choices.id ? 'customize-input-' + data.id : data.choices.id }}">
<span class="customize-control-title">{{{ data.label }}}</span>
<# if ( data.description ) { #>
<span class="description customize-control-description">{{{ data.description }}}</span>
<# } #>
</label>
<div class="kirki-control-form">
<# element = ( data.choices.element ) ? data.choices.element : 'input'; #>
<# if ( 'textarea' === element ) { #>
<textarea
{{{ data.inputAttrs }}}
{{ data.link.replace(/"/g, '') }}
<# if ( ! data.choices.id ) { #>
id="{{'customize-input-' + data.id}}"
<# } #>
<# _.each( data.choices, function( val, key ) { #>
{{ key }}="{{ val }}"
<# }); #>
>{{{ data.value }}}</textarea>
<# } else { #>
<{{ element }}
{{{ data.inputAttrs }}}
value="{{ data.value }}"
{{ data.link.replace(/"/g, '') }}
<# if ( ! data.choices.id ) { #>
id="{{'customize-input-' + data.id}}"
<# } #>
<# _.each( data.choices, function( val, key ) { #>
{{ key }}="{{ val }}"
<# } ); #>
<# if ( data.choices.content ) { #>>{{{ data.choices.content }}}</{{ element }}><# } else { #>/><# } #>
<# } #>
</div>
<?php
}
}

View file

@ -0,0 +1,98 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Field;
/**
* Field overrides.
*
* @since 1.0
*/
class Generic extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-generic';
/**
* The control class-name.
*
* @access protected
* @since 0.1
* @var string
*/
protected $control_class = '\Kirki\Control\Generic';
/**
* Whether we should register the control class for JS-templating or not.
*
* @access protected
* @since 0.1
* @var bool
*/
protected $control_has_js_template = true;
/**
* 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'] ) {
$args = parent::filter_setting_args( $args, $wp_customize );
// Set the sanitize-callback if none is defined.
if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
$args['sanitize_callback'] = 'wp_kses_post';
}
}
return $args;
}
/**
* Filter arguments before creating the control.
*
* @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_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_control_args( $args, $wp_customize );
// Set the control-type.
$args['type'] = 'kirki-generic';
// Choices.
$args['choices'] = isset( $args['choices'] ) ? $args['choices'] : [];
$args['choices']['element'] = isset( $args['choices']['element'] ) ? $args['choices']['element'] : 'input';
}
return $args;
}
}

View file

@ -0,0 +1,110 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
/**
* Field overrides.
*
* @since 1.0
*/
class Number extends Generic {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-number';
/**
* 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'] = function( $value ) use ( $args ) {
$value = filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
if ( isset( $args['choices'] ) && isset( $args['choices']['min'] ) && isset( $args['choices']['max'] ) ) {
// Make sure min & max are all numeric.
$min = filter_var( $args['choices']['min'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$max = filter_var( $args['choices']['max'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
if ( $value < $min ) {
$value = $min;
} elseif ( $value > $max ) {
$value = $max;
}
}
return $value;
};
}
return $args;
}
/**
* Filter arguments before creating the control.
*
* @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_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_control_args( $args, $wp_customize );
// Set the control-type.
$args['type'] = 'kirki-generic';
// Choices.
$args['choices'] = isset( $args['choices'] ) ? $args['choices'] : [];
$args['choices']['element'] = 'input';
$args['choices']['type'] = 'number';
$args['choices'] = wp_parse_args(
$args['choices'],
[
'min' => -999999999,
'max' => 999999999,
'step' => 1,
]
);
// Make sure min, max & step are all numeric.
$args['choices']['min'] = filter_var( $args['choices']['min'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$args['choices']['max'] = filter_var( $args['choices']['max'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$args['choices']['step'] = filter_var( $args['choices']['step'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
}
return $args;
}
}

View file

@ -0,0 +1,73 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
/**
* Field overrides.
*
* @since 1.0
*/
class Text extends Generic {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-text';
/**
* 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'] ) {
$args = parent::filter_setting_args( $args, $wp_customize );
// Set the sanitize-callback if none is defined.
if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
$args['sanitize_callback'] = 'sanitize_textarea_field'; // ? Bagus: should we use `sanitize_text_field` instead ?
}
}
return $args;
}
/**
* Filter arguments before creating the control.
*
* @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_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_control_args( $args, $wp_customize );
// Set the control-type.
$args['type'] = 'kirki-generic';
// Choices.
$args['choices'] = isset( $args['choices'] ) ? $args['choices'] : [];
$args['choices']['element'] = 'input';
$args['choices']['type'] = 'text';
}
return $args;
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
/**
* Field overrides.
*/
class Textarea extends Generic {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-textarea';
/**
* Filter arguments before creating the control.
*
* @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_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_control_args( $args, $wp_customize );
// Set the control-type.
$args['type'] = 'kirki-generic';
// Choices.
$args['choices'] = isset( $args['choices'] ) ? $args['choices'] : [];
$args['choices']['element'] = 'textarea';
$args['choices']['rows'] = '5';
}
return $args;
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
/**
* Field overrides.
*
* @since 1.0
*/
class URL extends Text {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-url';
/**
* 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'] ) {
$args = parent::filter_setting_args( $args, $wp_customize );
// Set the sanitize-callback if none is defined.
if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
$args['sanitize_callback'] = 'esc_url_raw';
}
}
return $args;
}
}

View file

@ -0,0 +1,28 @@
wp.customize.controlConstructor["kirki-generic"] =
wp.customize.kirkiDynamicControl.extend({
initKirkiControl: function (control) {
control = control || this;
const params = control.params;
control.container.find("input, textarea").on("change input", function () {
const value = jQuery(this).val();
if (
"kirki-generic" === params.type &&
params.choices &&
"number" === params.choices.type
) {
params.choices.min = parseFloat(params.choices.min);
params.choices.max = parseFloat(params.choices.max);
if (value < params.choices.min) {
value = params.choices.min;
} else if (value > params.choices.max) {
value = params.choices.max;
}
}
control.setting.set(value);
});
},
});