* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Image_Checkbox_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'image_checkbox';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
value() ) ); ?>
link(); ?> />
choices as $key => $value ) { ?>
class="multi-image-checkbox"/>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Text_Radio_Button_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'text_radio_button';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
choices as $key => $value ) { ?>
link(); ?> value() ); ?>/>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Image_Radio_Button_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'image_radio_button';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Single_Accordion_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'single_accordion';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'jquery' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
wp_enqueue_style( 'fontawesome', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/font-awesome.min.css', array(), '4.6.3', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'target' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'i' => array(
'class' => array()
),
);
?>
label ); ?>
description ) ) {
echo '
';
foreach ( $this->description as $key => $value ) {
echo '' . $key . wp_kses( $value, $allowed_html ) . ' ';
}
echo ' ';
}
else {
echo wp_kses( $this->description, $allowed_html );
}
?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Simple_Notice_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'simple_notice';
/**
* Render the control in the customizer
*/
public function render_content() {
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'target' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'i' => array(
'class' => array()
),
'span' => array(
'class' => array(),
),
'code' => array(),
);
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description, $allowed_html ); ?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Slider_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'slider_control';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'jquery', 'jquery-ui-core' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
description ) ) { ?>
description ); ?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Toggle_Switch_Custom_control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'toogle_switch';
/**
* Enqueue our scripts and styles
*/
public function enqueue(){
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content(){
?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Sortable_Repeater_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'sortable_repeater';
/**
* Button labels
*/
public $button_labels = array();
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Merge the passed button labels with our default labels
$this->button_labels = wp_parse_args( $this->button_labels,
array(
'add' => __( 'Add', 'billow' ),
)
);
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'jquery', 'jquery-ui-core' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
link(); ?> />
button_labels['add'] ); ?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Dropdown_Select2_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'dropdown_select2';
/**
* The type of Select2 Dropwdown to display. Can be either a single select dropdown or a multi-select dropdown. Either false for true. Default = false
*/
private $multiselect = false;
/**
* The Placeholder value to display. Select2 requires a Placeholder value to be set when using the clearall option. Default = 'Please select...'
*/
private $placeholder = 'Please select...';
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Check if this is a multi-select field
if ( isset( $this->input_attrs['multiselect'] ) && $this->input_attrs['multiselect'] ) {
$this->multiselect = true;
}
// Check if a placeholder string has been specified
if ( isset( $this->input_attrs['placeholder'] ) && $this->input_attrs['placeholder'] ) {
$this->placeholder = $this->input_attrs['placeholder'];
}
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-select2-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/select2.min.js', array( 'jquery' ), '4.0.6', true );
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'skyrocket-select2-js' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.1', 'all' );
wp_enqueue_style( 'skyrocket-select2-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/select2.min.css', array(), '4.0.6', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
$defaultValue = $this->value();
if ( $this->multiselect ) {
$defaultValue = explode( ',', $this->value() );
}
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
link(); ?> />
multiselect ? 'multiple="multiple" ' : '' ); ?>>
multiselect ) {
// When using Select2 for single selection, the Placeholder needs an empty at the top of the list for it to work (multi-selects dont need this)
echo ' ';
}
foreach ( $this->choices as $key => $value ) {
if ( is_array( $value ) ) {
echo '';
foreach ( $value as $optgroupkey => $optgroupvalue ) {
echo '' . esc_attr( $optgroupvalue ) . ' ';
}
echo ' ';
}
else {
echo '' . esc_attr( $value ) . ' ';
}
}
?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Dropdown_Posts_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'dropdown_posts';
/**
* Posts
*/
private $posts = array();
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Get our Posts
$this->posts = get_posts( $this->input_attrs );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
link(); ?>>
posts ) ) {
foreach ( $this->posts as $post ) {
printf( '%s ',
$post->ID,
selected( $this->value(), $post->ID, false ),
$post->post_title
);
}
}
?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_TinyMCE_Custom_control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'tinymce_editor';
/**
* Enqueue our scripts and styles
*/
public function enqueue(){
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'jquery' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.0', 'all' );
wp_enqueue_editor();
}
/**
* Pass our TinyMCE toolbar string to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['skyrockettinymcetoolbar1'] = isset( $this->input_attrs['toolbar1'] ) ? esc_attr( $this->input_attrs['toolbar1'] ) : 'bold italic bullist numlist alignleft aligncenter alignright link';
$this->json['skyrockettinymcetoolbar2'] = isset( $this->input_attrs['toolbar2'] ) ? esc_attr( $this->input_attrs['toolbar2'] ) : '';
}
/**
* Render the control in the customizer
*/
public function render_content(){
?>
label ); ?>
description ) ) { ?>
description ); ?>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Skyrocket_Google_Font_Select_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'google_fonts';
/**
* The list of Google Fonts
*/
private $fontList = false;
/**
* The saved font values decoded from json
*/
private $fontValues = [];
/**
* The index of the saved font within the list of Google fonts
*/
private $fontListIndex = 0;
/**
* The number of fonts to display from the json file. Either positive integer or 'all'. Default = 'all'
*/
private $fontCount = 'all';
/**
* The font list sort order. Either 'alpha' or 'popular'. Default = 'alpha'
*/
private $fontOrderBy = 'alpha';
/**
* Labels for font variants
*/
private $fontVariantLabel = [];
/**
* Labels for font subsets
*/
private $fontSubsetLabel = [];
/**
* Get our list of fonts from the json file
*/
private $fontAlternateWeb = [];
/**
* Get our list of Alternate Web Fonts
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Get the font sort order
if ( isset( $this->input_attrs['orderby'] ) && strtolower( $this->input_attrs['orderby'] ) === 'popular' ) {
$this->fontOrderBy = 'popular';
}
// Get the list of Google fonts
if ( isset( $this->input_attrs['font_count'] ) ) {
if ( 'all' != strtolower( $this->input_attrs['font_count'] ) ) {
$this->fontCount = ( abs( (int) $this->input_attrs['font_count'] ) > 0 ? abs( (int) $this->input_attrs['font_count'] ) : 'all' );
}
}
$this->fontList = $this->skyrocket_getGoogleFonts( 'all' );
// Decode the default json font value
$this->fontValues = json_decode( $this->value() );
// Find the index of our default font within our list of Google fonts
$this->fontListIndex = is_object( $this->fontValues ) && property_exists( $this->fontValues, 'font' ) ? $this->skyrocket_getFontIndex( $this->fontList, $this->fontValues->font ) : false ;
$this->fontVariantLabel = array(
'100' => __( 'Thin (100)','billow' ),
'100italic' => __( 'Thin Italic (100)','billow' ),
'300' => __( 'Light (300)','billow' ),
'300italic' => __( 'Light Italic (300)','billow' ),
'400' => __( 'Regular (400)','billow' ),
'400italic' => __( 'Regular Italic (400)','billow' ),
'500' => __( 'Medium (500)','billow' ),
'500italic' => __( 'Medium Italic (500)','billow' ),
'700' => __( 'Bold (700)','billow' ),
'700italic' => __( 'Bold Italic (700)','billow' ),
'900' => __( 'Black (900)','billow' ),
'900italic' => __( 'Black Italic (900)','billow' ),
'regular' => __( 'Regular (400)','billow' ),
'italic' => __( 'Italic','billow' ),
);
$this->fontSubsetLabel = array(
'latin-ext' => 'Latin Extended',
'latin' => 'Latin',
'cyrillic-ext' => 'Cyrillic Extended',
'cyrillic' => 'Cyrillic',
'greek-ext' => 'Greek Extended',
'greek' => 'Greek',
'vietnamese' => 'Vietnamese',
);
$this->fontAlternateWeb = array(
"Georgia, serif"=>"Georgia, serif",
"Palatino Linotype, Book Antiqua, Palatino, serif"=>"Palatino Linotype, Book Antiqua, Palatino, serif",
"Times New Roman, Times, serif"=>"Times New Roman, Times, serif",
"Arial, Helvetica, sans-serif"=>"Arial, Helvetica, sans-serif",
"Arial Black, Gadget, sans-serif"=>"Arial Black, Gadget, sans-serif",
"Comic Sans MS, cursive, sans-serif"=>"Comic Sans MS, cursive, sans-serif",
"Impact, Charcoal, sans-serif"=>"Impact, Charcoal, sans-serif",
"Lucida Sans Unicode, Lucida Grande, sans-serif"=>"Lucida Sans Unicode, Lucida Grande, sans-serif",
"Tahoma, Geneva, sans-serif"=>"Tahoma, Geneva, sans-serif",
"Trebuchet MS, Helvetica, sans-serif"=>"Trebuchet MS, Helvetica, sans-serif",
"Verdana, Geneva, sans-serif"=>"Verdana, Geneva, sans-serif",
"Courier New, Courier, monospace"=>"Courier New, Courier, monospace",
"Lucida Console, Monaco, monospace"=>"Lucida Console, Monaco, monospace"
);
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-select2-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/select2.min.js', array( 'jquery' ), '4.0.6', true );
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'skyrocket-select2-js' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array(), '1.1', 'all' );
wp_enqueue_style( 'skyrocket-select2-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/select2.min.css', array(), '4.0.6', 'all' );
wp_enqueue_script( 'autocomplete-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/autocomplete.min.js', array( 'jquery' ), '1.0.4', true );
wp_enqueue_style( 'autocomplete-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/autocomplete.css', array(), '1.0.4', 'all' );
$autocomplete_hints = array();
foreach( $this->fontList as $f ){
$autocomplete_hints[] = $f->family;
}
wp_localize_script( 'autocomplete-js', 'blw_google_font_select', array(
'hints' => $autocomplete_hints,
'variant_labels' => $this->fontVariantLabel,
) );
}
/**
* Export our List of Google Fonts to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['skyrocketfontslist'] = $this->fontList;
}
/**
* Render the control in the customizer
*/
public function render_content() {
$fontCounter = 0;
$isFontInList = false;
$fontListStr = '';
if( is_object( $this->fontValues ) && property_exists( $this->fontValues, 'font' ) ){
$font = $this->fontValues->font;
}else{
$font = '';
}
if( !empty($this->fontList) ) {
?>
label ) ) { ?>
label ); ?>
description ) ) { ?>
description ); ?>
link(); ?> />
$value ) {
if( $value->family == $needle ) {
return $key;
}
}
return false;
}
/**
* Google Fonts List.
*/
public function skyrocket_getGoogleFonts( $count = 30 ) {
if ( $this->fontOrderBy === 'popular' ) {
require dirname( __FILE__ ) . '/google-fonts-popularity.php';
} else {
require dirname( __FILE__ ) . '/google-fonts-alphabetical.php';
}
if( $count == 'all' ) {
return $fonts->items;
} else {
return array_slice( $fonts->items, 0, $count );
}
}
}
/**
* Alpha Color Picker Custom Control
*
* @author Braad Martin
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/BraadMartin/components/tree/master/customizer/alpha-color-picker
*/
class Skyrocket_Customize_Alpha_Color_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'alpha-color';
/**
* Add support for palettes to be passed in.
*
* Supported palette values are true, false, or an array of RGBa and Hex colors.
*/
public $palette;
/**
* Add support for showing the opacity value on the slider handle.
*/
public $show_opacity;
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'skyrocket-custom-controls-js', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/js/customizer.js', array( 'jquery', 'wp-color-picker' ), '1.0.1', true );
wp_enqueue_style( 'skyrocket-custom-controls-css', trailingslashit( get_template_directory_uri() ) . 'inc/customizer/custom-controls/css/customizer.css', array( 'wp-color-picker' ), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
// Process the palette
if ( is_array( $this->palette ) ) {
$palette = implode( '|', $this->palette );
} else {
// Default to true.
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true';
}
// Support passing show_opacity as string or boolean. Default to true.
$show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true';
?>
label ) && '' !== $this->label ) {
echo '' . sanitize_text_field( $this->label ) . ' ';
}
if ( isset( $this->description ) && '' !== $this->description ) {
echo '' . sanitize_text_field( $this->description ) . ' ';
} ?>
link(); ?> />
$value) {
$input[$key] = esc_url_raw( $value );
}
$input = implode( ',', $input );
}
else {
$input = esc_url_raw( $input );
}
return $input;
}
}
/**
* Switch sanitization
*
* @param string Switch value
* @return integer Sanitized value
*/
if ( ! function_exists( 'skyrocket_switch_sanitization' ) ) {
function skyrocket_switch_sanitization( $input ) {
if ( true === $input ) {
return 1;
} else {
return 0;
}
}
}
/**
* Radio Button and Select sanitization
*
* @param string Radio Button value
* @return integer Sanitized value
*/
if ( ! function_exists( 'skyrocket_radio_sanitization' ) ) {
function skyrocket_radio_sanitization( $input, $setting ) {
//get the list of possible radio box or select options
$choices = $setting->manager->get_control( $setting->id )->choices;
if ( array_key_exists( $input, $choices ) ) {
return $input;
} else {
return $setting->default;
}
}
}
/**
* Integer sanitization
*
* @param string Input value to check
* @return integer Returned integer value
*/
if ( ! function_exists( 'skyrocket_sanitize_integer' ) ) {
function skyrocket_sanitize_integer( $input ) {
return (int) $input;
}
}
/**
* Text sanitization
*
* @param string Input to be sanitized (either a string containing a single string or multiple, separated by commas)
* @return string Sanitized input
*/
if ( ! function_exists( 'skyrocket_text_sanitization' ) ) {
function skyrocket_text_sanitization( $input ) {
if ( strpos( $input, ',' ) !== false) {
$input = explode( ',', $input );
}
if( is_array( $input ) ) {
foreach ( $input as $key => $value ) {
$input[$key] = sanitize_text_field( $value );
}
$input = implode( ',', $input );
}
else {
$input = sanitize_text_field( $input );
}
return $input;
}
}
/**
* Array sanitization
*
* @param array Input to be sanitized
* @return array Sanitized input
*/
if ( ! function_exists( 'skyrocket_array_sanitization' ) ) {
function skyrocket_array_sanitization( $input ) {
if( is_array( $input ) ) {
foreach ( $input as $key => $value ) {
$input[$key] = sanitize_text_field( $value );
}
}
else {
$input = '';
}
return $input;
}
}
/**
* Alpha Color (Hex & RGBa) sanitization
*
* @param string Input to be sanitized
* @return string Sanitized input
*/
if ( ! function_exists( 'skyrocket_hex_rgba_sanitization' ) ) {
function skyrocket_hex_rgba_sanitization( $input, $setting ) {
if ( empty( $input ) || is_array( $input ) ) {
return $setting->default;
}
if ( false === strpos( $input, 'rgba' ) ) {
// If string doesn't start with 'rgba' then santize as hex color
$input = sanitize_hex_color( $input );
} else {
// Sanitize as RGBa color
$input = str_replace( ' ', '', $input );
sscanf( $input, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );
$input = 'rgba(' . skyrocket_in_range( $red, 0, 255 ) . ',' . skyrocket_in_range( $green, 0, 255 ) . ',' . skyrocket_in_range( $blue, 0, 255 ) . ',' . skyrocket_in_range( $alpha, 0, 1 ) . ')';
}
return $input;
}
}
/**
* Only allow values between a certain minimum & maxmium range
*
* @param number Input to be sanitized
* @return number Sanitized input
*/
if ( ! function_exists( 'skyrocket_in_range' ) ) {
function skyrocket_in_range( $input, $min, $max ){
if ( $input < $min ) {
$input = $min;
}
if ( $input > $max ) {
$input = $max;
}
return $input;
}
}
/**
* Google Font sanitization
*
* @param string JSON string to be sanitized
* @return string Sanitized input
*/
if ( ! function_exists( 'skyrocket_google_font_sanitization' ) ) {
function skyrocket_google_font_sanitization( $input ) {
$val = json_decode( $input, true );
if( is_array( $val ) ) {
foreach ( $val as $key => $value ) {
$val[$key] = sanitize_text_field( $value );
}
$input = json_encode( $val );
}
else {
$input = json_encode( sanitize_text_field( $val ) );
}
return $input;
}
}
/**
* Date Time sanitization
*
* @param string Date/Time string to be sanitized
* @return string Sanitized input
*/
if ( ! function_exists( 'skyrocket_date_time_sanitization' ) ) {
function skyrocket_date_time_sanitization( $input, $setting ) {
$datetimeformat = 'Y-m-d';
if ( $setting->manager->get_control( $setting->id )->include_time ) {
$datetimeformat = 'Y-m-d H:i:s';
}
$date = DateTime::createFromFormat( $datetimeformat, $input );
if ( $date === false ) {
$date = DateTime::createFromFormat( $datetimeformat, $setting->default );
}
return $date->format( $datetimeformat );
}
}
/**
* Slider sanitization
*
* @param string Slider value to be sanitized
* @return string Sanitized input
*/
if ( ! function_exists( 'skyrocket_range_sanitization' ) ) {
function skyrocket_range_sanitization( $input, $setting ) {
$attrs = $setting->manager->get_control( $setting->id )->input_attrs;
$min = ( isset( $attrs['min'] ) ? $attrs['min'] : $input );
$max = ( isset( $attrs['max'] ) ? $attrs['max'] : $input );
$step = ( isset( $attrs['step'] ) ? $attrs['step'] : 1 );
$number = floor( $input / $attrs['step'] ) * $attrs['step'];
return skyrocket_in_range( $number, $min, $max );
}
}
}