Initial commit

This commit is contained in:
Alexander Agnarson 2019-02-10 20:21:07 +01:00
commit ee50200fe7
353 changed files with 78977 additions and 0 deletions

View file

@ -0,0 +1,117 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 3.0.0
*/
/**
* Field overrides.
*/
class Kirki_Field_Background extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-background';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* Sanitizes typography controls
*
* @since 2.2.0
* @param array $value The value.
* @return array
*/
public function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return array();
}
return array(
'background-color' => ( isset( $value['background-color'] ) ) ? sanitize_text_field( $value['background-color'] ) : '',
'background-image' => ( isset( $value['background-image'] ) ) ? esc_url_raw( $value['background-image'] ) : '',
'background-repeat' => ( isset( $value['background-repeat'] ) ) ? sanitize_text_field( $value['background-repeat'] ) : '',
'background-position' => ( isset( $value['background-position'] ) ) ? sanitize_text_field( $value['background-position'] ) : '',
'background-size' => ( isset( $value['background-size'] ) ) ? sanitize_text_field( $value['background-size'] ) : '',
'background-attachment' => ( isset( $value['background-attachment'] ) ) ? sanitize_text_field( $value['background-attachment'] ) : '',
);
}
/**
* Sets the $js_vars
*
* @access protected
*/
protected function set_js_vars() {
// Typecast to array.
$this->js_vars = (array) $this->js_vars;
// Check if transport is set to auto.
// If not, then skip the auto-calculations and exit early.
if ( 'auto' !== $this->transport ) {
return;
}
// Set transport to refresh initially.
// Serves as a fallback in case we failt to auto-calculate js_vars.
$this->transport = 'refresh';
$js_vars = array();
// Try to auto-generate js_vars.
// First we need to check if js_vars are empty, and that output is not empty.
if ( empty( $this->js_vars ) && ! empty( $this->output ) ) {
// Start going through each item in the $output array.
foreach ( $this->output as $output ) {
// If 'element' is not defined, skip this.
if ( ! isset( $output['element'] ) ) {
continue;
}
if ( is_array( $output['element'] ) ) {
$output['element'] = implode( ',', $output['element'] );
}
// If there's a sanitize_callback defined, skip this.
if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) ) {
continue;
}
// If we got this far, it's safe to add this.
$js_vars[] = $output;
}
// Did we manage to get all the items from 'output'?
// If not, then we're missing something so don't add this.
if ( count( $js_vars ) !== count( $this->output ) ) {
return;
}
$this->js_vars = $js_vars;
$this->transport = 'postMessage';
}
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Checkbox extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'checkbox';
}
/**
* Sets the $sanitize_callback.
*
* @access protected
*/
protected function set_sanitize_callback() {
if ( ! $this->sanitize_callback ) {
$this->sanitize_callback = array( $this, 'sanitize' );
}
}
/**
* Sanitizes checkbox values.
*
* @access public
* @param boolean|integer|string|null $value The checkbox value.
* @return bool
*/
public function sanitize( $value = null ) {
return ( '0' === $value || 'false' === $value ) ? false : (bool) $value;
}
/**
* Sets the default value.
*
* @access protected
*/
protected function set_default() {
$this->default = (bool) ( 1 === $this->default || '1' === $this->default || true === $this->default || 'true' === $this->default || 'on' === $this->default );
}
}

View file

@ -0,0 +1,118 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Code extends Kirki_Field {
/**
* The code_type (MIME type).
*
* @access public
* @since 3.0.21
* @var string
*/
public $code_type = 'text/css';
/**
* Code editor settings.
*
* @see wp_enqueue_code_editor()
* @since 3.0.21
* @access public
* @var array|false
*/
public $editor_settings = array();
/**
* Custom input attributes (defined as an array).
*
* @access public
* @since 3.0.21
* @var array
*/
public $input_attrs = array(
'aria-describedby' => 'kirki-code editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4',
);
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'code_editor';
}
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! isset( $this->choices['language'] ) ) {
return;
}
$language = $this->choices['language'];
switch ( $language ) {
case 'json':
case 'xml':
$language = 'application/' . $language;
break;
case 'http':
$language = 'message/' . $language;
break;
case 'js':
case 'javascript':
$language = 'text/javascript';
break;
case 'txt':
$language = 'text/plain';
break;
case 'css':
case 'jsx':
case 'html':
$language = 'text/' . $language;
break;
default:
$language = ( 'js' === $language ) ? 'javascript' : $language;
$language = ( 'htm' === $language ) ? 'html' : $language;
$language = ( 'yml' === $language ) ? 'yaml' : $language;
$language = 'text/x-' . $language;
break;
}
if ( ! isset( $this->editor_settings['codemirror'] ) ) {
$this->editor_settings['codemirror'] = array();
}
if ( ! isset( $this->editor_settings['codemirror']['mode'] ) ) {
$this->editor_settings['codemirror']['mode'] = $language;
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
// Code fields must NOT be filtered. Their values usually contain CSS/JS.
// It is the responsibility of the theme/plugin that registers this field
// to properly apply any necessary filtering.
$this->sanitize_callback = array( 'Kirki_Sanitize_Values', 'unfiltered' );
}
}

