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/control-upload/LICENSE
Normal file
21
functions/kirki/kirki-packages/control-upload/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,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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
/**
|
||||
* Override field methods
|
||||
*
|
||||
* @package kirki-framework/control-typography
|
||||
* @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 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue