Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.2.4
Browse files Browse the repository at this point in the history
Codestar committed Aug 9, 2021
0 parents commit f468cf5
Showing 119 changed files with 25,779 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
[![Codestar Framework](http://s3.codestarthemes.com/codecanyon/23079100/github-banner.png)](http://codestarframework.com/)

# Codestar Framework
A Simple and Lightweight WordPress Option Framework for Themes and Plugins. Built in Object Oriented Programming paradigm with high number of custom fields and tons of options. Allows you to bring custom admin, metabox, taxonomy and customize settings to all of your pages, posts and categories. It's highly modern and advanced framework.

## Contents
- [Demo](#demo)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Documentation](#documentation)
- [Free vs Premium](#free-vs-premium)
- [Support](#support)
- [Release Notes](#release-notes)
- [License](#license)

## Demo
For usage and examples, have a look at :rocket: [online demo](http://codestarthemes.com/plugins/codestar-framework/wp-login.php?login=demo)

## Installation

1. Download the installable WordPress plugin zip.
2. Upload and active plugin from `WordPress` → `Plugins` → `Add New`
3. After activation, next step is to configure your settings. You can do it from here :gear: [configurations](http://codestarframework.com/documentation/#/configurations)

## Quick Start

Open your current theme **functions.php** file and paste this code.

```php
// Check core class for avoid errors
if( class_exists( 'CSF' ) ) {

// Set a unique slug-like ID
$prefix = 'my_framework';

// Create options
CSF::createOptions( $prefix, array(
'menu_title' => 'My Framework',
'menu_slug' => 'my-framework',
) );

// Create a section
CSF::createSection( $prefix, array(
'title' => 'Tab Title 1',
'fields' => array(

// A text field
array(
'id' => 'opt-text',
'type' => 'text',
'title' => 'Simple Text',
),

)
) );

// Create a section
CSF::createSection( $prefix, array(
'title' => 'Tab Title 2',
'fields' => array(

// A textarea field
array(
'id' => 'opt-textarea',
'type' => 'textarea',
'title' => 'Simple Textarea',
),

)
) );

}
```
How to get option value ?
```php
$options = get_option( 'my_framework' ); // unique id of the framework

echo $options['opt-text']; // id of the field
echo $options['opt-textarea']; // id of the field
```

## Documentation
Read the documentation for details :closed_book: [documentation](http://codestarframework.com/documentation/)

## Free vs Premium

| Features | Free Version | Premium Version
|:-----------------------------|:------------------:|:-----------------:
| Admin Option Framework | :heavy_check_mark: | :heavy_check_mark:
| Customize Option Framework | :x: | :heavy_check_mark:
| Metabox Option Framework | :x: | :heavy_check_mark:
| Nav Menu Option Framework | :x: | :heavy_check_mark:
| Taxonomy Option Framework | :x: | :heavy_check_mark:
| Profile Option Framework | :x: | :heavy_check_mark:
| Comment Option Framework | :x: | :heavy_check_mark:
| Widget Option Framework | :x: | :heavy_check_mark:
| Shortcode Option Framework | :x: | :heavy_check_mark:
| All Option Fields | :x: | :heavy_check_mark:
| Developer Packages | :x: | :heavy_check_mark:
| Unminfy Library | :x: | :heavy_check_mark:
| New Requests | :x: | :heavy_check_mark:
| Autoremove Advertisements | :x: | :heavy_check_mark:
| Life-time access/updates | :x: | :heavy_check_mark:
| | | :star2: <a href="http://codestarframework.com/">Upgrade Premium Version</a>

## Available Option Fields

| Accordion | Color | Icon | Select | Tabbed
|:------------|:------------|:-------------|:---------|:---
| Background | Color Group | Image Select | Slider | Text
| Backup | Date | Link Color | Sortable | Textarea
| Border | Dimensions | Media | Sorter | Typography
| Button Set | Fieldset | Palette | Spacing | Upload
| Checkbox | Gallery | Radio | Spinner | WP Editor
| Code Editor | Group | Repeater | Switcher | Others

## Support

We are provide [support forum](http://support.codestarthemes.com/) for premium version users. You can join to support forum for submit any question after purchasing. Free version users support is limited on [github](https://github.com/Codestar/codestar-framework/issues).

## Release Notes
Check out the [release notes](http://codestarframework.com/documentation/#/relnotes)

## License
Codestar Framework have two different version. Free version has limited features and offers only admin option panel feature. Premium version offers all extensions and more of settings for the best experience and advanced features. You can bundle the framework ( both free and premium ) in the premium theme/plugin and sell them on your own website or in marketplaces like ThemeForest. This framework is licensed 100% GPL.
1 change: 1 addition & 0 deletions assets/css/style-rtl.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/style.min.css

Large diffs are not rendered by default.

Binary file added assets/images/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/images/wp-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/images/wp-plugin-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/js/main.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assets/js/plugins.min.js

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions classes/abstract.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Abstract Class
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Abstract' ) ) {
abstract class CSF_Abstract {

public $abstract = '';
public $output_css = '';

public function __construct() {

// Collect output css and typography
if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 );
CSF::$css = apply_filters( "csf_{$this->unique}_output_css", CSF::$css, $this );
}

}

public function collect_output_css_and_typography() {
$this->recursive_output_css( $this->pre_fields );
}

public function recursive_output_css( $fields = array(), $combine_field = array() ) {

if ( ! empty( $fields ) ) {

foreach ( $fields as $field ) {

$field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : '';
$field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : '';
$field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : '';
$field_check = ( $field_type === 'typography' || $field_output ) ? true : false;
$field_class = 'CSF_Field_' . $field_type;

if ( $field_type && $field_id ) {


if( $field_type === 'fieldset' ) {
if ( ! empty( $field['fields'] ) ) {
$this->recursive_output_css( $field['fields'], $field );
}
}

if( $field_type === 'accordion' ) {
if ( ! empty( $field['accordions'] ) ) {
foreach ( $field['accordions'] as $accordion ) {
$this->recursive_output_css( $accordion['fields'], $field );
}
}
}

if( $field_type === 'tabbed' ) {
if ( ! empty( $field['tabs'] ) ) {
foreach ( $field['tabs'] as $accordion ) {
$this->recursive_output_css( $accordion['fields'], $field );
}
}
}

if ( class_exists( $field_class ) ) {

if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) {

$field_value = '';

if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) {

if( ! empty( $combine_field ) ) {

$field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : '';

} else {

$field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';

}

} else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) {

if( ! empty( $combine_field ) ) {

$meta_value = $this->get_meta_value( $combine_field );
$field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : '';

} else {

$meta_value = $this->get_meta_value( $field );
$field_value = ( isset( $meta_value ) ) ? $meta_value : '';

}

}

$instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this );

// typography enqueue and embed google web fonts
if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) {

$method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue';

$instance->enqueue_google_fonts( $method );

}

// output css
if ( $field_output && $this->args['output_css'] ) {
CSF::$css .= $instance->output();
}

unset( $instance );

}

}

}

}

}

}

}
}
721 changes: 721 additions & 0 deletions classes/admin-options.class.php

Large diffs are not rendered by default.

405 changes: 405 additions & 0 deletions classes/fields.class.php

Large diffs are not rendered by default.

787 changes: 787 additions & 0 deletions classes/setup.class.php

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions codestar-framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* @package Codestar Framework - WordPress Options Framework
* @author Codestar <info@codestarthemes.com>
* @link http://codestarframework.com
* @copyright 2015-2021 Codestar
*
*
* Plugin Name: Codestar Framework
* Plugin URI: http://codestarframework.com/
* Author: Codestar
* Author URI: http://codestarthemes.com/
* Version: 2.2.4
* Description: A Simple and Lightweight WordPress Option Framework for Themes and Plugins
* Text Domain: csf
* Domain Path: /languages
*
*/
require_once plugin_dir_path( __FILE__ ) .'classes/setup.class.php';
64 changes: 64 additions & 0 deletions fields/accordion/accordion.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
340 changes: 340 additions & 0 deletions fields/background/background.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
38 changes: 38 additions & 0 deletions fields/backup/backup.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
176 changes: 176 additions & 0 deletions fields/border/border.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
67 changes: 67 additions & 0 deletions fields/button_set/button_set.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
31 changes: 31 additions & 0 deletions fields/callback/callback.php
Original file line number Diff line number Diff line change
@@ -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 );

}

}

}
}