View file

@ -0,0 +1,28 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Color_Alpha extends Kirki_Field_Color {
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices['alpha'] = true;
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.3.2
*/
/**
* Field overrides.
*/
class Kirki_Field_Color_Palette extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-color-palette';
}
}

View file

@ -0,0 +1,85 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Color extends Kirki_Field {
/**
* Backwards compatibility.
*
* @access protected
* @var bool
*/
protected $alpha = false;
/**
* Mode (hue)
*
* @access protected
* @var string
*/
protected $mode = 'full';
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-color';
}
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
if ( true === $this->alpha ) {
_doing_it_wrong( 'Kirki::add_field', esc_html__( 'Do not use "alpha" as an argument in color controls. Use "choices[alpha]" instead.', 'kirki' ), '3.0.10' );
$this->choices['alpha'] = true;
}
if ( ! isset( $this->choices['alpha'] ) || true !== $this->choices['alpha'] ) {
$this->choices['alpha'] = true;
if ( property_exists( $this, 'default' ) && ! empty( $this->default ) && false === strpos( 'rgba', $this->default ) ) {
$this->choices['alpha'] = false;
}
}
if ( ( ! isset( $this->choices['mode'] ) ) || ( 'hex' !== $this->choices['mode'] || 'hue' !== $this->choices['mode'] ) ) {
$this->choices['mode'] = 'hex';
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
if ( 'hue' === $this->mode ) {
$this->sanitize_callback = 'absint';
return;
}
$this->sanitize_callback = array( 'Kirki_Sanitize_Values', 'color' );
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Custom extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-custom';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
// Custom fields don't actually save any value.
// just use __return_true.
$this->sanitize_callback = '__return_true';
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Dashicons extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-dashicons';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'sanitize_text_field';
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Date extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-date';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'sanitize_text_field';
}
}

View file

@ -0,0 +1,36 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.3.2
*/
/**
* Field overrides.
*/
class Kirki_Field_Dimension extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-dimension';
}
/**
* Sanitizes the value.
*
* @access public
* @param string $value The value.
* @return string
*/
public function sanitize( $value ) {
return sanitize_text_field( $value );
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Dimensions extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-dimensions';
}
/**
* Sets the $sanitize_callback.
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* Sanitizes the value.
*
* @access public
* @param array $value The value.
* @return array
*/
public function sanitize( $value ) {
// Sanitize each sub-value separately.
foreach ( $value as $key => $sub_value ) {
$value[ $key ] = sanitize_text_field( $sub_value );
}
return $value;
}
/**
* Set the choices.
* Adds a pseudo-element "controls" that helps with the JS API.
*
* @access protected
*/
protected function set_choices() {
$this->choices['controls'] = array();
if ( is_array( $this->default ) ) {
foreach ( $this->default as $key => $value ) {
$this->choices['controls'][ $key ] = true;
}
}
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Editor extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
global $wp_version;
if ( version_compare( $wp_version, '4.8' ) >= 0 ) {
$this->type = 'kirki-editor';
return;
}
// Fallback for older WordPress versions.
$this->type = 'kirki-generic';
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices['element'] = 'textarea';
$this->choices['rows'] = '5';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'wp_kses_post';
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 3.0.0
*/
/**
* Field overrides.
*/
class Kirki_Field_FontAwesome extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-fontawesome';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'sanitize_text_field';
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.3.2
*/
/**
* This is simply an alias for the Kirki_Field_Kirki_Generic class.
*/
class Kirki_Field_Generic extends Kirki_Field_Kirki_Generic {}

View file

@ -0,0 +1,16 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Prior to version 0.8 there was a separate 'group-title' field.
* This exists here just for backwards-compatibility purposes.
*/
class Kirki_Field_Group_Title extends Kirki_Field_Custom {}

View file

@ -0,0 +1,115 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Image extends Kirki_Field {
/**
* Custom labels.
* This only exists here for backwards-compatibility purposes.
*
* @access public
* @since 3.0.23
* @var string
*/
public $button_labels = array();
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-image';
}
/**
* Sets the button labels.
*
* @access protected
* @since 3.0.23
* @return void
*/
protected function set_button_labels() {
$this->button_labels = wp_parse_args(
$this->button_labels,
array(
'select' => esc_html__( 'Select image', 'kirki' ),
'change' => esc_html__( 'Change image', 'kirki' ),
'default' => esc_html__( 'Default', 'kirki' ),
'remove' => esc_html__( 'Remove', 'kirki' ),
'placeholder' => esc_html__( 'No image selected', 'kirki' ),
'frame_title' => esc_html__( 'Select image', 'kirki' ),
'frame_button' => esc_html__( 'Choose image', 'kirki' ),
)
);
}
/**
* Set the choices.
* Adds a pseudo-element "controls" that helps with the JS API.
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = (array) $this->choices;
}
if ( ! isset( $this->choices['save_as'] ) ) {
$this->choices['save_as'] = 'url';
}
if ( ! isset( $this->choices['labels'] ) ) {
$this->choices['labels'] = array();
}
$this->set_button_labels();
$this->choices['labels'] = wp_parse_args( $this->choices['labels'], $this->button_labels );
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* The sanitize method that will be used as a falback
*
* @param string|array $value The control's value.
*/
public function sanitize( $value ) {
if ( isset( $this->choices['save_as'] ) && 'array' === $this->choices['save_as'] ) {
return array(
'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '',
'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '',
'width' => ( isset( $value['width'] ) && '' !== $value['width'] ) ? (int) $value['width'] : '',
'height' => ( isset( $value['height'] ) && '' !== $value['height'] ) ? (int) $value['height'] : '',
);
}
if ( isset( $this->choices['save_as'] ) && 'id' === $this->choices['save_as'] ) {
return absint( $value );
}
if ( is_string( $value ) ) {
return esc_url_raw( $value );
}
return $value;
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Kirki_Generic extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-generic';
}
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
if ( ! isset( $this->choices['element'] ) ) {
$this->choices['element'] = 'input';
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'wp_kses_post';
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Link extends Kirki_Field_URL {}

View file

@ -0,0 +1,50 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Multicheck extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-multicheck';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* The sanitize method that will be used as a falback
*
* @param string|array $value The control's value.
*/
public function sanitize( $value ) {
$value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value;
return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : array();
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Multicolor extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-multicolor';
}
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
// Make sure choices are defined as an array.
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* The method that will be used as a `sanitize_callback`.
*
* @param array $value The value to be sanitized.
* @return array The value.
*/
public function sanitize( $value ) {
return $value;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Number extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-number';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
$this->choices = wp_parse_args(
$this->choices,
array(
'min' => -999999999,
'max' => 999999999,
'step' => 1,
)
);
// Make sure min, max & step are all numeric.
$this->choices['min'] = filter_var( $this->choices['min'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$this->choices['max'] = filter_var( $this->choices['max'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$this->choices['step'] = filter_var( $this->choices['step'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
}
/**
* Sanitizes numeric values.
*
* @access public
* @param integer|string $value The checkbox value.
* @return bool
*/
public function sanitize( $value = 0 ) {
$this->set_choices();
$value = filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
// Minimum & maximum value limits.
if ( $value < $this->choices['min'] || $value > $this->choices['max'] ) {
return max( min( $value, $this->choices['max'] ), $this->choices['min'] );
}
// Only multiple of steps.
$steps = ( $value - $this->choices['min'] ) / $this->choices['step'];
if ( ! is_int( $steps ) ) {
$value = $this->choices['min'] + ( round( $steps ) * $this->choices['step'] );
}
return $value;
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Palette extends Kirki_Field_Radio {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-palette';
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Preset extends Kirki_Field_Select {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-select';
}
/**
* Set the preset.
*
* @access protected
* @since 3.0.28
*/
protected function set_preset() {
// Set preset from the choices.
$this->preset = $this->choices;
// We're using a flat select.
foreach ( $this->choices as $key => $args ) {
$this->choices[ $key ] = $args['label'];
}
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Radio_Buttonset extends Kirki_Field_Radio {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-radio-buttonset';
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Radio_Image extends Kirki_Field_Radio {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-radio-image';
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Radio extends Kirki_Field {
/**
* Whitelisting for backwards-compatibility.
*
* @access protected
* @var string
*/
protected $mode = '';
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-radio';
// Tweaks for backwards-compatibility:
// Prior to version 0.8 radio-buttonset & radio-image were part of the radio control.
if ( in_array( $this->mode, array( 'buttonset', 'image' ), true ) ) {
/* translators: %1$s represents the field ID where the error occurs. %2%s is buttonset/image. */
_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Error in field %1$s. The "mode" argument has been deprecated since Kirki v0.8. Use the "radio-%2$s" type instead.', 'kirki' ), esc_html( $this->settings ), esc_html( $this->mode ) ), '3.0.10' );
$this->type = 'radio-' . $this->mode;
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'sanitize_text_field';
}
}

View file

@ -0,0 +1,173 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Repeater extends Kirki_Field {
/**
* Used only on repeaters.
* Contains an array of the fields.
*
* @access protected
* @var array
*/
protected $fields = array();
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'repeater';
}
/**
* Sets the $transport
*
* @access protected
*/
protected function set_transport() {
// Force using refresh mode.
// Currently the repeater control does not support postMessage.
$this->transport = 'refresh';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* The sanitize method that will be used as a falback
*
* @param string|array $value The control's value.
*/
public function sanitize( $value ) {
// is the value formatted as a string?
if ( is_string( $value ) ) {
$value = rawurldecode( $value );
$value = json_decode( $value, true );
}
// Nothing to sanitize if we don't have fields.
if ( empty( $this->fields ) ) {
return $value;
}
foreach ( $value as $row_id => $row_value ) {
// Make sure the row is formatted as an array.
if ( ! is_array( $row_value ) ) {
$value[ $row_id ] = array();
continue;
}
// Start parsing sub-fields in rows.
foreach ( $row_value as $subfield_id => $subfield_value ) {
// Make sure this is a valid subfield.
// If it's not, then unset it.
if ( ! isset( $this->fields[ $subfield_id ] ) ) {
unset( $value[ $row_id ][ $subfield_id ] );
}
// Get the subfield-type.
if ( ! isset( $this->fields[ $subfield_id ]['type'] ) ) {
continue;
}
$subfield_type = $this->fields[ $subfield_id ]['type'];
// Allow using a sanitize-callback on a per-field basis.
if ( isset( $this->fields[ $subfield_id ]['sanitize_callback'] ) ) {
$subfield_value = call_user_func( $this->fields[ $subfield_id ]['sanitize_callback'], $subfield_value );
} else {
switch ( $subfield_type ) {
case 'image':
case 'cropped_image':
case 'upload':
if ( ! is_numeric( $subfield_value ) && is_string( $subfield_value ) ) {
$subfield_value = esc_url_raw( $subfield_value );
}
break;
case 'dropdown-pages':
$subfield_value = (int) $subfield_value;
break;
case 'color':
if ( $subfield_value ) {
$color_obj = ariColor::newColor( $subfield_value );
$subfield_value = $color_obj->toCSS( $color_obj->mode );
}
break;
case 'text':
$subfield_value = sanitize_text_field( $subfield_value );
break;
case 'url':
case 'link':
$subfield_value = esc_url_raw( $subfield_value );
break;
case 'email':
$subfield_value = filter_var( $subfield_value, FILTER_SANITIZE_EMAIL );
break;
case 'tel':
$subfield_value = sanitize_text_field( $subfield_value );
break;
case 'checkbox':
$subfield_value = (bool) $subfield_value;
break;
case 'select':
if ( isset( $this->fields[ $subfield_id ]['multiple'] ) ) {
if ( true === $this->fields[ $subfield_id ]['multiple'] ) {
$multiple = 2;
}
$multiple = (int) $this->fields[ $subfield_id ]['multiple'];
if ( 1 < $multiple ) {
$subfield_value = (array) $subfield_value;
foreach ( $subfield_value as $sub_subfield_key => $sub_subfield_value ) {
$subfield_value[ $sub_subfield_key ] = sanitize_text_field( $sub_subfield_value );
}
} else {
$subfield_value = sanitize_text_field( $subfield_value );
}
}
break;
case 'radio':
case 'radio-image':
$subfield_value = sanitize_text_field( $subfield_value );
break;
case 'textarea':
$subfield_value = html_entity_decode( wp_kses_post( $subfield_value ) );
}
}
$value[ $row_id ][ $subfield_id ] = $subfield_value;
}
}
return $value;
}
}

View file

@ -0,0 +1,102 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Select extends Kirki_Field {
/**
* Use only on select controls.
* Defines if this is a multi-select or not.
* If value is > 1, then the maximum number of selectable options
* is the number defined here.
*
* @access protected
* @var integer
*/
protected $multiple = 1;
/**
* Placeholder text.
*
* @access protected
* @since 3.0.21
* @var string|false
*/
protected $placeholder = false;
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-select';
}
/**
* Sets the $multiple
*
* @access protected
*/
protected function set_multiple() {
$this->multiple = absint( $this->multiple );
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* Sanitizes select control values.
*
* @since 2.2.8
* @access public
* @param array $value The value.
* @return string|array
*/
public function sanitize( $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $key => $subvalue ) {
if ( '' !== $subvalue || isset( $this->choices[''] ) ) {
$key = sanitize_key( $key );
$value[ $key ] = sanitize_text_field( $subvalue );
}
}
return $value;
}
return sanitize_text_field( $value );
}
/**
* Sets the default value.
*
* @access protected
* @since 3.0.0
*/
protected function set_default() {
if ( 1 < $this->multiple && ! is_array( $this->default ) ) {
$this->default = array( $this->default );
}
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* This is nothing more than an alias for the Kirki_Field_Select class.
* In older versions of Kirki there was a separate 'select2' field.
* This exists here just for compatibility purposes.
*/
class Kirki_Field_Select2_Multiple extends Kirki_Field_Select {
/**
* Sets the $multiple
*
* @access protected
*/
protected function set_multiple() {
$this->multiple = 999;
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* This is nothing more than an alias for the Kirki_Field_Select class.
* In older versions of Kirki there was a separate 'select2' field.
* This exists here just for compatibility purposes.
*/
class Kirki_Field_Select2 extends Kirki_Field_Select {}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Slider extends Kirki_Field_Number {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-slider';
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.3.2
*/
/**
* Field overrides.
*/
class Kirki_Field_Sortable extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-sortable';
}
/**
* Sets the $sanitize_callback.
*
* @access protected
*/
protected function set_sanitize_callback() {
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* Sanitizes sortable values.
*
* @access public
* @param array $value The checkbox value.
* @return array
*/
public function sanitize( $value = array() ) {
if ( is_string( $value ) || is_numeric( $value ) ) {
return array(
sanitize_text_field( $value ),
);
}
$sanitized_value = array();
foreach ( $value as $sub_value ) {
if ( isset( $this->choices[ $sub_value ] ) ) {
$sanitized_value[] = sanitize_text_field( $sub_value );
}
}
return $sanitized_value;
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Spacing extends Kirki_Field_Dimensions {
/**
* Set the choices.
* Adds a pseudo-element "controls" that helps with the JS API.
*
* @access protected
*/
protected function set_choices() {
$default_args = array(
'controls' => array(
'top' => ( isset( $this->default['top'] ) ),
'bottom' => ( isset( $this->default['top'] ) ),
'left' => ( isset( $this->default['top'] ) ),
'right' => ( isset( $this->default['top'] ) ),
),
'labels' => array(
'top' => esc_html__( 'Top', 'kirki' ),
'bottom' => esc_html__( 'Bottom', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
),
);
$this->choices = wp_parse_args( $this->choices, $default_args );
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Switch extends Kirki_Field_Checkbox {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-switch';
}
/**
* Sets the control choices.
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices = wp_parse_args(
$this->choices,
array(
'on' => esc_html__( 'On', 'kirki' ),
'off' => esc_html__( 'Off', 'kirki' ),
'round' => false,
)
);
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Text extends Kirki_Field_Kirki_Generic {
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices['element'] = 'input';
$this->choices['type'] = 'text';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'sanitize_textarea_field';
}
}

View file

@ -0,0 +1,28 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Textarea extends Kirki_Field_Kirki_Generic {
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
$this->choices = array(
'element' => 'textarea',
'rows' => 5,
);
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Toggle extends Kirki_Field_Checkbox {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-toggle';
}
}

View file

@ -0,0 +1,217 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Typography extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'kirki-typography';
}
/**
* The class constructor.
* Parses and sanitizes all field arguments.
* Then it adds the field to Kirki::$fields.
*
* @access public
* @param string $config_id The ID of the config we want to use.
* Defaults to "global".
* Configs are handled by the Kirki_Config class.
* @param array $args The arguments of the field.
*/
public function __construct( $config_id = 'global', $args = array() ) {
parent::__construct( $config_id, $args );
$this->set_default();
}
/**
* Sets the default value.
*
* @access protected
*/
protected function set_default() {
// Accomodate the use of font-weight and convert to variant.
if ( isset( $this->default['font-weight'] ) ) {
$this->default['variant'] = ( 'regular' === $this->default['font-weight'] ) ? 400 : (string) intval( $this->default['font-weight'] );
}
// Make sure letter-spacing has units.
if ( isset( $this->default['letter-spacing'] ) && is_numeric( $this->default['letter-spacing'] ) && $this->default['letter-spacing'] ) {
$this->default['letter-spacing'] .= 'px';
}
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( __CLASS__, 'sanitize' );
}
/**
* Sets the $js_vars
*
* @access protected
*/
protected function set_js_vars() {
if ( ! is_array( $this->js_vars ) ) {
$this->js_vars = array();
}
// Check if transport is set to auto.
// If not, then skip the auto-calculations and exit early.
if ( 'auto' !== $this->transport ) {
return;
}
// Set transport to refresh initially.
// Serves as a fallback in case we failt to auto-calculate js_vars.
$this->transport = 'refresh';
$js_vars = array();
// Try to auto-generate js_vars.
// First we need to check if js_vars are empty, and that output is not empty.
if ( ! empty( $this->output ) ) {
// Start going through each item in the $output array.
foreach ( $this->output as $output ) {
// If 'element' or 'property' are not defined, skip this.
if ( ! isset( $output['element'] ) ) {
continue;
}
if ( is_array( $output['element'] ) ) {
$output['element'] = implode( ',', $output['element'] );
}
// If we got this far, it's safe to add this.
$js_vars[] = $output;
}
// Did we manage to get all the items from 'output'?
// If not, then we're missing something so don't add this.
if ( count( $js_vars ) !== count( $this->output ) ) {
return;
}
$this->js_vars = $js_vars;
$this->transport = 'postMessage';
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 2.2.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return array();
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'font-weight':
if ( isset( $value['variant'] ) ) {
break;
}
$value['variant'] = $val;
if ( isset( $value['font-style'] ) && 'italic' === $value['font-style'] ) {
$value['variant'] = ( '400' !== $val || 400 !== $val ) ? $value['variant'] . 'italic' : 'italic';
}
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? 400 : absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'font-size':
case 'letter-spacing':
case 'word-spacing':
case 'line-height':
$value[ $key ] = '' === trim( $value[ $key ] ) ? '' : sanitize_text_field( $val );
break;
case 'text-align':
if ( ! in_array( $val, array( '', 'inherit', 'left', 'center', 'right', 'justify' ), true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, array( '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ), true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, array( '', 'none', 'underline', 'overline', 'line-through', 'initial', 'inherit' ), true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : ariColor::newColor( $val )->toCSS( 'hex' );
break;
}
}
return $value;
}
/**
* Sets the $choices
*
* @access protected
* @since 3.0.0
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices = wp_parse_args(
$this->choices, array(
'variant' => array(),
'fonts' => array(
'standard' => array(),
'google' => array(),
),
)
);
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_Upload extends Kirki_Field {
/**
* Sets the control type.
*
* @access protected
*/
protected function set_type() {
$this->type = 'upload';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'esc_url_raw';
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.7
*/
/**
* Field overrides.
*/
class Kirki_Field_URL extends Kirki_Field_Kirki_Generic {
/**
* Sets the $choices
*
* @access protected
*/
protected function set_choices() {
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
$this->choices['element'] = 'input';
$this->choices['type'] = 'text';
}
/**
* Sets the $sanitize_callback
*
* @access protected
*/
protected function set_sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = 'esc_url_raw';
}
}