first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: accordion
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_accordion' ) ) {
class CSF_Field_accordion extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$unallows = array( 'accordion' );
echo $this->field_before();
echo '<div class="csf-accordion-items" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
foreach ( $this->field['accordions'] as $key => $accordion ) {
echo '<div class="csf-accordion-item">';
$icon = ( ! empty( $accordion['icon'] ) ) ? 'csf--icon '. $accordion['icon'] : 'csf-accordion-icon fas fa-angle-right';
echo '<h4 class="csf-accordion-title">';
echo '<i class="'. esc_attr( $icon ) .'"></i>';
echo esc_html( $accordion['title'] );
echo '</h4>';
echo '<div class="csf-accordion-content">';
foreach ( $accordion['fields'] as $field ) {
if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
CSF::field( $field, $field_value, $unique_id, 'field/accordion' );
}
echo '</div>';
echo '</div>';
}
echo '</div>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,340 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: background
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_background' ) ) {
class CSF_Field_background extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'background_color' => true,
'background_image' => true,
'background_position' => true,
'background_repeat' => true,
'background_attachment' => true,
'background_size' => true,
'background_origin' => false,
'background_clip' => false,
'background_blend_mode' => false,
'background_gradient' => false,
'background_gradient_color' => true,
'background_gradient_direction' => true,
'background_image_preview' => true,
'background_auto_attributes' => false,
'compact' => false,
'background_image_library' => 'image',
'background_image_placeholder' => esc_html__( 'Not selected', 'csf' ),
) );
if ( $args['compact'] ) {
$args['background_color'] = false;
$args['background_auto_attributes'] = true;
}
$default_value = array(
'background-color' => '',
'background-image' => '',
'background-position' => '',
'background-repeat' => '',
'background-attachment' => '',
'background-size' => '',
'background-origin' => '',
'background-clip' => '',
'background-blend-mode' => '',
'background-gradient-color' => '',
'background-gradient-direction' => '',
);
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
$this->value = wp_parse_args( $this->value, $default_value );
echo $this->field_before();
echo '<div class="csf--background-colors">';
//
// Background Color
if ( ! empty( $args['background_color'] ) ) {
echo '<div class="csf--color">';
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'From', 'csf' ) .'</div>' : '';
CSF::field( array(
'id' => 'background-color',
'type' => 'color',
'default' => $default_value['background-color'],
), $this->value['background-color'], $this->field_name(), 'field/background' );
echo '</div>';
}
//
// Background Gradient Color
if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) {
echo '<div class="csf--color">';
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'To', 'csf' ) .'</div>' : '';
CSF::field( array(
'id' => 'background-gradient-color',
'type' => 'color',
'default' => $default_value['background-gradient-color'],
), $this->value['background-gradient-color'], $this->field_name(), 'field/background' );
echo '</div>';
}
//
// Background Gradient Direction
if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) {
echo '<div class="csf--color">';
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf---title">'. esc_html__( 'Direction', 'csf' ) .'</div>' : '';
CSF::field( array(
'id' => 'background-gradient-direction',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Gradient Direction', 'csf' ),
'to bottom' => esc_html__( '&#8659; top to bottom', 'csf' ),
'to right' => esc_html__( '&#8658; left to right', 'csf' ),
'135deg' => esc_html__( '&#8664; corner top to right', 'csf' ),
'-135deg' => esc_html__( '&#8665; corner top to left', 'csf' ),
),
), $this->value['background-gradient-direction'], $this->field_name(), 'field/background' );
echo '</div>';
}
echo '</div>';
//
// Background Image
if ( ! empty( $args['background_image'] ) ) {
echo '<div class="csf--background-image">';
CSF::field( array(
'id' => 'background-image',
'type' => 'media',
'class' => 'csf-assign-field-background',
'library' => $args['background_image_library'],
'preview' => $args['background_image_preview'],
'placeholder' => $args['background_image_placeholder'],
'attributes' => array( 'data-depend-id' => $this->field['id'] ),
), $this->value['background-image'], $this->field_name(), 'field/background' );
echo '</div>';
}
$auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' csf--auto-attributes' : '';
$hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' csf--attributes-hidden' : '';
echo '<div class="csf--background-attributes'. esc_attr( $auto_class . $hidden_class ) .'">';
//
// Background Position
if ( ! empty( $args['background_position'] ) ) {
CSF::field( array(
'id' => 'background-position',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Position', 'csf' ),
'left top' => esc_html__( 'Left Top', 'csf' ),
'left center' => esc_html__( 'Left Center', 'csf' ),
'left bottom' => esc_html__( 'Left Bottom', 'csf' ),
'center top' => esc_html__( 'Center Top', 'csf' ),
'center center' => esc_html__( 'Center Center', 'csf' ),
'center bottom' => esc_html__( 'Center Bottom', 'csf' ),
'right top' => esc_html__( 'Right Top', 'csf' ),
'right center' => esc_html__( 'Right Center', 'csf' ),
'right bottom' => esc_html__( 'Right Bottom', 'csf' ),
),
), $this->value['background-position'], $this->field_name(), 'field/background' );
}
//
// Background Repeat
if ( ! empty( $args['background_repeat'] ) ) {
CSF::field( array(
'id' => 'background-repeat',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Repeat', 'csf' ),
'repeat' => esc_html__( 'Repeat', 'csf' ),
'no-repeat' => esc_html__( 'No Repeat', 'csf' ),
'repeat-x' => esc_html__( 'Repeat Horizontally', 'csf' ),
'repeat-y' => esc_html__( 'Repeat Vertically', 'csf' ),
),
), $this->value['background-repeat'], $this->field_name(), 'field/background' );
}
//
// Background Attachment
if ( ! empty( $args['background_attachment'] ) ) {
CSF::field( array(
'id' => 'background-attachment',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Attachment', 'csf' ),
'scroll' => esc_html__( 'Scroll', 'csf' ),
'fixed' => esc_html__( 'Fixed', 'csf' ),
),
), $this->value['background-attachment'], $this->field_name(), 'field/background' );
}
//
// Background Size
if ( ! empty( $args['background_size'] ) ) {
CSF::field( array(
'id' => 'background-size',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Size', 'csf' ),
'cover' => esc_html__( 'Cover', 'csf' ),
'contain' => esc_html__( 'Contain', 'csf' ),
'auto' => esc_html__( 'Auto', 'csf' ),
),
), $this->value['background-size'], $this->field_name(), 'field/background' );
}
//
// Background Origin
if ( ! empty( $args['background_origin'] ) ) {
CSF::field( array(
'id' => 'background-origin',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Origin', 'csf' ),
'padding-box' => esc_html__( 'Padding Box', 'csf' ),
'border-box' => esc_html__( 'Border Box', 'csf' ),
'content-box' => esc_html__( 'Content Box', 'csf' ),
),
), $this->value['background-origin'], $this->field_name(), 'field/background' );
}
//
// Background Clip
if ( ! empty( $args['background_clip'] ) ) {
CSF::field( array(
'id' => 'background-clip',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Clip', 'csf' ),
'border-box' => esc_html__( 'Border Box', 'csf' ),
'padding-box' => esc_html__( 'Padding Box', 'csf' ),
'content-box' => esc_html__( 'Content Box', 'csf' ),
),
), $this->value['background-clip'], $this->field_name(), 'field/background' );
}
//
// Background Blend Mode
if ( ! empty( $args['background_blend_mode'] ) ) {
CSF::field( array(
'id' => 'background-blend-mode',
'type' => 'select',
'options' => array(
'' => esc_html__( 'Background Blend Mode', 'csf' ),
'normal' => esc_html__( 'Normal', 'csf' ),
'multiply' => esc_html__( 'Multiply', 'csf' ),
'screen' => esc_html__( 'Screen', 'csf' ),
'overlay' => esc_html__( 'Overlay', 'csf' ),
'darken' => esc_html__( 'Darken', 'csf' ),
'lighten' => esc_html__( 'Lighten', 'csf' ),
'color-dodge' => esc_html__( 'Color Dodge', 'csf' ),
'saturation' => esc_html__( 'Saturation', 'csf' ),
'color' => esc_html__( 'Color', 'csf' ),
'luminosity' => esc_html__( 'Luminosity', 'csf' ),
),
), $this->value['background-blend-mode'], $this->field_name(), 'field/background' );
}
echo '</div>';
echo $this->field_after();
}
public function output() {
$output = '';
$bg_image = array();
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
// Background image and gradient
$background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : '';
$background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : '';
$background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : '';
$background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : '';
if ( $background_color && $background_gd_color ) {
$gd_direction = ( $background_gd_direction ) ? $background_gd_direction .',' : '';
$bg_image[] = 'linear-gradient('. $gd_direction . $background_color .','. $background_gd_color .')';
unset( $this->value['background-color'] );
}
if ( $background_image ) {
$bg_image[] = 'url('. $background_image .')';
}
if ( ! empty( $bg_image ) ) {
$output .= 'background-image:'. implode( ',', $bg_image ) . $important .';';
}
// Common background properties
$properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' );
foreach ( $properties as $property ) {
$property = 'background-'. $property;
if ( ! empty( $this->value[$property] ) ) {
$output .= $property .':'. $this->value[$property] . $important .';';
}
}
if ( $output ) {
$output = $element .'{'. $output .'}';
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,38 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: backup
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_backup' ) ) {
class CSF_Field_backup extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$unique = $this->unique;
$nonce = wp_create_nonce( 'csf_backup_nonce' );
$export = add_query_arg( array( 'action' => 'csf-export', 'unique' => $unique, 'nonce' => $nonce ), admin_url( 'admin-ajax.php' ) );
echo $this->field_before();
echo '<textarea name="csf_import_data" class="csf-import-data"></textarea>';
echo '<button type="submit" class="button button-primary csf-confirm csf-import" data-unique="'. esc_attr( $unique ) .'" data-nonce="'. esc_attr( $nonce ) .'">'. esc_html__( 'Import', 'csf' ) .'</button>';
echo '<hr />';
echo '<textarea readonly="readonly" class="csf-export-data">'. esc_attr( json_encode( get_option( $unique ) ) ) .'</textarea>';
echo '<a href="'. esc_url( $export ) .'" class="button button-primary csf-export" target="_blank">'. esc_html__( 'Export & Download', 'csf' ) .'</a>';
echo '<hr />';
echo '<button type="submit" name="csf_transient[reset]" value="reset" class="button csf-warning-primary csf-confirm csf-reset" data-unique="'. esc_attr( $unique ) .'" data-nonce="'. esc_attr( $nonce ) .'">'. esc_html__( 'Reset', 'csf' ) .'</button>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,176 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: border
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_border' ) ) {
class CSF_Field_border extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
'all_icon' => '<i class="fas fa-arrows-alt"></i>',
'top_placeholder' => esc_html__( 'top', 'csf' ),
'right_placeholder' => esc_html__( 'right', 'csf' ),
'bottom_placeholder' => esc_html__( 'bottom', 'csf' ),
'left_placeholder' => esc_html__( 'left', 'csf' ),
'all_placeholder' => esc_html__( 'all', 'csf' ),
'top' => true,
'left' => true,
'bottom' => true,
'right' => true,
'all' => false,
'color' => true,
'style' => true,
'unit' => 'px',
) );
$default_value = array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
'color' => '',
'style' => 'solid',
'all' => '',
);
$border_props = array(
'solid' => esc_html__( 'Solid', 'csf' ),
'dashed' => esc_html__( 'Dashed', 'csf' ),
'dotted' => esc_html__( 'Dotted', 'csf' ),
'double' => esc_html__( 'Double', 'csf' ),
'inset' => esc_html__( 'Inset', 'csf' ),
'outset' => esc_html__( 'Outset', 'csf' ),
'groove' => esc_html__( 'Groove', 'csf' ),
'ridge' => esc_html__( 'ridge', 'csf' ),
'none' => esc_html__( 'None', 'csf' )
);
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
$value = wp_parse_args( $this->value, $default_value );
echo $this->field_before();
echo '<div class="csf--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
if ( ! empty( $args['all'] ) ) {
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['all_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="csf-input-number csf--is-unit" step="any" />';
echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
echo '</div>';
} else {
$properties = array();
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
if ( ! empty( $args[$prop] ) ) {
$properties[] = $prop;
}
}
$properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
foreach ( $properties as $property ) {
$placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args[$property.'_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="csf-input-number csf--is-unit" step="any" />';
echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
echo '</div>';
}
}
if ( ! empty( $args['style'] ) ) {
echo '<div class="csf--input">';
echo '<select name="'. esc_attr( $this->field_name( '[style]' ) ) .'">';
foreach ( $border_props as $border_prop_key => $border_prop_value ) {
$selected = ( $value['style'] === $border_prop_key ) ? ' selected' : '';
echo '<option value="'. esc_attr( $border_prop_key ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $border_prop_value ) .'</option>';
}
echo '</select>';
echo '</div>';
}
echo '</div>';
if ( ! empty( $args['color'] ) ) {
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : '';
echo '<div class="csf--color">';
echo '<div class="csf-field-color">';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" value="'. esc_attr( $value['color'] ) .'" class="csf-color"'. $default_color_attr .' />';
echo '</div>';
echo '</div>';
}
echo $this->field_after();
}
public function output() {
$output = '';
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
// properties
$top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $this->value['top'] : '';
$right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $this->value['right'] : '';
$bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $this->value['bottom'] : '';
$left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $this->value['left'] : '';
$style = ( isset( $this->value['style'] ) && $this->value['style'] !== '' ) ? $this->value['style'] : '';
$color = ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) ? $this->value['color'] : '';
$all = ( isset( $this->value['all'] ) && $this->value['all'] !== '' ) ? $this->value['all'] : '';
if ( ! empty( $this->field['all'] ) && ( $all !== '' || $color !== '' ) ) {
$output = $element .'{';
$output .= ( $all !== '' ) ? 'border-width:'. $all . $unit . $important .';' : '';
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
$output .= '}';
} else if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' || $color !== '' ) {
$output = $element .'{';
$output .= ( $top !== '' ) ? 'border-top-width:'. $top . $unit . $important .';' : '';
$output .= ( $right !== '' ) ? 'border-right-width:'. $right . $unit . $important .';' : '';
$output .= ( $bottom !== '' ) ? 'border-bottom-width:'. $bottom . $unit . $important .';' : '';
$output .= ( $left !== '' ) ? 'border-left-width:'. $left . $unit . $important .';' : '';
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
$output .= '}';
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: button_set
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_button_set' ) ) {
class CSF_Field_button_set extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'multiple' => false,
'options' => array(),
'query_args' => array(),
) );
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
echo $this->field_before();
if ( isset( $this->field['options'] ) ) {
$options = $this->field['options'];
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
if ( is_array( $options ) && ! empty( $options ) ) {
echo '<div class="csf-siblings csf--button-group" data-multiple="'. esc_attr( $args['multiple'] ) .'">';
foreach ( $options as $key => $option ) {
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio';
$extra = ( $args['multiple'] ) ? '[]' : '';
$active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' csf--active' : '';
$checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : '';
echo '<div class="csf--sibling csf--button'. esc_attr( $active ) .'">';
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo $option;
echo '</div>';
}
echo '</div>';
} else {
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
}
}
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,31 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: callback
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_callback' ) ) {
class CSF_Field_callback extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
if ( isset( $this->field['function'] ) && is_callable( $this->field['function'] ) ) {
$args = ( isset( $this->field['args'] ) ) ? $this->field['args'] : null;
call_user_func( $this->field['function'], $args );
}
}
}
}

View File

@@ -0,0 +1,95 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: checkbox
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_checkbox' ) ) {
class CSF_Field_checkbox extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'inline' => false,
'query_args' => array(),
) );
$inline_class = ( $args['inline'] ) ? ' class="csf--inline-list"' : '';
echo $this->field_before();
if ( isset( $this->field['options'] ) ) {
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
$options = $this->field['options'];
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
if ( is_array( $options ) && ! empty( $options ) ) {
echo '<ul'. $inline_class .'>';
foreach ( $options as $option_key => $option_value ) {
if ( is_array( $option_value ) && ! empty( $option_value ) ) {
echo '<li>';
echo '<ul>';
echo '<li><strong>'. esc_attr( $option_key ) .'</strong></li>';
foreach ( $option_value as $sub_key => $sub_value ) {
$checked = ( in_array( $sub_key, $value ) ) ? ' checked' : '';
echo '<li>';
echo '<label>';
echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $sub_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '<span class="csf--text">'. esc_attr( $sub_value ) .'</span>';
echo '</label>';
echo '</li>';
}
echo '</ul>';
echo '</li>';
} else {
$checked = ( in_array( $option_key, $value ) ) ? ' checked' : '';
echo '<li>';
echo '<label>';
echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $option_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '<span class="csf--text">'. esc_attr( $option_value ) .'</span>';
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
} else {
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
}
} else {
echo '<label class="csf-checkbox">';
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. $this->value .'" class="csf--input"'. $this->field_attributes() .'/>';
echo '<input type="checkbox" name="_pseudo" class="csf--checkbox"'. esc_attr( checked( $this->value, 1, false ) ) .'/>';
echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--text">'. esc_attr( $this->field['label'] ) .'</span>' : '';
echo '</label>';
}
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,58 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: code_editor
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_code_editor' ) ) {
class CSF_Field_code_editor extends CSF_Fields {
public $version = '5.60.0';
public $cdn_url = 'https://cdn.jsdelivr.net/npm/codemirror@';
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$default_settings = array(
'tabSize' => 2,
'lineNumbers' => true,
'theme' => 'default',
'mode' => 'htmlmixed',
'cdnURL' => $this->cdn_url . $this->version,
);
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
$settings = wp_parse_args( $settings, $default_settings );
echo $this->field_before();
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes() .' data-editor="'. esc_attr( json_encode( $settings ) ) .'">'. $this->value .'</textarea>';
echo $this->field_after();
}
public function enqueue() {
$page = ( ! empty( $_GET[ 'page' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'page' ] ) ) : '';
// Do not loads CodeMirror in revslider page.
if ( in_array( $page, array( 'revslider' ) ) ) { return; }
if ( ! wp_script_is( 'csf-codemirror' ) ) {
wp_enqueue_script( 'csf-codemirror', esc_url( $this->cdn_url . $this->version .'/lib/codemirror.min.js' ), array( 'csf' ), $this->version, true );
wp_enqueue_script( 'csf-codemirror-loadmode', esc_url( $this->cdn_url . $this->version .'/addon/mode/loadmode.min.js' ), array( 'csf-codemirror' ), $this->version, true );
}
if ( ! wp_style_is( 'csf-codemirror' ) ) {
wp_enqueue_style( 'csf-codemirror', esc_url( $this->cdn_url . $this->version .'/lib/codemirror.min.css' ), array(), $this->version );
}
}
}
}

View File

@@ -0,0 +1,52 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: color
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_color' ) ) {
class CSF_Field_color extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$default_attr = ( ! empty( $this->field['default'] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'] ) .'"' : '';
echo $this->field_before();
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="csf-color"'. $default_attr . $this->field_attributes() .'/>';
echo $this->field_after();
}
public function output() {
$output = '';
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'color';
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
foreach ( $elements as $key_property => $element ) {
if ( is_numeric( $key_property ) ) {
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $important .';}';
break;
} else {
$output .= $element .'{'. $key_property .':'. $this->value . $important .'}';
}
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,42 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: color_group
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_color_group' ) ) {
class CSF_Field_color_group extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$options = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
echo $this->field_before();
if ( ! empty( $options ) ) {
foreach ( $options as $key => $option ) {
$color_value = ( ! empty( $this->value[$key] ) ) ? $this->value[$key] : '';
$default_attr = ( ! empty( $this->field['default'][$key] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'][$key] ) .'"' : '';
echo '<div class="csf--left csf-field-color">';
echo '<div class="csf--title">'. $option .'</div>';
echo '<input type="text" name="'. esc_attr( $this->field_name( '['. $key .']' ) ) .'" value="'. esc_attr( $color_value ) .'" class="csf-color"'. $default_attr . $this->field_attributes() .'/>';
echo '</div>';
}
}
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,28 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: content
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_content' ) ) {
class CSF_Field_content extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
if ( ! empty( $this->field['content'] ) ) {
echo $this->field['content'];
}
}
}
}

View File

@@ -0,0 +1,64 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: date
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_date' ) ) {
class CSF_Field_date extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$default_settings = array(
'dateFormat' => 'mm/dd/yy',
);
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
$settings = wp_parse_args( $settings, $default_settings );
echo $this->field_before();
if ( ! empty( $this->field['from_to'] ) ) {
$args = wp_parse_args( $this->field, array(
'text_from' => esc_html__( 'From', 'csf' ),
'text_to' => esc_html__( 'To', 'csf' ),
) );
$value = wp_parse_args( $this->value, array(
'from' => '',
'to' => '',
) );
echo '<label class="csf--from">'. esc_attr( $args['text_from'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[from]' ) ) .'" value="'. esc_attr( $value['from'] ) .'"'. $this->field_attributes() .'/></label>';
echo '<label class="csf--to">'. esc_attr( $args['text_to'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[to]' ) ) .'" value="'. esc_attr( $value['to'] ) .'"'. $this->field_attributes() .'/></label>';
} else {
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
}
echo '<div class="csf-date-settings" data-settings="'. esc_attr( json_encode( $settings ) ) .'"></div>';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) {
wp_enqueue_script( 'jquery-ui-datepicker' );
}
}
}
}

View File

@@ -0,0 +1,101 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: dimensions
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_dimensions' ) ) {
class CSF_Field_dimensions extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'width_icon' => '<i class="fas fa-arrows-alt-h"></i>',
'height_icon' => '<i class="fas fa-arrows-alt-v"></i>',
'width_placeholder' => esc_html__( 'width', 'csf' ),
'height_placeholder' => esc_html__( 'height', 'csf' ),
'width' => true,
'height' => true,
'unit' => true,
'show_units' => true,
'units' => array( 'px', '%', 'em' )
) );
$default_values = array(
'width' => '',
'height' => '',
'unit' => 'px',
);
$value = wp_parse_args( $this->value, $default_values );
$unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
$is_unit = ( ! empty( $unit ) ) ? ' csf--is-unit' : '';
echo $this->field_before();
echo '<div class="csf--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
if ( ! empty( $args['width'] ) ) {
$placeholder = ( ! empty( $args['width_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['width_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args['width_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['width_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $value['width'] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
echo ( ! empty( $unit ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
echo '</div>';
}
if ( ! empty( $args['height'] ) ) {
$placeholder = ( ! empty( $args['height_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['height_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args['height_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['height_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $value['height'] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
echo ( ! empty( $unit ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
echo '</div>';
}
if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
echo '<div class="csf--input">';
echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
foreach ( $args['units'] as $unit ) {
$selected = ( $value['unit'] === $unit ) ? ' selected' : '';
echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
}
echo '</select>';
echo '</div>';
}
echo '</div>';
echo $this->field_after();
}
public function output() {
$output = '';
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
$prefix = ( ! empty( $this->field['output_prefix'] ) ) ? $this->field['output_prefix'] .'-' : '';
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
$width = ( isset( $this->value['width'] ) && $this->value['width'] !== '' ) ? $prefix .'width:'. $this->value['width'] . $unit . $important .';' : '';
$height = ( isset( $this->value['height'] ) && $this->value['height'] !== '' ) ? $prefix .'height:'. $this->value['height'] . $unit . $important .';' : '';
if ( $width !== '' || $height !== '' ) {
$output = $element .'{'. $width . $height .'}';
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,41 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: fieldset
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_fieldset' ) ) {
class CSF_Field_fieldset extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo $this->field_before();
echo '<div class="csf-fieldset-content" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
foreach ( $this->field['fields'] as $field ) {
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
CSF::field( $field, $field_value, $unique_id, 'field/fieldset' );
}
echo '</div>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,52 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: gallery
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_gallery' ) ) {
class CSF_Field_gallery extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'add_title' => esc_html__( 'Add Gallery', 'csf' ),
'edit_title' => esc_html__( 'Edit Gallery', 'csf' ),
'clear_title' => esc_html__( 'Clear', 'csf' ),
) );
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
echo $this->field_before();
echo '<ul>';
if ( ! empty( $this->value ) ) {
$values = explode( ',', $this->value );
foreach ( $values as $id ) {
$attachment = wp_get_attachment_image_src( $id, 'thumbnail' );
echo '<li><img src="'. esc_url( $attachment[0] ) .'" /></li>';
}
}
echo '</ul>';
echo '<a href="#" class="button button-primary csf-button">'. $args['add_title'] .'</a>';
echo '<a href="#" class="button csf-edit-gallery'. esc_attr( $hidden ) .'">'. $args['edit_title'] .'</a>';
echo '<a href="#" class="button csf-warning-primary csf-clear-gallery'. esc_attr( $hidden ) .'">'. $args['clear_title'] .'</a>';
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,144 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: group
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_group' ) ) {
class CSF_Field_group extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'max' => 0,
'min' => 0,
'fields' => array(),
'button_title' => esc_html__( 'Add New', 'csf' ),
'accordion_title_prefix' => '',
'accordion_title_number' => false,
'accordion_title_auto' => true,
) );
$title_prefix = ( ! empty( $args['accordion_title_prefix'] ) ) ? $args['accordion_title_prefix'] : '';
$title_number = ( ! empty( $args['accordion_title_number'] ) ) ? true : false;
$title_auto = ( ! empty( $args['accordion_title_auto'] ) ) ? true : false;
if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
echo '<div class="csf-notice csf-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'csf' ) .'</div>';
} else {
echo $this->field_before();
echo '<div class="csf-cloneable-item csf-cloneable-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
echo '<div class="csf-cloneable-helper">';
echo '<i class="csf-cloneable-sort fas fa-arrows-alt"></i>';
echo '<i class="csf-cloneable-clone far fa-clone"></i>';
echo '<i class="csf-cloneable-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
echo '</div>';
echo '<h4 class="csf-cloneable-title">';
echo '<span class="csf-cloneable-text">';
echo ( $title_number ) ? '<span class="csf-cloneable-title-number"></span>' : '';
echo ( $title_prefix ) ? '<span class="csf-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
echo ( $title_auto ) ? '<span class="csf-cloneable-value"><span class="csf-cloneable-placeholder"></span></span>' : '';
echo '</span>';
echo '</h4>';
echo '<div class="csf-cloneable-content">';
foreach ( $this->field['fields'] as $field ) {
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
CSF::field( $field, $field_default, '___'. $field_unique, 'field/group' );
}
echo '</div>';
echo '</div>';
echo '<div class="csf-cloneable-wrapper csf-data-wrapper" data-title-number="'. esc_attr( $title_number ) .'" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
if ( ! empty( $this->value ) ) {
$num = 0;
foreach ( $this->value as $value ) {
$first_id = ( isset( $this->field['fields'][0]['id'] ) ) ? $this->field['fields'][0]['id'] : '';
$first_value = ( isset( $value[$first_id] ) ) ? $value[$first_id] : '';
$first_value = ( is_array( $first_value ) ) ? reset( $first_value ) : $first_value;
echo '<div class="csf-cloneable-item">';
echo '<div class="csf-cloneable-helper">';
echo '<i class="csf-cloneable-sort fas fa-arrows-alt"></i>';
echo '<i class="csf-cloneable-clone far fa-clone"></i>';
echo '<i class="csf-cloneable-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
echo '</div>';
echo '<h4 class="csf-cloneable-title">';
echo '<span class="csf-cloneable-text">';
echo ( $title_number ) ? '<span class="csf-cloneable-title-number">'. esc_attr( $num+1 ) .'.</span>' : '';
echo ( $title_prefix ) ? '<span class="csf-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
echo ( $title_auto ) ? '<span class="csf-cloneable-value">' . esc_attr( $first_value ) .'</span>' : '';
echo '</span>';
echo '</h4>';
echo '<div class="csf-cloneable-content">';
foreach ( $this->field['fields'] as $field ) {
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
$field_value = ( isset( $field['id'] ) && isset( $value[$field['id']] ) ) ? $value[$field['id']] : '';
CSF::field( $field, $field_value, $field_unique, 'field/group' );
}
echo '</div>';
echo '</div>';
$num++;
}
}
echo '</div>';
echo '<div class="csf-cloneable-alert csf-cloneable-max">'. esc_html__( 'You cannot add more.', 'csf' ) .'</div>';
echo '<div class="csf-cloneable-alert csf-cloneable-min">'. esc_html__( 'You cannot remove more.', 'csf' ) .'</div>';
echo '<a href="#" class="button button-primary csf-cloneable-add">'. $args['button_title'] .'</a>';
echo $this->field_after();
}
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-accordion' ) ) {
wp_enqueue_script( 'jquery-ui-accordion' );
}
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}

View File

@@ -0,0 +1,24 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: heading
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_heading' ) ) {
class CSF_Field_heading extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo ( ! empty( $this->field['content'] ) ) ? $this->field['content'] : '';
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,71 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: icon
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_icon' ) ) {
class CSF_Field_icon extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'button_title' => esc_html__( 'Add Icon', 'csf' ),
'remove_title' => esc_html__( 'Remove Icon', 'csf' ),
) );
echo $this->field_before();
$nonce = wp_create_nonce( 'csf_icon_nonce' );
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
echo '<div class="csf-icon-select">';
echo '<span class="csf-icon-preview'. esc_attr( $hidden ) .'"><i class="'. esc_attr( $this->value ) .'"></i></span>';
echo '<a href="#" class="button button-primary csf-icon-add" data-nonce="'. esc_attr( $nonce ) .'">'. $args['button_title'] .'</a>';
echo '<a href="#" class="button csf-warning-primary csf-icon-remove'. esc_attr( $hidden ) .'">'. $args['remove_title'] .'</a>';
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="csf-icon-value"'. $this->field_attributes() .' />';
echo '</div>';
echo $this->field_after();
}
public function enqueue() {
add_action( 'admin_footer', array( &$this, 'add_footer_modal_icon' ) );
add_action( 'customize_controls_print_footer_scripts', array( &$this, 'add_footer_modal_icon' ) );
}
public function add_footer_modal_icon() {
?>
<div id="csf-modal-icon" class="csf-modal csf-modal-icon hidden">
<div class="csf-modal-table">
<div class="csf-modal-table-cell">
<div class="csf-modal-overlay"></div>
<div class="csf-modal-inner">
<div class="csf-modal-title">
<?php esc_html_e( 'Add Icon', 'csf' ); ?>
<div class="csf-modal-close csf-icon-close"></div>
</div>
<div class="csf-modal-header">
<input type="text" placeholder="<?php esc_html_e( 'Search...', 'csf' ); ?>" class="csf-icon-search" />
</div>
<div class="csf-modal-content">
<div class="csf-modal-loading"><div class="csf-loading"></div></div>
<div class="csf-modal-load"></div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
}

View File

@@ -0,0 +1,79 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: image_select
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_image_select' ) ) {
class CSF_Field_image_select extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'multiple' => false,
'inline' => false,
'options' => array(),
) );
$inline = ( $args['inline'] ) ? ' csf--inline-list' : '';
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
echo $this->field_before();
if ( ! empty( $args['options'] ) ) {
echo '<div class="csf-siblings csf--image-group'. esc_attr( $inline ) .'" data-multiple="'. esc_attr( $args['multiple'] ) .'">';
$num = 1;
foreach ( $args['options'] as $key => $option ) {
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio';
$extra = ( $args['multiple'] ) ? '[]' : '';
$active = ( in_array( $key, $value ) ) ? ' csf--active' : '';
$checked = ( in_array( $key, $value ) ) ? ' checked' : '';
echo '<div class="csf--sibling csf--image'. esc_attr( $active ) .'">';
echo '<figure>';
echo '<img src="'. esc_url( $option ) .'" alt="img-'. esc_attr( $num++ ) .'" />';
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '</figure>';
echo '</div>';
}
echo '</div>';
}
echo $this->field_after();
}
public function output() {
$output = '';
$bg_image = array();
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
$output = $elements .'{background-image:url('. $this->value .')'. $important .';}';
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden.

View File

@@ -0,0 +1,82 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: link
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_link' ) ) {
class CSF_Field_link extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'add_title' => esc_html__( 'Add Link', 'csf' ),
'edit_title' => esc_html__( 'Edit Link', 'csf' ),
'remove_title' => esc_html__( 'Remove Link', 'csf' ),
) );
$default_values = array(
'url' => '',
'text' => '',
'target' => '',
);
$value = wp_parse_args( $this->value, $default_values );
$hidden = ( ! empty( $value['url'] ) || ! empty( $value['url'] ) || ! empty( $value['url'] ) ) ? ' hidden' : '';
$maybe_hidden = ( empty( $hidden ) ) ? ' hidden' : '';
echo $this->field_before();
echo '<textarea readonly="readonly" class="csf--link hidden"></textarea>';
echo '<div class="'. esc_attr( $maybe_hidden ) .'"><div class="csf--result">'. sprintf( '{url:"%s", text:"%s", target:"%s"}', $value['url'], $value['text'], $value['target'] ) .'</div></div>';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $value['url'] ) .'"'. $this->field_attributes( array( 'class' => 'csf--url hidden' ) ) .' />';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[text]' ) ) .'" value="'. esc_attr( $value['text'] ) .'" class="csf--text hidden" />';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[target]' ) ) .'" value="'. esc_attr( $value['target'] ) .'" class="csf--target hidden" />';
echo '<a href="#" class="button button-primary csf--add'. esc_attr( $hidden ) .'">'. $args['add_title'] .'</a> ';
echo '<a href="#" class="button csf--edit'. esc_attr( $maybe_hidden ) .'">'. $args['edit_title'] .'</a> ';
echo '<a href="#" class="button csf-warning-primary csf--remove'. esc_attr( $maybe_hidden ) .'">'. $args['remove_title'] .'</a>';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'wplink' ) ) {
wp_enqueue_script( 'wplink' );
}
if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
wp_enqueue_script( 'jquery-ui-autocomplete' );
}
add_action( 'admin_print_footer_scripts', array( &$this, 'add_wp_link_dialog' ) );
}
public function add_wp_link_dialog() {
if ( ! class_exists( '_WP_Editors' ) ) {
require_once ABSPATH . WPINC .'/class-wp-editor.php';
}
wp_print_styles( 'editor-buttons' );
_WP_Editors::wp_link_dialog();
}
}
}

View File

@@ -0,0 +1,91 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: link_color
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_link_color' ) ) {
class CSF_Field_link_color extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'color' => true,
'hover' => true,
'active' => false,
'visited' => false,
'focus' => false,
) );
$default_values = array(
'color' => '',
'hover' => '',
'active' => '',
'visited' => '',
'focus' => '',
);
$color_props = array(
'color' => esc_html__( 'Normal', 'csf' ),
'hover' => esc_html__( 'Hover', 'csf' ),
'active' => esc_html__( 'Active', 'csf' ),
'visited' => esc_html__( 'Visited', 'csf' ),
'focus' => esc_html__( 'Focus', 'csf' )
);
$value = wp_parse_args( $this->value, $default_values );
echo $this->field_before();
foreach ( $color_props as $color_prop_key => $color_prop_value ) {
if ( ! empty( $args[$color_prop_key] ) ) {
$default_attr = ( ! empty( $this->field['default'][$color_prop_key] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'][$color_prop_key] ) .'"' : '';
echo '<div class="csf--left csf-field-color">';
echo '<div class="csf--title">'. esc_attr( $color_prop_value ) .'</div>';
echo '<input type="text" name="'. esc_attr( $this->field_name( '['. $color_prop_key .']' ) ) .'" value="'. esc_attr( $value[$color_prop_key] ) .'" class="csf-color"'. $default_attr . $this->field_attributes() .'/>';
echo '</div>';
}
}
echo $this->field_after();
}
public function output() {
$output = '';
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
foreach ( $elements as $element ) {
if ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) { $output .= $element .'{color:'. $this->value['color'] . $important .';}'; }
if ( isset( $this->value['hover'] ) && $this->value['hover'] !== '' ) { $output .= $element .':hover{color:'. $this->value['hover'] . $important .';}'; }
if ( isset( $this->value['active'] ) && $this->value['active'] !== '' ) { $output .= $element .':active{color:'. $this->value['active'] . $important .';}'; }
if ( isset( $this->value['visited'] ) && $this->value['visited'] !== '' ) { $output .= $element .':visited{color:'. $this->value['visited'] . $important .';}'; }
if ( isset( $this->value['focus'] ) && $this->value['focus'] !== '' ) { $output .= $element .':focus{color:'. $this->value['focus'] . $important .';}'; }
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,98 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: map
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_map' ) ) {
class CSF_Field_map extends CSF_Fields {
public $version = '1.7.1';
public $cdn_url = 'https://cdn.jsdelivr.net/npm/leaflet@';
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'placeholder' => esc_html__( 'Search...', 'csf' ),
'latitude_text' => esc_html__( 'Latitude', 'csf' ),
'longitude_text' => esc_html__( 'Longitude', 'csf' ),
'address_field' => '',
'height' => '',
) );
$value = wp_parse_args( $this->value, array(
'address' => '',
'latitude' => '20',
'longitude' => '0',
'zoom' => '2',
) );
$default_settings = array(
'center' => array( $value['latitude'], $value['longitude'] ),
'zoom' => $value['zoom'],
'scrollWheelZoom' => false,
);
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
$settings = wp_parse_args( $settings, $default_settings );
$style_attr = ( ! empty( $args['height'] ) ) ? ' style="min-height:'. esc_attr( $args['height'] ) .';"' : '';
$placeholder = ( ! empty( $args['placeholder'] ) ) ? array( 'placeholder' => $args['placeholder'] ) : '';
echo $this->field_before();
if ( empty( $args['address_field'] ) ) {
echo '<div class="csf--map-search">';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[address]' ) ) .'" value="'. esc_attr( $value['address'] ) .'"'. $this->field_attributes( $placeholder ) .' />';
echo '</div>';
} else {
echo '<div class="csf--address-field" data-address-field="'. esc_attr( $args['address_field'] ) .'"></div>';
}
echo '<div class="csf--map-osm-wrap"><div class="csf--map-osm" data-map="'. esc_attr( json_encode( $settings ) ) .'"'. $style_attr .'></div></div>';
echo '<div class="csf--map-inputs">';
echo '<div class="csf--map-input">';
echo '<label>'. esc_attr( $args['latitude_text'] ) .'</label>';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[latitude]' ) ) .'" value="'. esc_attr( $value['latitude'] ) .'" class="csf--latitude" />';
echo '</div>';
echo '<div class="csf--map-input">';
echo '<label>'. esc_attr( $args['longitude_text'] ) .'</label>';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[longitude]' ) ) .'" value="'. esc_attr( $value['longitude'] ) .'" class="csf--longitude" />';
echo '</div>';
echo '</div>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[zoom]' ) ) .'" value="'. esc_attr( $value['zoom'] ) .'" class="csf--zoom" />';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'csf-leaflet' ) ) {
wp_enqueue_script( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.js' ), array( 'csf' ), $this->version, true );
}
if ( ! wp_style_is( 'csf-leaflet' ) ) {
wp_enqueue_style( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.css' ), array(), $this->version );
}
if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
wp_enqueue_script( 'jquery-ui-autocomplete' );
}
}
}
}

View File

@@ -0,0 +1,86 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: media
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_media' ) ) {
class CSF_Field_media extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'url' => true,
'preview' => true,
'library' => array(),
'button_title' => esc_html__( 'Upload', 'csf' ),
'remove_title' => esc_html__( 'Remove', 'csf' ),
'preview_size' => 'thumbnail',
) );
$default_values = array(
'url' => '',
'id' => '',
'width' => '',
'height' => '',
'thumbnail' => '',
'alt' => '',
'title' => '',
'description' => ''
);
// fallback
if ( is_numeric( $this->value ) ) {
$this->value = array(
'id' => $this->value,
'url' => wp_get_attachment_url( $this->value ),
'thumbnail' => wp_get_attachment_image_src( $this->value, 'thumbnail', true )[0],
);
}
$this->value = wp_parse_args( $this->value, $default_values );
$library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
$library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
$preview_src = ( $args['preview_size'] !== 'thumbnail' ) ? $this->value['url'] : $this->value['thumbnail'];
$hidden_url = ( empty( $args['url'] ) ) ? ' hidden' : '';
$hidden_auto = ( empty( $this->value['url'] ) ) ? ' hidden' : '';
$placeholder = ( empty( $this->field['placeholder'] ) ) ? ' placeholder="'. esc_html__( 'Not selected', 'csf' ) .'"' : '';
echo $this->field_before();
if ( ! empty( $args['preview'] ) ) {
echo '<div class="csf--preview'. esc_attr( $hidden_auto ) .'">';
echo '<div class="csf-image-preview"><a href="#" class="csf--remove fas fa-times"></a><img src="'. esc_url( $preview_src ) .'" class="csf--src" /></div>';
echo '</div>';
}
echo '<div class="csf--placeholder">';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $this->value['url'] ) .'" class="csf--url'. esc_attr( $hidden_url ) .'" readonly="readonly"'. $this->field_attributes() . $placeholder .' />';
echo '<a href="#" class="button button-primary csf--button" data-library="'. esc_attr( $library ) .'" data-preview-size="'. esc_attr( $args['preview_size'] ) .'">'. $args['button_title'] .'</a>';
echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary csf-warning-primary csf--remove'. esc_attr( $hidden_auto ) .'">'. $args['remove_title'] .'</a>' : '';
echo '</div>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[id]' ) ) .'" value="'. esc_attr( $this->value['id'] ) .'" class="csf--id"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $this->value['width'] ) .'" class="csf--width"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $this->value['height'] ) .'" class="csf--height"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[thumbnail]' ) ) .'" value="'. esc_attr( $this->value['thumbnail'] ) .'" class="csf--thumbnail"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[alt]' ) ) .'" value="'. esc_attr( $this->value['alt'] ) .'" class="csf--alt"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[title]' ) ) .'" value="'. esc_attr( $this->value['title'] ) .'" class="csf--title"/>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[description]' ) ) .'" value="'. esc_attr( $this->value['description'] ) .'" class="csf--description"/>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,26 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: notice
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_notice' ) ) {
class CSF_Field_notice extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$style = ( ! empty( $this->field['style'] ) ) ? $this->field['style'] : 'normal';
echo ( ! empty( $this->field['content'] ) ) ? '<div class="csf-notice csf-notice-'. esc_attr( $style ) .'">'. $this->field['content'] .'</div>' : '';
}
}
}

View File

@@ -0,0 +1,60 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: number
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_number' ) ) {
class CSF_Field_number extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'unit' => '',
) );
echo $this->field_before();
echo '<div class="csf--wrap">';
echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'csf-input-number' ) ) .' step="any" />';
echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
echo '</div>';
echo $this->field_after();
}
public function output() {
$output = '';
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
foreach ( $elements as $key_property => $element ) {
if ( is_numeric( $key_property ) ) {
if ( $mode ) {
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
}
break;
} else {
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
}
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,58 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: palette
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_palette' ) ) {
class CSF_Field_palette extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$palette = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
echo $this->field_before();
if ( ! empty( $palette ) ) {
echo '<div class="csf-siblings csf--palettes">';
foreach ( $palette as $key => $colors ) {
$active = ( $key === $this->value ) ? ' csf--active' : '';
$checked = ( $key === $this->value ) ? ' checked' : '';
echo '<div class="csf--sibling csf--palette'. esc_attr( $active ) .'">';
if ( ! empty( $colors ) ) {
foreach ( $colors as $color ) {
echo '<span style="background-color: '. esc_attr( $color ) .';"></span>';
}
}
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '</div>';
}
echo '</div>';
}
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,93 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: radio
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_radio' ) ) {
class CSF_Field_radio extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'inline' => false,
'query_args' => array(),
) );
$inline_class = ( $args['inline'] ) ? ' class="csf--inline-list"' : '';
echo $this->field_before();
if ( isset( $this->field['options'] ) ) {
$options = $this->field['options'];
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
if ( is_array( $options ) && ! empty( $options ) ) {
echo '<ul'. $inline_class .'>';
foreach ( $options as $option_key => $option_value ) {
if ( is_array( $option_value ) && ! empty( $option_value ) ) {
echo '<li>';
echo '<ul>';
echo '<li><strong>'. esc_attr( $option_key ) .'</strong></li>';
foreach ( $option_value as $sub_key => $sub_value ) {
$checked = ( $sub_key == $this->value ) ? ' checked' : '';
echo '<li>';
echo '<label>';
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $sub_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '<span class="csf--text">'. esc_attr( $sub_value ) .'</span>';
echo '</label>';
echo '</li>';
}
echo '</ul>';
echo '</li>';
} else {
$checked = ( $option_key == $this->value ) ? ' checked' : '';
echo '<li>';
echo '<label>';
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $option_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
echo '<span class="csf--text">'. esc_attr( $option_value ) .'</span>';
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
} else {
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
}
} else {
$label = ( isset( $this->field['label'] ) ) ? $this->field['label'] : '';
echo '<label><input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="1"'. $this->field_attributes() . esc_attr( checked( $this->value, 1, false ) ) .'/>';
echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--text">'. esc_attr( $this->field['label'] ) .'</span>' : '';
echo '</label>';
}
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,108 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: repeater
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_repeater' ) ) {
class CSF_Field_repeater extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'max' => 0,
'min' => 0,
'button_title' => '<i class="fas fa-plus-circle"></i>',
) );
if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
echo '<div class="csf-notice csf-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'csf' ) .'</div>';
} else {
echo $this->field_before();
echo '<div class="csf-repeater-item csf-repeater-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
echo '<div class="csf-repeater-content">';
foreach ( $this->field['fields'] as $field ) {
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
CSF::field( $field, $field_default, '___'. $field_unique, 'field/repeater' );
}
echo '</div>';
echo '<div class="csf-repeater-helper">';
echo '<div class="csf-repeater-helper-inner">';
echo '<i class="csf-repeater-sort fas fa-arrows-alt"></i>';
echo '<i class="csf-repeater-clone far fa-clone"></i>';
echo '<i class="csf-repeater-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="csf-repeater-wrapper csf-data-wrapper" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
if ( ! empty( $this->value ) && is_array( $this->value ) ) {
$num = 0;
foreach ( $this->value as $key => $value ) {
echo '<div class="csf-repeater-item">';
echo '<div class="csf-repeater-content">';
foreach ( $this->field['fields'] as $field ) {
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
$field_value = ( isset( $field['id'] ) && isset( $this->value[$key][$field['id']] ) ) ? $this->value[$key][$field['id']] : '';
CSF::field( $field, $field_value, $field_unique, 'field/repeater' );
}
echo '</div>';
echo '<div class="csf-repeater-helper">';
echo '<div class="csf-repeater-helper-inner">';
echo '<i class="csf-repeater-sort fas fa-arrows-alt"></i>';
echo '<i class="csf-repeater-clone far fa-clone"></i>';
echo '<i class="csf-repeater-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
echo '</div>';
echo '</div>';
echo '</div>';
$num++;
}
}
echo '</div>';
echo '<div class="csf-repeater-alert csf-repeater-max">'. esc_html__( 'You cannot add more.', 'csf' ) .'</div>';
echo '<div class="csf-repeater-alert csf-repeater-min">'. esc_html__( 'You cannot remove more.', 'csf' ) .'</div>';
echo '<a href="#" class="button button-primary csf-repeater-add">'. $args['button_title'] .'</a>';
echo $this->field_after();
}
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}

View File

@@ -0,0 +1,132 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: select
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_select' ) ) {
class CSF_Field_select extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'placeholder' => '',
'chosen' => false,
'multiple' => false,
'sortable' => false,
'ajax' => false,
'settings' => array(),
'query_args' => array(),
) );
$this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
echo $this->field_before();
if ( isset( $this->field['options'] ) ) {
if ( ! empty( $args['ajax'] ) ) {
$args['settings']['data']['type'] = $args['options'];
$args['settings']['data']['nonce'] = wp_create_nonce( 'csf_chosen_ajax_nonce' );
if ( ! empty( $args['query_args'] ) ) {
$args['settings']['data']['query_args'] = $args['query_args'];
}
}
$chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
$multiple_name = ( $args['multiple'] ) ? '[]' : '';
$multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
$chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' csf-chosen-sortable' : '';
$chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' csf-chosen-ajax' : '';
$placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="'. esc_attr( $args['placeholder'] ) .'"' : '';
$field_class = ( $args['chosen'] ) ? ' class="csf-chosen'. esc_attr( $chosen_rtl . $chosen_sortable . $chosen_ajax ) .'"' : '';
$field_name = $this->field_name( $multiple_name );
$field_attr = $this->field_attributes();
$maybe_options = $this->field['options'];
$chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="'. esc_attr( json_encode( $args['settings'] ) ) .'"' : '';
if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
$options = $this->field_wp_query_data_title( $maybe_options, $this->value );
} else if ( is_string( $maybe_options ) ) {
$options = $this->field_data( $maybe_options, false, $args['query_args'] );
} else {
$options = $maybe_options;
}
if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
echo '<select name="'. $field_name .'" class="csf-hide-select hidden"'. $multiple_attr . $field_attr .'>';
foreach ( $this->value as $option_key ) {
echo '<option value="'. esc_attr( $option_key ) .'" selected>'. esc_attr( $option_key ) .'</option>';
}
echo '</select>';
$field_name = '_pseudo';
$field_attr = '';
}
// These attributes has been serialized above.
echo '<select name="'. esc_attr( $field_name ) .'"'. $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr .'>';
if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
if ( ! empty( $args['chosen'] ) ) {
echo '<option value=""></option>';
} else {
echo '<option value="">'. esc_attr( $args['placeholder'] ) .'</option>';
}
}
foreach ( $options as $option_key => $option ) {
if ( is_array( $option ) && ! empty( $option ) ) {
echo '<optgroup label="'. esc_attr( $option_key ) .'">';
foreach ( $option as $sub_key => $sub_value ) {
$selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
echo '<option value="'. esc_attr( $sub_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $sub_value ) .'</option>';
}
echo '</optgroup>';
} else {
$selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
echo '<option value="'. esc_attr( $option_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $option ) .'</option>';
}
}
echo '</select>';
} else {
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
}
}
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}

View File

@@ -0,0 +1,78 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: slider
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_slider' ) ) {
class CSF_Field_slider extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'max' => 100,
'min' => 0,
'step' => 1,
'unit' => '',
) );
$is_unit = ( ! empty( $args['unit'] ) ) ? ' csf--is-unit' : '';
echo $this->field_before();
echo '<div class="csf--wrap">';
echo '<div class="csf-slider-ui"></div>';
echo '<div class="csf--input">';
echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'csf-input-number'. esc_attr( $is_unit ) ) ) .' data-min="'. esc_attr( $args['min'] ) .'" data-max="'. esc_attr( $args['max'] ) .'" data-step="'. esc_attr( $args['step'] ) .'" step="any" />';
echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
echo '</div>';
echo '</div>';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-slider' ) ) {
wp_enqueue_script( 'jquery-ui-slider' );
}
}
public function output() {
$output = '';
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
foreach ( $elements as $key_property => $element ) {
if ( is_numeric( $key_property ) ) {
if ( $mode ) {
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
}
break;
} else {
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
}
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,87 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: sortable
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_sortable' ) ) {
class CSF_Field_sortable extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo $this->field_before();
echo '<div class="csf-sortable" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
$pre_sortby = array();
$pre_fields = array();
// Add array-keys to defined fields for sort by
foreach ( $this->field['fields'] as $key => $field ) {
$pre_fields[$field['id']] = $field;
}
// Set sort by by saved-value or default-value
if ( ! empty( $this->value ) ) {
foreach ( $this->value as $key => $value ) {
$pre_sortby[$key] = $pre_fields[$key];
}
$diff = array_diff_key( $pre_fields, $this->value );
if( ! empty( $diff ) ) {
$pre_sortby = array_merge( $pre_sortby, $diff );
}
} else {
foreach ( $pre_fields as $key => $value ) {
$pre_sortby[$key] = $value;
}
}
foreach ( $pre_sortby as $key => $field ) {
echo '<div class="csf-sortable-item">';
echo '<div class="csf-sortable-content">';
$field_default = ( isset( $this->field['default'][$key] ) ) ? $this->field['default'][$key] : '';
$field_value = ( isset( $this->value[$key] ) ) ? $this->value[$key] : $field_default;
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
CSF::field( $field, $field_value, $unique_id, 'field/sortable' );
echo '</div>';
echo '<div class="csf-sortable-helper"><i class="fas fa-arrows-alt"></i></div>';
echo '</div>';
}
echo '</div>';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}

View File

@@ -0,0 +1,76 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: sorter
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_sorter' ) ) {
class CSF_Field_sorter extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'disabled' => true,
'enabled_title' => esc_html__( 'Enabled', 'csf' ),
'disabled_title' => esc_html__( 'Disabled', 'csf' ),
) );
echo $this->field_before();
$this->value = ( ! empty( $this->value ) ) ? $this->value : $this->field['default'];
$enabled_options = ( ! empty( $this->value['enabled'] ) ) ? $this->value['enabled'] : array();
$disabled_options = ( ! empty( $this->value['disabled'] ) ) ? $this->value['disabled'] : array();
echo '<div class="csf-sorter" data-depend-id="'. esc_attr( $this->field['id'] ) .'"></div>';
echo ( $args['disabled'] ) ? '<div class="csf-modules">' : '';
echo ( ! empty( $args['enabled_title'] ) ) ? '<div class="csf-sorter-title">'. esc_attr( $args['enabled_title'] ) .'</div>' : '';
echo '<ul class="csf-enabled">';
if ( ! empty( $enabled_options ) ) {
foreach ( $enabled_options as $key => $value ) {
echo '<li><input type="hidden" name="'. esc_attr( $this->field_name( '[enabled]['. $key .']' ) ) .'" value="'. esc_attr( $value ) .'"/><label>'. esc_attr( $value ) .'</label></li>';
}
}
echo '</ul>';
// Check for hide/show disabled section
if ( $args['disabled'] ) {
echo '</div>';
echo '<div class="csf-modules">';
echo ( ! empty( $args['disabled_title'] ) ) ? '<div class="csf-sorter-title">'. esc_attr( $args['disabled_title'] ) .'</div>' : '';
echo '<ul class="csf-disabled">';
if ( ! empty( $disabled_options ) ) {
foreach ( $disabled_options as $key => $value ) {
echo '<li><input type="hidden" name="'. esc_attr( $this->field_name( '[disabled]['. $key .']' ) ) .'" value="'. esc_attr( $value ) .'"/><label>'. esc_attr( $value ) .'</label></li>';
}
}
echo '</ul>';
echo '</div>';
}
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}

View File

@@ -0,0 +1,150 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: spacing
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_spacing' ) ) {
class CSF_Field_spacing extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
'all_icon' => '<i class="fas fa-arrows-alt"></i>',
'top_placeholder' => esc_html__( 'top', 'csf' ),
'right_placeholder' => esc_html__( 'right', 'csf' ),
'bottom_placeholder' => esc_html__( 'bottom', 'csf' ),
'left_placeholder' => esc_html__( 'left', 'csf' ),
'all_placeholder' => esc_html__( 'all', 'csf' ),
'top' => true,
'left' => true,
'bottom' => true,
'right' => true,
'unit' => true,
'show_units' => true,
'all' => false,
'units' => array( 'px', '%', 'em' )
) );
$default_values = array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
'all' => '',
'unit' => 'px',
);
$value = wp_parse_args( $this->value, $default_values );
$unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
$is_unit = ( ! empty( $unit ) ) ? ' csf--is-unit' : '';
echo $this->field_before();
echo '<div class="csf--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
if ( ! empty( $args['all'] ) ) {
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['all_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
echo ( $unit ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
echo '</div>';
} else {
$properties = array();
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
if ( ! empty( $args[$prop] ) ) {
$properties[] = $prop;
}
}
$properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
foreach ( $properties as $property ) {
$placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
echo '<div class="csf--input">';
echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args[$property.'_icon'] .'</span>' : '';
echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="csf-input-number'. esc_attr( $is_unit ) .'" step="any" />';
echo ( $unit ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
echo '</div>';
}
}
if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
echo '<div class="csf--input">';
echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
foreach ( $args['units'] as $unit ) {
$selected = ( $value['unit'] === $unit ) ? ' selected' : '';
echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
}
echo '</select>';
echo '</div>';
}
echo '</div>';
echo $this->field_after();
}
public function output() {
$output = '';
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding';
$mode = ( $mode === 'relative' || $mode === 'absolute' || $mode === 'none' ) ? '' : $mode;
$mode = ( ! empty( $mode ) ) ? $mode .'-' : '';
if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && $this->value['all'] !== '' ) {
$output = $element .'{';
$output .= $mode .'top:'. $this->value['all'] . $unit . $important .';';
$output .= $mode .'right:'. $this->value['all'] . $unit . $important .';';
$output .= $mode .'bottom:'. $this->value['all'] . $unit . $important .';';
$output .= $mode .'left:'. $this->value['all'] . $unit . $important .';';
$output .= '}';
} else {
$top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $mode .'top:'. $this->value['top'] . $unit . $important .';' : '';
$right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $mode .'right:'. $this->value['right'] . $unit . $important .';' : '';
$bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $mode .'bottom:'. $this->value['bottom'] . $unit . $important .';' : '';
$left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $mode .'left:'. $this->value['left'] . $unit . $important .';' : '';
if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' ) {
$output = $element .'{'. $top . $right . $bottom . $left .'}';
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,70 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: spinner
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_spinner' ) ) {
class CSF_Field_spinner extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'max' => 100,
'min' => 0,
'step' => 1,
'unit' => '',
) );
echo $this->field_before();
echo '<div class="csf--spin"><input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'csf-input-number' ) ) .' data-min="'. esc_attr( $args['min'] ) .'" data-max="'. esc_attr( $args['max'] ) .'" data-step="'. esc_attr( $args['step'] ) .'" data-unit="'. esc_attr( $args['unit'] ) .'" step="any" /></div>';
echo $this->field_after();
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-spinner' ) ) {
wp_enqueue_script( 'jquery-ui-spinner' );
}
}
public function output() {
$output = '';
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
foreach ( $elements as $key_property => $element ) {
if ( is_numeric( $key_property ) ) {
if ( $mode ) {
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
}
break;
} else {
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
}
}
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,24 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: subheading
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_subheading' ) ) {
class CSF_Field_subheading extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo ( ! empty( $this->field['content'] ) ) ? $this->field['content'] : '';
}
}
}

View File

@@ -0,0 +1,26 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: submessage
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_submessage' ) ) {
class CSF_Field_submessage extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$style = ( ! empty( $this->field['style'] ) ) ? $this->field['style'] : 'normal';
echo '<div class="csf-submessage csf-submessage-'. esc_attr( $style ) .'">'. $this->field['content'] .'</div>';
}
}
}

View File

@@ -0,0 +1,40 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: switcher
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_switcher' ) ) {
class CSF_Field_switcher extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$active = ( ! empty( $this->value ) ) ? ' csf--active' : '';
$text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'csf' );
$text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'csf' );
$text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: '. esc_attr( $this->field['text_width'] ) .'px;"': '';
echo $this->field_before();
echo '<div class="csf--switcher'. esc_attr( $active ) .'"'. $text_width .'>';
echo '<span class="csf--on">'. esc_attr( $text_on ) .'</span>';
echo '<span class="csf--off">'. esc_attr( $text_off ) .'</span>';
echo '<span class="csf--ball"></span>';
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
echo '</div>';
echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--label">'. esc_attr( $this->field['label'] ) . '</span>' : '';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,64 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: tabbed
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_tabbed' ) ) {
class CSF_Field_tabbed extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$unallows = array( 'tabbed' );
echo $this->field_before();
echo '<div class="csf-tabbed-nav" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
foreach ( $this->field['tabs'] as $key => $tab ) {
$tabbed_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="csf--icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';
$tabbed_active = ( empty( $key ) ) ? 'csf-tabbed-active' : '';
echo '<a href="#" class="'. esc_attr( $tabbed_active ) .'"">'. $tabbed_icon . esc_attr( $tab['title'] ) .'</a>';
}
echo '</div>';
echo '<div class="csf-tabbed-contents">';
foreach ( $this->field['tabs'] as $key => $tab ) {
$tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : '';
echo '<div class="csf-tabbed-content'. esc_attr( $tabbed_hidden ) .'">';
foreach ( $tab['fields'] as $field ) {
if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
CSF::field( $field, $field_value, $unique_id, 'field/tabbed' );
}
echo '</div>';
}
echo '</div>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,30 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: text
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_text' ) ) {
class CSF_Field_text extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$type = ( ! empty( $this->field['attributes']['type'] ) ) ? $this->field['attributes']['type'] : 'text';
echo $this->field_before();
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,48 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: textarea
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_textarea' ) ) {
class CSF_Field_textarea extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo $this->field_before();
echo $this->shortcoder();
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes() .'>'. $this->value .'</textarea>';
echo $this->field_after();
}
public function shortcoder() {
if ( ! empty( $this->field['shortcoder'] ) ) {
$instances = ( is_array( $this->field['shortcoder'] ) ) ? $this->field['shortcoder'] : array_filter( (array) $this->field['shortcoder'] );
foreach ( $instances as $instance_key ) {
if ( isset( CSF::$shortcode_instances[$instance_key] ) ) {
$button_title = CSF::$shortcode_instances[$instance_key]['button_title'];
echo '<a href="#" class="button button-primary csf-shortcode-button" data-modal-id="'. esc_attr( $instance_key ) .'">'. $button_title .'</a>';
}
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,544 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: typography
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_typography' ) ) {
class CSF_Field_typography extends CSF_Fields {
public $chosen = false;
public $value = array();
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
echo $this->field_before();
$args = wp_parse_args( $this->field, array(
'font_family' => true,
'font_weight' => true,
'font_style' => true,
'font_size' => true,
'line_height' => true,
'letter_spacing' => true,
'text_align' => true,
'text_transform' => true,
'color' => true,
'chosen' => true,
'preview' => true,
'subset' => true,
'multi_subset' => false,
'extra_styles' => false,
'backup_font_family' => false,
'font_variant' => false,
'word_spacing' => false,
'text_decoration' => false,
'custom_style' => false,
'compact' => false,
'exclude' => '',
'unit' => 'px',
'line_height_unit' => '',
'preview_text' => 'The quick brown fox jumps over the lazy dog',
) );
if ( $args['compact'] ) {
$args['text_transform'] = false;
$args['text_align'] = false;
$args['font_size'] = false;
$args['line_height'] = false;
$args['letter_spacing'] = false;
$args['preview'] = false;
$args['color'] = false;
}
$default_value = array(
'font-family' => '',
'font-weight' => '',
'font-style' => '',
'font-variant' => '',
'font-size' => '',
'line-height' => '',
'letter-spacing' => '',
'word-spacing' => '',
'text-align' => '',
'text-transform' => '',
'text-decoration' => '',
'backup-font-family' => '',
'color' => '',
'custom-style' => '',
'type' => '',
'subset' => '',
'extra-styles' => array(),
);
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
$this->value = wp_parse_args( $this->value, $default_value );
$this->chosen = $args['chosen'];
$chosen_class = ( $this->chosen ) ? ' csf--chosen' : '';
$line_height_unit = ( ! empty( $args['line_height_unit'] ) ) ? $args['line_height_unit'] : $args['unit'];
echo '<div class="csf--typography'. esc_attr( $chosen_class ) .'" data-depend-id="'. esc_attr( $this->field['id'] ) .'" data-unit="'. esc_attr( $args['unit'] ) .'" data-line-height-unit="'. esc_attr( $line_height_unit ) .'" data-exclude="'. esc_attr( $args['exclude'] ) .'">';
echo '<div class="csf--blocks csf--blocks-selects">';
//
// Font Family
if ( ! empty( $args['font_family'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Font Family', 'csf' ) .'</div>';
echo $this->create_select( array( $this->value['font-family'] => $this->value['font-family'] ), 'font-family', esc_html__( 'Select a font', 'csf' ) );
echo '</div>';
}
//
// Backup Font Family
if ( ! empty( $args['backup_font_family'] ) ) {
echo '<div class="csf--block csf--block-backup-font-family hidden">';
echo '<div class="csf--title">'. esc_html__( 'Backup Font Family', 'csf' ) .'</div>';
echo $this->create_select( apply_filters( 'csf_field_typography_backup_font_family', array(
'Arial, Helvetica, sans-serif',
"'Arial Black', Gadget, sans-serif",
"'Comic Sans MS', cursive, sans-serif",
'Impact, Charcoal, sans-serif',
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
'Tahoma, Geneva, sans-serif',
"'Trebuchet MS', Helvetica, sans-serif'",
'Verdana, Geneva, sans-serif',
"'Courier New', Courier, monospace",
"'Lucida Console', Monaco, monospace",
'Georgia, serif',
'Palatino Linotype'
) ), 'backup-font-family', esc_html__( 'Default', 'csf' ) );
echo '</div>';
}
//
// Font Style and Extra Style Select
if ( ! empty( $args['font_weight'] ) || ! empty( $args['font_style'] ) ) {
//
// Font Style Select
echo '<div class="csf--block csf--block-font-style hidden">';
echo '<div class="csf--title">'. esc_html__( 'Font Style', 'csf') .'</div>';
echo '<select class="csf--font-style-select" data-placeholder="Default">';
echo '<option value="">'. ( ! $this->chosen ? esc_html__( 'Default', 'csf' ) : '' ) .'</option>';
if ( ! empty( $this->value['font-weight'] ) || ! empty( $this->value['font-style'] ) ) {
echo '<option value="'. esc_attr( strtolower( $this->value['font-weight'] . $this->value['font-style'] ) ) .'" selected></option>';
}
echo '</select>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[font-weight]' ) ) .'" class="csf--font-weight" value="'. esc_attr( $this->value['font-weight'] ) .'" />';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[font-style]' ) ) .'" class="csf--font-style" value="'. esc_attr( $this->value['font-style'] ) .'" />';
//
// Extra Font Style Select
if ( ! empty( $args['extra_styles'] ) ) {
echo '<div class="csf--block-extra-styles hidden">';
echo ( ! $this->chosen ) ? '<div class="csf--title">'. esc_html__( 'Load Extra Styles', 'csf' ) .'</div>' : '';
$placeholder = ( $this->chosen ) ? esc_html__( 'Load Extra Styles', 'csf' ) : esc_html__( 'Default', 'csf' );
echo $this->create_select( $this->value['extra-styles'], 'extra-styles', $placeholder, true );
echo '</div>';
}
echo '</div>';
}
//
// Subset
if ( ! empty( $args['subset'] ) ) {
echo '<div class="csf--block csf--block-subset hidden">';
echo '<div class="csf--title">'. esc_html__( 'Subset', 'csf' ) .'</div>';
$subset = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] );
echo $this->create_select( $subset, 'subset', esc_html__( 'Default', 'csf' ), $args['multi_subset'] );
echo '</div>';
}
//
// Text Align
if ( ! empty( $args['text_align'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Text Align', 'csf' ) .'</div>';
echo $this->create_select( array(
'inherit' => esc_html__( 'Inherit', 'csf' ),
'left' => esc_html__( 'Left', 'csf' ),
'center' => esc_html__( 'Center', 'csf' ),
'right' => esc_html__( 'Right', 'csf' ),
'justify' => esc_html__( 'Justify', 'csf' ),
'initial' => esc_html__( 'Initial', 'csf' )
), 'text-align', esc_html__( 'Default', 'csf' ) );
echo '</div>';
}
//
// Font Variant
if ( ! empty( $args['font_variant'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Font Variant', 'csf' ) .'</div>';
echo $this->create_select( array(
'normal' => esc_html__( 'Normal', 'csf' ),
'small-caps' => esc_html__( 'Small Caps', 'csf' ),
'all-small-caps' => esc_html__( 'All Small Caps', 'csf' )
), 'font-variant', esc_html__( 'Default', 'csf' ) );
echo '</div>';
}
//
// Text Transform
if ( ! empty( $args['text_transform'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Text Transform', 'csf' ) .'</div>';
echo $this->create_select( array(
'none' => esc_html__( 'None', 'csf' ),
'capitalize' => esc_html__( 'Capitalize', 'csf' ),
'uppercase' => esc_html__( 'Uppercase', 'csf' ),
'lowercase' => esc_html__( 'Lowercase', 'csf' )
), 'text-transform', esc_html__( 'Default', 'csf' ) );
echo '</div>';
}
//
// Text Decoration
if ( ! empty( $args['text_decoration'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Text Decoration', 'csf' ) .'</div>';
echo $this->create_select( array(
'none' => esc_html__( 'None', 'csf' ),
'underline' => esc_html__( 'Solid', 'csf' ),
'underline double' => esc_html__( 'Double', 'csf' ),
'underline dotted' => esc_html__( 'Dotted', 'csf' ),
'underline dashed' => esc_html__( 'Dashed', 'csf' ),
'underline wavy' => esc_html__( 'Wavy', 'csf' ),
'underline overline' => esc_html__( 'Overline', 'csf' ),
'line-through' => esc_html__( 'Line-through', 'csf' )
), 'text-decoration', esc_html__( 'Default', 'csf' ) );
echo '</div>';
}
echo '</div>';
echo '<div class="csf--blocks csf--blocks-inputs">';
//
// Font Size
if ( ! empty( $args['font_size'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Font Size', 'csf' ) .'</div>';
echo '<div class="csf--input-wrap">';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[font-size]' ) ) .'" class="csf--font-size csf--input csf-input-number" value="'. esc_attr( $this->value['font-size'] ) .'" step="any" />';
echo '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>';
echo '</div>';
echo '</div>';
}
//
// Line Height
if ( ! empty( $args['line_height'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Line Height', 'csf' ) .'</div>';
echo '<div class="csf--input-wrap">';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[line-height]' ) ) .'" class="csf--line-height csf--input csf-input-number" value="'. esc_attr( $this->value['line-height'] ) .'" step="any" />';
echo '<span class="csf--unit">'. esc_attr( $line_height_unit ) .'</span>';
echo '</div>';
echo '</div>';
}
//
// Letter Spacing
if ( ! empty( $args['letter_spacing'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Letter Spacing', 'csf' ) .'</div>';
echo '<div class="csf--input-wrap">';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[letter-spacing]' ) ) .'" class="csf--letter-spacing csf--input csf-input-number" value="'. esc_attr( $this->value['letter-spacing'] ) .'" step="any" />';
echo '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>';
echo '</div>';
echo '</div>';
}
//
// Word Spacing
if ( ! empty( $args['word_spacing'] ) ) {
echo '<div class="csf--block">';
echo '<div class="csf--title">'. esc_html__( 'Word Spacing', 'csf' ) .'</div>';
echo '<div class="csf--input-wrap">';
echo '<input type="number" name="'. esc_attr( $this->field_name( '[word-spacing]' ) ) .'" class="csf--word-spacing csf--input csf-input-number" value="'. esc_attr( $this->value['word-spacing'] ) .'" step="any" />';
echo '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>';
echo '</div>';
echo '</div>';
}
echo '</div>';
//
// Font Color
if ( ! empty( $args['color'] ) ) {
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : '';
echo '<div class="csf--block csf--block-font-color">';
echo '<div class="csf--title">'. esc_html__( 'Font Color', 'csf' ) .'</div>';
echo '<div class="csf-field-color">';
echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" class="csf-color csf--color" value="'. esc_attr( $this->value['color'] ) .'"'. $default_color_attr .' />';
echo '</div>';
echo '</div>';
}
//
// Custom style
if ( ! empty( $args['custom_style'] ) ) {
echo '<div class="csf--block csf--block-custom-style">';
echo '<div class="csf--title">'. esc_html__( 'Custom Style', 'csf' ) .'</div>';
echo '<textarea name="'. esc_attr( $this->field_name( '[custom-style]' ) ) .'" class="csf--custom-style">'. esc_attr( $this->value['custom-style'] ) .'</textarea>';
echo '</div>';
}
//
// Preview
$always_preview = ( $args['preview'] !== 'always' ) ? ' hidden' : '';
if ( ! empty( $args['preview'] ) ) {
echo '<div class="csf--block csf--block-preview'. esc_attr( $always_preview ) .'">';
echo '<div class="csf--toggle fas fa-toggle-off"></div>';
echo '<div class="csf--preview">'. esc_attr( $args['preview_text'] ) .'</div>';
echo '</div>';
}
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[type]' ) ) .'" class="csf--type" value="'. esc_attr( $this->value['type'] ) .'" />';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[unit]' ) ) .'" class="csf--unit-save" value="'. esc_attr( $args['unit'] ) .'" />';
echo '</div>';
echo $this->field_after();
}
public function create_select( $options, $name, $placeholder = '', $is_multiple = false ) {
$multiple_name = ( $is_multiple ) ? '[]' : '';
$multiple_attr = ( $is_multiple ) ? ' multiple data-multiple="true"' : '';
$chosen_rtl = ( $this->chosen && is_rtl() ) ? ' chosen-rtl' : '';
$output = '<select name="'. esc_attr( $this->field_name( '['. $name .']'. $multiple_name ) ) .'" class="csf--'. esc_attr( $name ) . esc_attr( $chosen_rtl ) .'" data-placeholder="'. esc_attr( $placeholder ) .'"'. $multiple_attr .'>';
$output .= ( ! empty( $placeholder ) ) ? '<option value="">'. esc_attr( ( ! $this->chosen ) ? $placeholder : '' ) .'</option>' : '';
if ( ! empty( $options ) ) {
foreach ( $options as $option_key => $option_value ) {
if ( $is_multiple ) {
$selected = ( in_array( $option_value, $this->value[$name] ) ) ? ' selected' : '';
$output .= '<option value="'. esc_attr( $option_value ) .'"'. esc_attr( $selected ).'>'. esc_attr( $option_value ) .'</option>';
} else {
$option_key = ( is_numeric( $option_key ) ) ? $option_value : $option_key;
$selected = ( $option_key === $this->value[$name] ) ? ' selected' : '';
$output .= '<option value="'. esc_attr( $option_key ) .'"'. esc_attr( $selected ).'>'. esc_attr( $option_value ) .'</option>';
}
}
}
$output .= '</select>';
return $output;
}
public function enqueue() {
if ( ! wp_script_is( 'csf-webfontloader' ) ) {
CSF::include_plugin_file( 'fields/typography/google-fonts.php' );
wp_enqueue_script( 'csf-webfontloader', 'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js', array( 'csf' ), '1.6.28', true );
$webfonts = array();
$customwebfonts = apply_filters( 'csf_field_typography_customwebfonts', array() );
if ( ! empty( $customwebfonts ) ) {
$webfonts['custom'] = array(
'label' => esc_html__( 'Custom Web Fonts', 'csf' ),
'fonts' => $customwebfonts
);
}
$webfonts['safe'] = array(
'label' => esc_html__( 'Safe Web Fonts', 'csf' ),
'fonts' => apply_filters( 'csf_field_typography_safewebfonts', array(
'Arial',
'Arial Black',
'Helvetica',
'Times New Roman',
'Courier New',
'Tahoma',
'Verdana',
'Impact',
'Trebuchet MS',
'Comic Sans MS',
'Lucida Console',
'Lucida Sans Unicode',
'Georgia, serif',
'Palatino Linotype'
)
) );
$webfonts['google'] = array(
'label' => esc_html__( 'Google Web Fonts', 'csf' ),
'fonts' => apply_filters( 'csf_field_typography_googlewebfonts', csf_get_google_fonts()
) );
$defaultstyles = apply_filters( 'csf_field_typography_defaultstyles', array( 'normal', 'italic', '700', '700italic' ) );
$googlestyles = apply_filters( 'csf_field_typography_googlestyles', array(
'100' => 'Thin 100',
'100italic' => 'Thin 100 Italic',
'200' => 'Extra-Light 200',
'200italic' => 'Extra-Light 200 Italic',
'300' => 'Light 300',
'300italic' => 'Light 300 Italic',
'normal' => 'Normal 400',
'italic' => 'Normal 400 Italic',
'500' => 'Medium 500',
'500italic' => 'Medium 500 Italic',
'600' => 'Semi-Bold 600',
'600italic' => 'Semi-Bold 600 Italic',
'700' => 'Bold 700',
'700italic' => 'Bold 700 Italic',
'800' => 'Extra-Bold 800',
'800italic' => 'Extra-Bold 800 Italic',
'900' => 'Black 900',
'900italic' => 'Black 900 Italic'
) );
$webfonts = apply_filters( 'csf_field_typography_webfonts', $webfonts );
wp_localize_script( 'csf', 'csf_typography_json', array(
'webfonts' => $webfonts,
'defaultstyles' => $defaultstyles,
'googlestyles' => $googlestyles
) );
}
}
public function enqueue_google_fonts( $method = 'enqueue' ) {
$is_google = false;
if ( ! empty( $this->value['type'] ) ) {
$is_google = ( $this->value['type'] === 'google' ) ? true : false;
} else {
CSF::include_plugin_file( 'fields/typography/google-fonts.php' );
$is_google = ( array_key_exists( $this->value['font-family'], csf_get_google_fonts() ) ) ? true : false;
}
if ( $is_google ) {
// set style
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : '';
$font_weight = ( ! empty( $this->value['font-weight'] ) ) ? $this->value['font-weight'] : '';
$font_style = ( ! empty( $this->value['font-style'] ) ) ? $this->value['font-style'] : '';
if ( $font_weight || $font_style ) {
$style = $font_weight . $font_style;
if ( ! empty( $style ) ) {
$style = ( $style === 'normal' ) ? '400' : $style;
CSF::$webfonts[$method][$font_family][$style] = $style;
}
} else {
CSF::$webfonts[$method][$font_family] = array();
}
// set extra styles
if ( ! empty( $this->value['extra-styles'] ) ) {
foreach ( $this->value['extra-styles'] as $extra_style ) {
if ( ! empty( $extra_style ) ) {
$extra_style = ( $extra_style === 'normal' ) ? '400' : $extra_style;
CSF::$webfonts[$method][$font_family][$extra_style] = $extra_style;
}
}
}
// set subsets
if ( ! empty( $this->value['subset'] ) ) {
$this->value['subset'] = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] );
foreach ( $this->value['subset'] as $subset ) {
if( ! empty( $subset ) ) {
CSF::$subsets[$subset] = $subset;
}
}
}
return true;
}
return false;
}
public function output() {
$output = '';
$bg_image = array();
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : '';
$backup_family = ( ! empty( $this->value['backup-font-family'] ) ) ? ', '. $this->value['backup-font-family'] : '';
if ( $font_family ) {
$output .= 'font-family:"'. $font_family .'"'. $backup_family . $important .';';
}
// Common font properties
$properties = array(
'color',
'font-weight',
'font-style',
'font-variant',
'text-align',
'text-transform',
'text-decoration',
);
foreach ( $properties as $property ) {
if ( isset( $this->value[$property] ) && $this->value[$property] !== '' ) {
$output .= $property .':'. $this->value[$property] . $important .';';
}
}
$properties = array(
'font-size',
'line-height',
'letter-spacing',
'word-spacing',
);
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : '';
$line_height_unit = ( ! empty( $this->value['line_height_unit'] ) ) ? $this->value['line_height_unit'] : $unit;
foreach ( $properties as $property ) {
if ( isset( $this->value[$property] ) && $this->value[$property] !== '' ) {
$unit = ( $property === 'line-height' ) ? $line_height_unit : $unit;
$output .= $property .':'. $this->value[$property] . $unit . $important .';';
}
}
$custom_style = ( ! empty( $this->value['custom-style'] ) ) ? $this->value['custom-style'] : '';
if ( $output ) {
$output = $element .'{'. $output . $custom_style .'}';
}
$this->parent->output_css .= $output;
return $output;
}
}
}

View File

@@ -0,0 +1,41 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: upload
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_upload' ) ) {
class CSF_Field_upload extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'library' => array(),
'button_title' => esc_html__( 'Upload', 'csf' ),
'remove_title' => esc_html__( 'Remove', 'csf' ),
) );
echo $this->field_before();
$library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
$library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
echo '<div class="csf--wrap">';
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
echo '<a href="#" class="button button-primary csf--button" data-library="'. esc_attr( $library ) .'">'. $args['button_title'] .'</a>';
echo '<a href="#" class="button button-secondary csf-warning-primary csf--remove'. esc_attr( $hidden ) .'">'. $args['remove_title'] .'</a>';
echo '</div>';
echo $this->field_after();
}
}
}

View File

@@ -0,0 +1,103 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: wp_editor
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_wp_editor' ) ) {
class CSF_Field_wp_editor extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'tinymce' => true,
'quicktags' => true,
'media_buttons' => true,
'wpautop' => false,
'height' => '',
) );
$attributes = array(
'rows' => 10,
'class' => 'wp-editor-area',
'autocomplete' => 'off',
);
$editor_height = ( ! empty( $args['height'] ) ) ? ' style="height:'. esc_attr( $args['height'] ) .';"' : '';
$editor_settings = array(
'tinymce' => $args['tinymce'],
'quicktags' => $args['quicktags'],
'media_buttons' => $args['media_buttons'],
'wpautop' => $args['wpautop'],
);
echo $this->field_before();
echo ( csf_wp_editor_api() ) ? '<div class="csf-wp-editor" data-editor-settings="'. esc_attr( json_encode( $editor_settings ) ) .'">' : '';
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes( $attributes ) . $editor_height .'>'. $this->value .'</textarea>';
echo ( csf_wp_editor_api() ) ? '</div>' : '';
echo $this->field_after();
}
public function enqueue() {
if ( csf_wp_editor_api() && function_exists( 'wp_enqueue_editor' ) ) {
wp_enqueue_editor();
$this->setup_wp_editor_settings();
add_action( 'print_default_editor_scripts', array( &$this, 'setup_wp_editor_media_buttons' ) );
}
}
// Setup wp editor media buttons
public function setup_wp_editor_media_buttons() {
ob_start();
echo '<div class="wp-media-buttons">';
do_action( 'media_buttons' );
echo '</div>';
$media_buttons = ob_get_clean();
echo '<script type="text/javascript">';
echo 'var csf_media_buttons = '. json_encode( $media_buttons ) .';';
echo '</script>';
}
// Setup wp editor settings
public function setup_wp_editor_settings() {
if ( csf_wp_editor_api() && class_exists( '_WP_Editors') ) {
$defaults = apply_filters( 'csf_wp_editor', array(
'tinymce' => array(
'wp_skip_init' => true
),
) );
$setup = _WP_Editors::parse_settings( 'csf_wp_editor', $defaults );
_WP_Editors::editor_settings( 'csf_wp_editor', $setup );
}
}
}
}