Update to Kirki 4.0.22

This commit is contained in:
AlxMedia 2022-03-15 14:29:17 +01:00
parent 2b6ac38550
commit 78edeb1b25
492 changed files with 29668 additions and 39884 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,55 @@
# control-upload
## Installation
First, install the package using composer:
```bash
composer require kirki-framework/control-upload
```
Make sure you include the autoloader:
```php
require_once get_parent_theme_file_path( 'vendor/autoload.php' );
```
To add a control using the customizer API:
```php
/**
* Registers the control and whitelists it for JS templating.
*
* @since 1.0
* @param WP_Customize_Manager $wp_customize The WP_Customize_Manager object.
* @return void
*/
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->register_control_type( '\Kirki\Control\Upload' );
} );
/**
* Add Customizer settings & controls.
*
* @since 1.0
* @param WP_Customize_Manager $wp_customize The WP_Customize_Manager object.
* @return void
*/
add_action( 'customize_register', function( $wp_customize ) {
// Add settings.
$wp_customize->add_setting( 'my_control', [
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 'option-1',
'transport' => 'refresh', // Or postMessage.
'sanitize_callback' => 'esc_url_raw',
'default' => '',
] );
// Add controls.
$wp_customize->add_control( new \Kirki\Control\Upload( $wp_customize, 'my_control', [
'label' => esc_html__( 'My Control', 'theme_textdomain' ),
'section' => 'my_section',
] ) );
} );
```

View file

@ -0,0 +1,72 @@
<?php
/**
* Kirki upload control.
*
* @package kirki-framework/control-upload
* @since 1.0.1
*/
namespace Kirki\Control;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Upload control
*/
class Upload extends \WP_Customize_Media_Control {
/**
* Control type.
*
* @since 1.0.1
* @var string
*/
public $type = 'upload';
/**
* Media control mime type.
*
* @since 1.0.1
* @var string
*/
public $mime_type = '';
/**
* Button labels.
*
* @since 1.0.1
* @var array
*/
public $button_labels = array();
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @since 1.0.1
*
* @uses WP_Customize_Media_Control::to_json()
*/
public function to_json() {
parent::to_json();
$value = $this->value();
if ( ! empty( $value ) ) {
if ( is_array( $value ) && isset( $value['id'] ) ) {
$attachment_id = $value['id'];
} elseif ( is_numeric( $value ) ) {
$attachment_id = absint( $value );
} elseif ( is_string( $value ) && ! is_numeric( $value ) ) {
$attachment_id = attachment_url_to_postid( $value );
}
if ( ! empty( $attachment_id ) ) {
$this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
}
}
}
}

View file

@ -0,0 +1,152 @@
<?php
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @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 Upload extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-upload';
/**
* The control class-name.
*
* @access protected
* @since 0.1
* @var string
*/
protected $control_class = '\Kirki\Control\Upload';
/**
* 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'] = function( $value ) {
$save_as = isset( $this->args['choices']['save_as'] ) ? $this->args['choices']['save_as'] : 'url';
return self::sanitize( $value, $save_as );
};
}
}
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 );
$args['type'] = 'upload';
}
return $args;
}
/**
* Sanitizes the field value.
*
* @since 1.0.2
*
* @param mixed $value The field value.
* @param string $save_as The expected saving format.
*
* @return mixed
*/
public static function sanitize( $value, $save_as = 'url' ) {
if ( 'array' === $save_as ) {
if ( is_array( $value ) ) {
return [
'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '',
'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '',
'filename' => ( isset( $value['filename'] ) && '' !== $value['filename'] ) ? sanitize_text_field( $value['filename'] ) : '',
];
} elseif ( is_string( $value ) && ! is_numeric( $value ) ) {
// Here, we assume that the value is the URL.
$attachment_id = attachment_url_to_postid( $value );
return [
'id' => $attachment_id,
'url' => $value,
'filename' => basename( get_attached_file( $attachment_id ) ),
];
} else {
// Here, we assume that the value is int or numeric (the attachment ID).
$value = absint( $value );
return [
'id' => $value,
'url' => wp_get_attachment_url( $value ),
'filename' => basename( get_attached_file( $value ) ),
];
}
} elseif ( 'id' === $save_as ) {
if ( is_string( $value ) && ! is_numeric( $value ) ) {
// Here, we assume that the value is the URL.
return attachment_url_to_postid( $value );
} elseif ( is_array( $value ) && isset( $value['id'] ) ) {
return absint( $value['id'] );
}
// Here, we assume that the value is int or numeric (the attachment ID).
return absint( $value );
}
// If we're reaching this point, then we're saving the URL.
if ( is_array( $value ) && isset( $value['url'] ) ) {
$value = $value['url'];
} elseif ( is_numeric( $value ) ) {
$value = absint( $value );
$value = wp_get_attachment_url( $value );
} else {
$value = esc_url_raw( $value );
}
return $value;
}
}