95 changes: 95 additions & 0 deletions fields/checkbox/checkbox.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
58 changes: 58 additions & 0 deletions fields/code_editor/code_editor.php
Original file line number Diff line number Diff line change
@@ -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.62.2';
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 );
}

}

}
}
52 changes: 52 additions & 0 deletions fields/color/color.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
42 changes: 42 additions & 0 deletions fields/color_group/color_group.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
28 changes: 28 additions & 0 deletions fields/content/content.php
Original file line number Diff line number Diff line change
@@ -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'];

}

}

}
}
64 changes: 64 additions & 0 deletions fields/date/date.php
Original file line number Diff line number Diff line change
@@ -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' );
}

}

}
}
101 changes: 101 additions & 0 deletions fields/dimensions/dimensions.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
41 changes: 41 additions & 0 deletions fields/fieldset/fieldset.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
52 changes: 52 additions & 0 deletions fields/gallery/gallery.php
Original file line number Diff line number Diff line change
@@ -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="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';

echo $this->field_after();

}

}
}
144 changes: 144 additions & 0 deletions fields/group/group.php
Original file line number Diff line number Diff line change
@@ -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' );
}

}

}
}
24 changes: 24 additions & 0 deletions fields/heading/heading.php
Original file line number Diff line number Diff line change
@@ -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'] : '';

}

}
}
12 changes: 12 additions & 0 deletions fields/icon/fa4-icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
//
// Font Awesome 4 Icons
//
if ( ! function_exists( 'csf_get_default_icons' ) ) {
function csf_get_default_icons() {
return array( array(
'title' => 'Font Awesome',
'icons' => array( 'fa fa-glass','fa fa-music','fa fa-search','fa fa-envelope-o','fa fa-heart','fa fa-star','fa fa-star-o','fa fa-user','fa fa-film','fa fa-th-large','fa fa-th','fa fa-th-list','fa fa-check','fa fa-times','fa fa-search-plus','fa fa-search-minus','fa fa-power-off','fa fa-signal','fa fa-cog','fa fa-trash-o','fa fa-home','fa fa-file-o','fa fa-clock-o','fa fa-road','fa fa-download','fa fa-arrow-circle-o-down','fa fa-arrow-circle-o-up','fa fa-inbox','fa fa-play-circle-o','fa fa-repeat','fa fa-refresh','fa fa-list-alt','fa fa-lock','fa fa-flag','fa fa-headphones','fa fa-volume-off','fa fa-volume-down','fa fa-volume-up','fa fa-qrcode','fa fa-barcode','fa fa-tag','fa fa-tags','fa fa-book','fa fa-bookmark','fa fa-print','fa fa-camera','fa fa-font','fa fa-bold','fa fa-italic','fa fa-text-height','fa fa-text-width','fa fa-align-left','fa fa-align-center','fa fa-align-right','fa fa-align-justify','fa fa-list','fa fa-outdent','fa fa-indent','fa fa-video-camera','fa fa-picture-o','fa fa-pencil','fa fa-map-marker','fa fa-adjust','fa fa-tint','fa fa-pencil-square-o','fa fa-share-square-o','fa fa-check-square-o','fa fa-arrows','fa fa-step-backward','fa fa-fast-backward','fa fa-backward','fa fa-play','fa fa-pause','fa fa-stop','fa fa-forward','fa fa-fast-forward','fa fa-step-forward','fa fa-eject','fa fa-chevron-left','fa fa-chevron-right','fa fa-plus-circle','fa fa-minus-circle','fa fa-times-circle','fa fa-check-circle','fa fa-question-circle','fa fa-info-circle','fa fa-crosshairs','fa fa-times-circle-o','fa fa-check-circle-o','fa fa-ban','fa fa-arrow-left','fa fa-arrow-right','fa fa-arrow-up','fa fa-arrow-down','fa fa-share','fa fa-expand','fa fa-compress','fa fa-plus','fa fa-minus','fa fa-asterisk','fa fa-exclamation-circle','fa fa-gift','fa fa-leaf','fa fa-fire','fa fa-eye','fa fa-eye-slash','fa fa-exclamation-triangle','fa fa-plane','fa fa-calendar','fa fa-random','fa fa-comment','fa fa-magnet','fa fa-chevron-up','fa fa-chevron-down','fa fa-retweet','fa fa-shopping-cart','fa fa-folder','fa fa-folder-open','fa fa-arrows-v','fa fa-arrows-h','fa fa-bar-chart','fa fa-twitter-square','fa fa-facebook-square','fa fa-camera-retro','fa fa-key','fa fa-cogs','fa fa-comments','fa fa-thumbs-o-up','fa fa-thumbs-o-down','fa fa-star-half','fa fa-heart-o','fa fa-sign-out','fa fa-linkedin-square','fa fa-thumb-tack','fa fa-external-link','fa fa-sign-in','fa fa-trophy','fa fa-github-square','fa fa-upload','fa fa-lemon-o','fa fa-phone','fa fa-square-o','fa fa-bookmark-o','fa fa-phone-square','fa fa-twitter','fa fa-facebook','fa fa-github','fa fa-unlock','fa fa-credit-card','fa fa-rss','fa fa-hdd-o','fa fa-bullhorn','fa fa-bell','fa fa-certificate','fa fa-hand-o-right','fa fa-hand-o-left','fa fa-hand-o-up','fa fa-hand-o-down','fa fa-arrow-circle-left','fa fa-arrow-circle-right','fa fa-arrow-circle-up','fa fa-arrow-circle-down','fa fa-globe','fa fa-wrench','fa fa-tasks','fa fa-filter','fa fa-briefcase','fa fa-arrows-alt','fa fa-users','fa fa-link','fa fa-cloud','fa fa-flask','fa fa-scissors','fa fa-files-o','fa fa-paperclip','fa fa-floppy-o','fa fa-square','fa fa-bars','fa fa-list-ul','fa fa-list-ol','fa fa-strikethrough','fa fa-underline','fa fa-table','fa fa-magic','fa fa-truck','fa fa-pinterest','fa fa-pinterest-square','fa fa-google-plus-square','fa fa-google-plus','fa fa-money','fa fa-caret-down','fa fa-caret-up','fa fa-caret-left','fa fa-caret-right','fa fa-columns','fa fa-sort','fa fa-sort-desc','fa fa-sort-asc','fa fa-envelope','fa fa-linkedin','fa fa-undo','fa fa-gavel','fa fa-tachometer','fa fa-comment-o','fa fa-comments-o','fa fa-bolt','fa fa-sitemap','fa fa-umbrella','fa fa-clipboard','fa fa-lightbulb-o','fa fa-exchange','fa fa-cloud-download','fa fa-cloud-upload','fa fa-user-md','fa fa-stethoscope','fa fa-suitcase','fa fa-bell-o','fa fa-coffee','fa fa-cutlery','fa fa-file-text-o','fa fa-building-o','fa fa-hospital-o','fa fa-ambulance','fa fa-medkit','fa fa-fighter-jet','fa fa-beer','fa fa-h-square','fa fa-plus-square','fa fa-angle-double-left','fa fa-angle-double-right','fa fa-angle-double-up','fa fa-angle-double-down','fa fa-angle-left','fa fa-angle-right','fa fa-angle-up','fa fa-angle-down','fa fa-desktop','fa fa-laptop','fa fa-tablet','fa fa-mobile','fa fa-circle-o','fa fa-quote-left','fa fa-quote-right','fa fa-spinner','fa fa-circle','fa fa-reply','fa fa-github-alt','fa fa-folder-o','fa fa-folder-open-o','fa fa-smile-o','fa fa-frown-o','fa fa-meh-o','fa fa-gamepad','fa fa-keyboard-o','fa fa-flag-o','fa fa-flag-checkered','fa fa-terminal','fa fa-code','fa fa-reply-all','fa fa-star-half-o','fa fa-location-arrow','fa fa-crop','fa fa-code-fork','fa fa-chain-broken','fa fa-question','fa fa-info','fa fa-exclamation','fa fa-superscript','fa fa-subscript','fa fa-eraser','fa fa-puzzle-piece','fa fa-microphone','fa fa-microphone-slash','fa fa-shield','fa fa-calendar-o','fa fa-fire-extinguisher','fa fa-rocket','fa fa-maxcdn','fa fa-chevron-circle-left','fa fa-chevron-circle-right','fa fa-chevron-circle-up','fa fa-chevron-circle-down','fa fa-html5','fa fa-css3','fa fa-anchor','fa fa-unlock-alt','fa fa-bullseye','fa fa-ellipsis-h','fa fa-ellipsis-v','fa fa-rss-square','fa fa-play-circle','fa fa-ticket','fa fa-minus-square','fa fa-minus-square-o','fa fa-level-up','fa fa-level-down','fa fa-check-square','fa fa-pencil-square','fa fa-external-link-square','fa fa-share-square','fa fa-compass','fa fa-caret-square-o-down','fa fa-caret-square-o-up','fa fa-caret-square-o-right','fa fa-eur','fa fa-gbp','fa fa-usd','fa fa-inr','fa fa-jpy','fa fa-rub','fa fa-krw','fa fa-btc','fa fa-file','fa fa-file-text','fa fa-sort-alpha-asc','fa fa-sort-alpha-desc','fa fa-sort-amount-asc','fa fa-sort-amount-desc','fa fa-sort-numeric-asc','fa fa-sort-numeric-desc','fa fa-thumbs-up','fa fa-thumbs-down','fa fa-youtube-square','fa fa-youtube','fa fa-xing','fa fa-xing-square','fa fa-youtube-play','fa fa-dropbox','fa fa-stack-overflow','fa fa-instagram','fa fa-flickr','fa fa-adn','fa fa-bitbucket','fa fa-bitbucket-square','fa fa-tumblr','fa fa-tumblr-square','fa fa-long-arrow-down','fa fa-long-arrow-up','fa fa-long-arrow-left','fa fa-long-arrow-right','fa fa-apple','fa fa-windows','fa fa-android','fa fa-linux','fa fa-dribbble','fa fa-skype','fa fa-foursquare','fa fa-trello','fa fa-female','fa fa-male','fa fa-gratipay','fa fa-sun-o','fa fa-moon-o','fa fa-archive','fa fa-bug','fa fa-vk','fa fa-weibo','fa fa-renren','fa fa-pagelines','fa fa-stack-exchange','fa fa-arrow-circle-o-right','fa fa-arrow-circle-o-left','fa fa-caret-square-o-left','fa fa-dot-circle-o','fa fa-wheelchair','fa fa-vimeo-square','fa fa-try','fa fa-plus-square-o','fa fa-space-shuttle','fa fa-slack','fa fa-envelope-square','fa fa-wordpress','fa fa-openid','fa fa-university','fa fa-graduation-cap','fa fa-yahoo','fa fa-google','fa fa-reddit','fa fa-reddit-square','fa fa-stumbleupon-circle','fa fa-stumbleupon','fa fa-delicious','fa fa-digg','fa fa-pied-piper-pp','fa fa-pied-piper-alt','fa fa-drupal','fa fa-joomla','fa fa-language','fa fa-fax','fa fa-building','fa fa-child','fa fa-paw','fa fa-spoon','fa fa-cube','fa fa-cubes','fa fa-behance','fa fa-behance-square','fa fa-steam','fa fa-steam-square','fa fa-recycle','fa fa-car','fa fa-taxi','fa fa-tree','fa fa-spotify','fa fa-deviantart','fa fa-soundcloud','fa fa-database','fa fa-file-pdf-o','fa fa-file-word-o','fa fa-file-excel-o','fa fa-file-powerpoint-o','fa fa-file-image-o','fa fa-file-archive-o','fa fa-file-audio-o','fa fa-file-video-o','fa fa-file-code-o','fa fa-vine','fa fa-codepen','fa fa-jsfiddle','fa fa-life-ring','fa fa-circle-o-notch','fa fa-rebel','fa fa-empire','fa fa-git-square','fa fa-git','fa fa-hacker-news','fa fa-tencent-weibo','fa fa-qq','fa fa-weixin','fa fa-paper-plane','fa fa-paper-plane-o','fa fa-history','fa fa-circle-thin','fa fa-header','fa fa-paragraph','fa fa-sliders','fa fa-share-alt','fa fa-share-alt-square','fa fa-bomb','fa fa-futbol-o','fa fa-tty','fa fa-binoculars','fa fa-plug','fa fa-slideshare','fa fa-twitch','fa fa-yelp','fa fa-newspaper-o','fa fa-wifi','fa fa-calculator','fa fa-paypal','fa fa-google-wallet','fa fa-cc-visa','fa fa-cc-mastercard','fa fa-cc-discover','fa fa-cc-amex','fa fa-cc-paypal','fa fa-cc-stripe','fa fa-bell-slash','fa fa-bell-slash-o','fa fa-trash','fa fa-copyright','fa fa-at','fa fa-eyedropper','fa fa-paint-brush','fa fa-birthday-cake','fa fa-area-chart','fa fa-pie-chart','fa fa-line-chart','fa fa-lastfm','fa fa-lastfm-square','fa fa-toggle-off','fa fa-toggle-on','fa fa-bicycle','fa fa-bus','fa fa-ioxhost','fa fa-angellist','fa fa-cc','fa fa-ils','fa fa-meanpath','fa fa-buysellads','fa fa-connectdevelop','fa fa-dashcube','fa fa-forumbee','fa fa-leanpub','fa fa-sellsy','fa fa-shirtsinbulk','fa fa-simplybuilt','fa fa-skyatlas','fa fa-cart-plus','fa fa-cart-arrow-down','fa fa-diamond','fa fa-ship','fa fa-user-secret','fa fa-motorcycle','fa fa-street-view','fa fa-heartbeat','fa fa-venus','fa fa-mars','fa fa-mercury','fa fa-transgender','fa fa-transgender-alt','fa fa-venus-double','fa fa-mars-double','fa fa-venus-mars','fa fa-mars-stroke','fa fa-mars-stroke-v','fa fa-mars-stroke-h','fa fa-neuter','fa fa-genderless','fa fa-facebook-official','fa fa-pinterest-p','fa fa-whatsapp','fa fa-server','fa fa-user-plus','fa fa-user-times','fa fa-bed','fa fa-viacoin','fa fa-train','fa fa-subway','fa fa-medium','fa fa-y-combinator','fa fa-optin-monster','fa fa-opencart','fa fa-expeditedssl','fa fa-battery-full','fa fa-battery-three-quarters','fa fa-battery-half','fa fa-battery-quarter','fa fa-battery-empty','fa fa-mouse-pointer','fa fa-i-cursor','fa fa-object-group','fa fa-object-ungroup','fa fa-sticky-note','fa fa-sticky-note-o','fa fa-cc-jcb','fa fa-cc-diners-club','fa fa-clone','fa fa-balance-scale','fa fa-hourglass-o','fa fa-hourglass-start','fa fa-hourglass-half','fa fa-hourglass-end','fa fa-hourglass','fa fa-hand-rock-o','fa fa-hand-paper-o','fa fa-hand-scissors-o','fa fa-hand-lizard-o','fa fa-hand-spock-o','fa fa-hand-pointer-o','fa fa-hand-peace-o','fa fa-trademark','fa fa-registered','fa fa-creative-commons','fa fa-gg','fa fa-gg-circle','fa fa-tripadvisor','fa fa-odnoklassniki','fa fa-odnoklassniki-square','fa fa-get-pocket','fa fa-wikipedia-w','fa fa-safari','fa fa-chrome','fa fa-firefox','fa fa-opera','fa fa-internet-explorer','fa fa-television','fa fa-contao','fa fa-500px','fa fa-amazon','fa fa-calendar-plus-o','fa fa-calendar-minus-o','fa fa-calendar-times-o','fa fa-calendar-check-o','fa fa-industry','fa fa-map-pin','fa fa-map-signs','fa fa-map-o','fa fa-map','fa fa-commenting','fa fa-commenting-o','fa fa-houzz','fa fa-vimeo','fa fa-black-tie','fa fa-fonticons','fa fa-reddit-alien','fa fa-edge','fa fa-credit-card-alt','fa fa-codiepie','fa fa-modx','fa fa-fort-awesome','fa fa-usb','fa fa-product-hunt','fa fa-mixcloud','fa fa-scribd','fa fa-pause-circle','fa fa-pause-circle-o','fa fa-stop-circle','fa fa-stop-circle-o','fa fa-shopping-bag','fa fa-shopping-basket','fa fa-hashtag','fa fa-bluetooth','fa fa-bluetooth-b','fa fa-percent','fa fa-gitlab','fa fa-wpbeginner','fa fa-wpforms','fa fa-envira','fa fa-universal-access','fa fa-wheelchair-alt','fa fa-question-circle-o','fa fa-blind','fa fa-audio-description','fa fa-volume-control-phone','fa fa-braille','fa fa-assistive-listening-systems','fa fa-american-sign-language-interpreting','fa fa-deaf','fa fa-glide','fa fa-glide-g','fa fa-sign-language','fa fa-low-vision','fa fa-viadeo','fa fa-viadeo-square','fa fa-snapchat','fa fa-snapchat-ghost','fa fa-snapchat-square','fa fa-pied-piper','fa fa-first-order','fa fa-yoast','fa fa-themeisle','fa fa-google-plus-official','fa fa-font-awesome','fa fa-handshake-o','fa fa-envelope-open','fa fa-envelope-open-o','fa fa-linode','fa fa-address-book','fa fa-address-book-o','fa fa-address-card','fa fa-address-card-o','fa fa-user-circle','fa fa-user-circle-o','fa fa-user-o','fa fa-id-badge','fa fa-id-card','fa fa-id-card-o','fa fa-quora','fa fa-free-code-camp','fa fa-telegram','fa fa-thermometer-full','fa fa-thermometer-three-quarters','fa fa-thermometer-half','fa fa-thermometer-quarter','fa fa-thermometer-empty','fa fa-shower','fa fa-bath','fa fa-podcast','fa fa-window-maximize','fa fa-window-minimize','fa fa-window-restore','fa fa-window-close','fa fa-window-close-o','fa fa-bandcamp','fa fa-grav','fa fa-etsy','fa fa-imdb','fa fa-ravelry','fa fa-eercast','fa fa-microchip','fa fa-snowflake-o','fa fa-superpowers','fa fa-wpexplorer','fa fa-meetup' )
) );
}
}
12 changes: 12 additions & 0 deletions fields/icon/fa5-icons.php

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions fields/icon/icon.php
Original file line number Diff line number Diff line change
@@ -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="hidden" 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( 'CSF_Field_icon', 'add_footer_modal_icon' ) );
add_action( 'customize_controls_print_footer_scripts', array( 'CSF_Field_icon', 'add_footer_modal_icon' ) );
}

public static 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
}

}
}
79 changes: 79 additions & 0 deletions fields/image_select/image_select.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
1 change: 1 addition & 0 deletions fields/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden.
82 changes: 82 additions & 0 deletions fields/link/link.php
Original file line number Diff line number Diff line change
@@ -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="hidden" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $value['url'] ) .'"'. $this->field_attributes( array( 'class' => 'csf--url' ) ) .' />';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[text]' ) ) .'" value="'. esc_attr( $value['text'] ) .'" class="csf--text" />';
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[target]' ) ) .'" value="'. esc_attr( $value['target'] ) .'" class="csf--target" />';

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();

}

}
}
91 changes: 91 additions & 0 deletions fields/link_color/link_color.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
98 changes: 98 additions & 0 deletions fields/map/map.php
Original file line number Diff line number Diff line change
@@ -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' );
}

}

}
}
96 changes: 96 additions & 0 deletions fields/media/media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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,
'preview_width' => '',
'preview_height' => '',
'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'] ) ) {

$preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:'. esc_attr( $args['preview_width'] ) .'px;' : '';
$preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:'. esc_attr( $args['preview_height'] ) .'px;' : '';
$preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="'. esc_attr( $preview_width . $preview_height ) .'"': '';

echo '<div class="csf--preview'. esc_attr( $hidden_auto ) .'">';
echo '<div class="csf-image-preview"'. $preview_style .'>';
echo '<i class="csf--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="csf--src" /></span>';
echo '</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();

}

}
}
26 changes: 26 additions & 0 deletions fields/notice/notice.php
Original file line number Diff line number Diff line change
@@ -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>' : '';

}

}
}
60 changes: 60 additions & 0 deletions fields/number/number.php
Original file line number Diff line number Diff line change
@@ -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;

}

}
}
58 changes: 58 additions & 0 deletions fields/palette/palette.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
93 changes: 93 additions & 0 deletions fields/radio/radio.php
Original file line number Diff line number Diff line change
@@ -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();

}

}
}
108 changes: 108 additions & 0 deletions fields/repeater/repeater.php
Original file line number Diff line number Diff line change
@@ -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' );
}

}

}
}
Loading

0 comments on commit f468cf5

Please sign in to comment.