Update to Kirki 4.2.0

This commit is contained in:
AlxMedia 2023-08-04 15:41:48 +02:00
parent cbfd4f27e4
commit 77ecd4ca69
440 changed files with 6230 additions and 5211 deletions

View 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.

View file

@ -0,0 +1,2 @@
wp.customize.controlConstructor["kirki-generic"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(i){var c=(i=i||this).params;i.container.find("input, textarea").on("change input",(function(){var e=jQuery(this).val();"kirki-generic"===c.type&&c.choices&&"number"===c.choices.type&&(c.choices.min=parseFloat(c.choices.min),c.choices.max=parseFloat(c.choices.max),e<c.choices.min?e=c.choices.min:e>c.choices.max&&(e=c.choices.max)),i.setting.set(e)}))}});
//# sourceMappingURL=control.js.map

View file

@ -0,0 +1 @@
{"mappings":"AAAAA,GAAGC,UAAUC,mBAAmB,iBAC9BF,GAAGC,UAAUE,oBAAoBC,OAAO,CACtCC,iBAAkB,SAAUC,GAE1B,IAAMC,GADND,EAAUA,GAAWE,MACED,OAEvBD,EAAQG,UAAUC,KAAK,mBAAmBC,GAAG,gBAAgB,WAC3D,IAAMC,EAAQC,OAAOL,MAAMM,MAGzB,kBAAoBP,EAAOQ,MAC3BR,EAAOS,SACP,WAAaT,EAAOS,QAAQD,OAE5BR,EAAOS,QAAQC,IAAMC,WAAWX,EAAOS,QAAQC,KAC/CV,EAAOS,QAAQG,IAAMD,WAAWX,EAAOS,QAAQG,KAE3CP,EAAQL,EAAOS,QAAQC,IACzBL,EAAQL,EAAOS,QAAQC,IACdL,EAAQL,EAAOS,QAAQG,MAChCP,EAAQL,EAAOS,QAAQG,MAI3Bb,EAAQc,QAAQC,IAAIT","sources":["packages/kirki-framework/control-generic/src/control.js"],"sourcesContent":["wp.customize.controlConstructor[\"kirki-generic\"] =\n wp.customize.kirkiDynamicControl.extend({\n initKirkiControl: function (control) {\n control = control || this;\n const params = control.params;\n\n control.container.find(\"input, textarea\").on(\"change input\", function () {\n const value = jQuery(this).val();\n\n if (\n \"kirki-generic\" === params.type &&\n params.choices &&\n \"number\" === params.choices.type\n ) {\n params.choices.min = parseFloat(params.choices.min);\n params.choices.max = parseFloat(params.choices.max);\n\n if (value < params.choices.min) {\n value = params.choices.min;\n } else if (value > params.choices.max) {\n value = params.choices.max;\n }\n }\n\n control.setting.set(value);\n });\n },\n });\n"],"names":["wp","customize","controlConstructor","kirkiDynamicControl","extend","initKirkiControl","control","params","this","container","find","on","value","jQuery","val","type","choices","min","parseFloat","max","setting","set"],"version":3,"file":"control.js.map"}

View file

@ -0,0 +1,110 @@
<?php
/**
* Customizer Control: kirki-generic.
*
* @package kirki-framework/control-generic
* @copyright Copyright (c) 2023, Themeum
* @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) 2023, Themeum
* @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) 2023, Themeum
* @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) 2023, Themeum
* @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) 2023, Themeum
* @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) 2023, Themeum
* @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);
});
},
});