Plugin Directory

Changeset 3175163


Ignore:
Timestamp:
10/24/2024 04:47:55 PM (16 months ago)
Author:
bibleup
Message:

Upload stable v1.1.0 to trunk

Location:
bibleup/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bibleup/trunk/bibleup.php

    r2951254 r3175163  
    11<?php
    22/*
    3    Plugin Name: BibleUp
    4    Plugin URI: https://bibleup.netlify.com
    5    description: BibleUp transforms Bible References on a webpage into flexible, and highly customisable popovers.
    6    Version: 1.0.1
    7    Author: BibleUp
    8    Author URI: https://bibleup.netlify.com
    9    License: GPLv3
    10    License URI: https://www.gnu.org/licenses/gpl-3.0.html
    11    */
     3 * Plugin Name: BibleUp
     4 * Plugin URI: https://bibleup.netlify.app
     5 * description: BibleUp transforms Bible References on a webpage into flexible, and highly customisable popovers.
     6 * Version: 1.1.0
     7 * Requires at least: 5.6
     8 * Requires PHP: 7.0
     9 * Author: BibleUp
     10 * Author URI: https://bibleup.netlify.app
     11 * License: GPLv3
     12 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
     13 */
    1214
    13 class BibleUp {
     15class BibleUp
     16{
    1417
    1518    private $plugin_path; // @var string
     
    1922
    2023    // BibleUp constructor.
    21     function __construct() {
    22         $this->plugin_path = plugin_dir_path( __FILE__ );
     24    function __construct()
     25    {
     26        $this->plugin_path = plugin_dir_path(__FILE__);
    2327        //this service is documented and delivery is pegged to major version @1
    2428        $this->script = 'https://cdn.jsdelivr.net/npm/@bibleup/bibleup@1/dist/umd/bibleup-core.min.js';
     
    2630
    2731        // Include and create a new Bibleup_WordPressSettingsFramework
    28         require_once( $this->plugin_path . 'wp-settings-framework/wp-settings-framework.php' );
    29         $this->wpsf = new Bibleup_WordPressSettingsFramework( $this->plugin_path . 'settings/settings-general.php', 'bibleup' );
     32        require_once($this->plugin_path . 'wp-settings-framework/wp-settings-framework.php');
     33        $this->wpsf = new Bibleup_WordPressSettingsFramework($this->plugin_path . 'settings/settings-general.php', 'bibleup');
    3034
    3135        // Add admin menu
    32         add_action( 'admin_menu', array( $this, 'add_settings_page' ), 20 );
     36        add_action('admin_menu', array($this, 'add_settings_page'), 20);
    3337
    3438        // Add an optional settings validation filter (recommended)
    35         add_filter( $this->wpsf->get_option_group() . '_settings_validate', array( &$this, 'validate_settings' ) );
     39        add_filter($this->wpsf->get_option_group() . '_settings_validate', array(&$this, 'validate_settings'));
    3640    }
    3741
     
    3943     * Add settings page.
    4044     */
    41     function add_settings_page() {
    42         $this->wpsf->add_settings_page( array(
     45    function add_settings_page()
     46    {
     47        $this->wpsf->add_settings_page(array(
    4348            'parent_slug' => 'options-general.php',
    44             'page_title'  => __( 'BibleUp', 'bibleup' ),
    45             'menu_title'  => __( 'BibleUp', 'bibleup' ),
    46             'capability'  => 'manage_options',
     49            'page_title' => __('BibleUp', 'bibleup'),
     50            'menu_title' => __('BibleUp', 'bibleup'),
     51            'capability' => 'manage_options',
    4752        ));
    4853    }
     
    5358     * @return mixed
    5459     */
    55     function validate_settings( $input ) {
     60    function validate_settings($input)
     61    {
    5662        // Do your settings validation here
    5763        // Same as $sanitize_callback from http://codex.wordpress.org/Function_Reference/register_setting
     
    6066    }
    6167
    62     function start() {
    63         add_action( 'wp_enqueue_scripts', array( $this, 'handle_scripts' ) );
     68    function start()
     69    {
     70        add_action('wp_enqueue_scripts', array($this, 'handle_scripts'));
    6471    }
    6572
    66     function handle_scripts() {
    67         $raw_options = wpsf_get_setting_bibleup( 'bibleup', 'tab_2_paste_config', 'raw_options' );
    68         $custom_css = wpsf_get_setting_bibleup( 'bibleup', 'tab_2_custom_css', 'custom_css' );
    69         wp_enqueue_script('bibleup-core', $this->script, null, 'v1', true );
     73    function handle_scripts()
     74    {
     75        $raw_options = wpsf_get_setting_bibleup('bibleup', 'tab_2_paste_config', 'raw_options');
     76        $custom_css = wpsf_get_setting_bibleup('bibleup', 'tab_2_custom_css', 'custom_css');
     77        wp_enqueue_script('bibleup-core', $this->script, null, 'v1', true);
    7078        wp_enqueue_style('bibleup-style', $this->style, null, 'v1');
    7179
     
    8492    }
    8593
    86     function get_custom_css() {
    87         $custom_css = wpsf_get_setting_bibleup( 'bibleup', 'tab_2_paste_config', 'custom_css' );
    88         return $custom_css;
    89     }
     94    function get_select_options()
     95    {
     96        // tab_1 section ID - select_options
     97        $popup = wpsf_get_setting_bibleup('bibleup', 'tab_1_select_options', 'popup');
     98        $version = wpsf_get_setting_bibleup('bibleup', 'tab_1_select_options', 'version');
     99        $dark_theme = wpsf_get_setting_bibleup('bibleup', 'tab_1_select_options', 'dark_theme');
     100        // tab_1 section ID - popup_style
     101        $primary = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'primary');
     102        $secondary = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'secondary');
     103        $tertiary = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'tertiary');
     104        $header_color = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'header_color');
     105        $font_color = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'font_color');
     106        $version_color = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'version_color');
     107        $close_color = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'close_color');
     108        $border_radius = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'border_radius');
     109        $box_shadow = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'box_shadow');
     110        $font_size = wpsf_get_setting_bibleup('bibleup', 'tab_1_popup_style', 'font_size');
     111        // tab_1 section ID - additional
     112        $ignoreCase = wpsf_get_setting_bibleup('bibleup', 'tab_1_additional', 'ignoreCase');
     113        $bu_allow = wpsf_get_setting_bibleup('bibleup', 'tab_1_additional', 'bu_allow');
     114        $bu_ignore = wpsf_get_setting_bibleup('bibleup', 'tab_1_additional', 'bu_ignore');
     115        $buid = wpsf_get_setting_bibleup('bibleup', 'tab_1_additional', 'buid');
    90116
    91     function get_select_options() {
    92         // tab_1 section ID - select_options
    93         $popup = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_select_options', 'popup' );
    94         $version = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_select_options', 'version' );
    95         $dark_theme = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_select_options', 'dark_theme' );
    96         // tab_1 section ID - popup_style
    97         $primary = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'primary' );
    98         $secondary = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'secondary' );
    99         $tertiary = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'tertiary' );
    100         $header_color = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'header_color' );
    101         $font_color = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'font_color' );
    102         $version_color = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'version_color' );
    103         $close_color = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'close_color' );
    104         $border_radius = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'border_radius' );
    105         $box_shadow = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'box_shadow' );
    106         $font_size = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_popup_style', 'font_size' );
    107         // tab_1 section ID - additional
    108         $ignoreCase = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_additional', 'ignoreCase' );
    109         $bu_allow = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_additional', 'bu_allow' );
    110         $bu_ignore = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_additional', 'bu_ignore' );
    111         $buid = wpsf_get_setting_bibleup( 'bibleup', 'tab_1_additional', 'buid' );
    112 
    113         $call = function($prop, $default, $isArray=false) {
    114             if ($prop == 'false' || empty($prop) ) {
     117        $call = function ($prop, $default, $isArray = false) {
     118            if ($prop == 'false' || empty($prop)) {
    115119                return ($isArray) ? $default : "'$default'";
    116120            } else if ($prop == 'true') {
     
    118122            } else {
    119123                $prop = esc_js($prop);
    120                 return "'${prop}'";
     124                return "'{$prop}'";
    121125            }
    122126        };
     
    124128        $r = "
    125129            let b = new BibleUp(document.body, {
    126                 popup: ". $call($popup, 'classic') .",
    127                 version: ". $call($version, 'KJV') .",
    128                 darkTheme: ". $call($dark_theme, 'false') .",
    129                 ignoreCase: ". $call($ignoreCase, 'false') .",
    130                 bu_ignore: ". $call($bu_ignore, '["H1", "H2", "H3", "H4", "H5", "H6", "A"]', true) .",
    131                 bu_allow: ". $call($bu_allow, '[]', true) .",
    132                 buid: ". $call($buid, 'false') .",
     130                popup: " . $call($popup, 'classic') . ",
     131                version: " . $call($version, 'KJV') . ",
     132                darkTheme: " . $call($dark_theme, 'false') . ",
     133                ignoreCase: " . $call($ignoreCase, 'false') . ",
     134                bu_ignore: " . $call($bu_ignore, '["H1", "H2", "H3", "H4", "H5", "H6", "A"]', true) . ",
     135                bu_allow: " . $call($bu_allow, '[]', true) . ",
     136                buid: " . $call($buid, 'false') . ",
    133137                styles: {
    134                     primary: ". $call($primary, 'false') .",
    135                     secondary: ". $call($secondary, 'false') .",
    136                     tertiary: ". $call($tertiary, 'false') .",
    137                     headerColor: ". $call($header_color, 'false') .",
    138                     fontColor: ". $call($font_color, 'false') .",
    139                     versionColor: ". $call($version_color, 'false') .",
    140                     closeColor: ". $call($close_color, 'false') .",
    141                     borderRadius: ". $call($border_radius, 'false') .",
    142                     boxShadow: ". $call($box_shadow, 'false') .",
    143                     fontSize: ". $call($font_size, 'false') .",
     138                    primary: " . $call($primary, 'false') . ",
     139                    secondary: " . $call($secondary, 'false') . ",
     140                    tertiary: " . $call($tertiary, 'false') . ",
     141                    headerColor: " . $call($header_color, 'false') . ",
     142                    fontColor: " . $call($font_color, 'false') . ",
     143                    versionColor: " . $call($version_color, 'false') . ",
     144                    closeColor: " . $call($close_color, 'false') . ",
     145                    borderRadius: " . $call($border_radius, 'false') . ",
     146                    boxShadow: " . $call($box_shadow, 'false') . ",
     147                    fontSize: " . $call($font_size, 'false') . ",
    144148                }
    145149            })
     
    149153    }
    150154
    151     function get_raw_options() {
    152         $raw_options = wpsf_get_setting_bibleup( 'bibleup', 'tab_2_paste_config', 'raw_options' );
     155    function get_raw_options()
     156    {
     157        $raw_options = wpsf_get_setting_bibleup('bibleup', 'tab_2_paste_config', 'raw_options');
    153158
    154159        $r = "
    155             let b = new BibleUp(document.body, ".$raw_options.");
     160            let b = new BibleUp(document.body, " . $raw_options . ");
    156161            b.create();";
    157162
     
    159164    }
    160165
    161     function bibleup_deactivate() {
     166    public static function bibleup_deactivate()
     167    {
    162168        // Delete all saved settings from option group - bibleup
    163         wpsf_delete_settings_bibleup( 'bibleup' );
     169        wpsf_delete_settings_bibleup('bibleup');
    164170    }
    165171
     
    168174$bibleup = new BibleUp();
    169175$bibleup->start();
    170 register_deactivation_hook( __FILE__, array( 'BibleUp', 'bibleup_deactivate' ) );
     176register_deactivation_hook(__FILE__, array('BibleUp', 'bibleup_deactivate'));
  • bibleup/trunk/readme.txt

    r2951254 r3175163  
    33Tags: bible, references, reftagging, christian, scripture, popup
    44Requires at least: 5.6
    5 Tested up to: 6.3
     5Tested up to: 6.6
    66Requires PHP: 7.0
    7 Stable tag: 1.0.1
     7Stable tag: 1.1.0
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    2323## Features 💡
    2424
    25 - **Smart tagging:** BibleUp can safely recognize and tag references in multiple, different ways. Abbreviated and standard names will be tagged correctly as well as multiple verse range. BibleUp also supports version tagging.
     25- **Smart tagging:** BibleUp can recognize and tag references in multiple, different ways. Abbreviated or standard names, as well as multiple verse ranges, will be tagged correctly. BibleUp also supports version tagging.
    2626
    27 - **Flexible and highly customizable:** BibleUp comes with different popover types and can be thoroughly customized to fit your site\'s theme. Customization can be done through the provided options.
     27- **Flexible and highly customizable:** BibleUp comes with different popover types and can be thoroughly customized to fit your site\'s theme.
    2828
    2929- **Performant:** Make your readers enjoy fast Bible references look-up without bloating your site. BibleUp also follows the WAI-ARAI accessibility guidelines for screen readers and keyboard navigation.
    3030
    31 - **Agile development and contributions:** BibleUp is free and open-sourced, contributions can be made by anyone. Issues and requests will also be attended to faster.
     31- **Agile development and contributions:** BibleUp is free and open-sourced, contributions can be made by anyone. Issues and requests will be attended to faster.
    3232
    3333## Demo 🛸
     
    3838
    3939== Frequently Asked Questions ==
    40 = How many versions does BibleUp supports =
    41 BibleUp currently supports 4 Bible versions with much more to come. These versions are the Authorized King James Version (KJV), Authorized Standard Version (ASV), Literal Standard Version (LSV) and the World English Bible (WEB).
     40= How many versions does BibleUp support =
     41BibleUp currently supports 10 Bible versions, including modern versions you can use. See [all versions](https://bibleup.netlify.app/docs/guide/options.html#version)
     42
     43
     44= Will BibleUp support other languages =
     45We are currently working to include other translations apart from English. If there is any language/translation you would like to use or help with, send us a message and let us know.
    4246
    4347= How to report an issue or submit feature requests =
     
    4650
    4751 1. [Github](https://github.com/bibleup/wordpress/issues) (all issues, requests and contributions)
    48  2. [General support Forum](https://groups.google.com/g/bibleup)
    49  3. WordPress Support forum (for WordPress)
    50 
    51 = How is the development going =
    52 BibleUp recently launched v1.0.0 and there is so much more to come!<br>
    53 We plan to roll out more Bible versions, change versions on popovers and lots more before the next major release.<br><br>
    54 The best way to participate in development is by following us on [Github](https://github.com/bibleup), making contributions and giving us a star.
     52 2. [General support Forum](https://groups.google.com/g/bibleup) or
     53 3. [Website contact form](https://bibleup.netlify.app)
     54 4. WordPress Support forum (for WordPress issues)
    5555
    5656= How can I help support =
     
    81813) Click on the 'Upload Plugin' button at the top left corner to reveal the file picker.
    82824) Select and upload the downloaded zip file.
    83 5) Install the Plugin and activate once done. Configure the options as you want!
     835) Install the Plugin and activate it once done. Configure the options as you want!
    8484
    85 You can find the settings page at **settings >> BibleUp** after activating the plugin.
     85After activating the plugin, you can find the settings page at **settings > BibleUp**
    8686
    8787== Changelog ==
     88= 1.1.0 =
     89* Added support for five more versions*
     90* Performance and bug fixes *
     91
    8892= 1.0.0 =
    8993* Initial Release
  • bibleup/trunk/settings/settings-general.php

    r2862460 r3175163  
    2121 */
    2222
    23 add_filter( 'wpsf_register_settings_bibleup', 'wpsf_tabbed_settings' );
     23add_filter('wpsf_register_settings_bibleup', 'wpsf_tabbed_settings');
    2424
    2525/**
     
    3232 * @param array $wpsf_settings settings.
    3333 */
    34 function wpsf_tabbed_settings( $wpsf_settings ) {
     34function wpsf_tabbed_settings($wpsf_settings)
     35{
    3536    // Tabs.
    3637    $wpsf_settings['tabs'] = array(
    3738        array(
    38             'id'    => 'tab_1',
    39             'title' => esc_html__( 'Select Options', 'bibleup' ),
    40         ),
    41         array(
    42             'id'    => 'tab_2',
    43             'title' => esc_html__( 'Paste Config', 'bibleup' ),
     39            'id' => 'tab_1',
     40            'title' => esc_html__('Select Options', 'bibleup'),
     41        ),
     42        array(
     43            'id' => 'tab_2',
     44            'title' => esc_html__('Paste Config', 'bibleup'),
    4445        ),
    4546    );
     
    4849    $wpsf_settings['sections'] = array(
    4950        array(
    50             'tab_id'        => 'tab_1',
    51             'section_id'    => 'note',
     51            'tab_id' => 'tab_1',
     52            'section_id' => 'note',
    5253            'section_description' => '<b>Please read the following before you begin to configure BibleUp</b><br>
    5354            There are two methods you can use to configure BibleUp - <b>select Options</b> or <b>Paste Config</b><br>
     
    5960        ),
    6061        array(
    61             'tab_id'        => 'tab_1',
    62             'section_id'    => 'select_options',
     62            'tab_id' => 'tab_1',
     63            'section_id' => 'select_options',
    6364            'section_title' => 'Select Options',
    6465            'section_order' => 10,
    65             'fields'        => array(
    66                 array(
    67                     'id'      => 'popup',
    68                     'title'   => 'Popup Type',
    69                     'desc'    => 'The preferred popup type.',
    70                     'type'    => 'select',
     66            'fields' => array(
     67                array(
     68                    'id' => 'popup',
     69                    'title' => 'Popup Type',
     70                    'desc' => 'The preferred popup type.',
     71                    'type' => 'select',
    7172                    'default' => 'classic',
    7273                    'choices' => array(
    73                         'classic'   => 'classic',
     74                        'classic' => 'classic',
    7475                        'inline' => 'inline',
    75                         'wiki'  => 'wiki',
    76                     ),
    77                 ),
    78                 array(
    79                     'id'      => 'version',
    80                     'title'   => 'Version',
    81                     'desc'    => 'The default Bible translation for references.',
    82                     'type'    => 'select',
     76                        'wiki' => 'wiki',
     77                    ),
     78                ),
     79                array(
     80                    'id' => 'version',
     81                    'title' => 'Version',
     82                    'desc' => 'The default Bible translation for references.',
     83                    'type' => 'select',
    8384                    'default' => 'KJV',
    8485                    'choices' => array(
    85                         'KJV'   => 'King James Version (KJV)',
     86                        'KJV' => 'King James Version (KJV)',
    8687                        'ASV' => 'American Standard Version (ASV)',
    87                         'LSV'  => 'Literal Standard Version (LSV)',
    88                         'WEB'  => 'World English Bible (WEB)',
    89                     ),
    90                 ),
    91                 array(
    92                     'id'      => 'dark_theme',
    93                     'title'   => 'Dark Theme',
    94                     'desc'    => 'Enable dark theme on popup.<br>
     88                        'LSV' => 'Literal Standard Version (LSV)',
     89                        'WEB' => 'World English Bible (WEB)',
     90                        'ESV' => 'English Standard Version (ESV)',
     91                        'NIV' => 'New International Version (NIV)',
     92                        'MSG' => 'The Message Translation (MSG)',
     93                        'AMP' => 'The Amplified Bible (AMP)',
     94                        'NLT' => 'New Living Translation (NLT)',
     95                        'NASB' => 'New American Standard Bible (NASB)'
     96                    ),
     97                ),
     98                array(
     99                    'id' => 'dark_theme',
     100                    'title' => 'Dark Theme',
     101                    'desc' => 'Enable dark theme on popup.<br>
    95102                    This can be overriden by the background and font color set by other options, to preserve the default dark theme you must set other color options to false.',
    96                     'type'    => 'radio',
     103                    'type' => 'radio',
    97104                    'default' => 'false',
    98105                    'choices' => array(
    99                         'true'   => 'True',
     106                        'true' => 'True',
    100107                        'false' => 'False',
    101108                    ),
     
    105112
    106113        array(
    107             'tab_id'        => 'tab_1',
    108             'section_id'    => 'popup_style',
     114            'tab_id' => 'tab_1',
     115            'section_id' => 'popup_style',
    109116            'section_title' => 'Popup Style',
    110117            'section_description' => 'Set popup background and font colors.',
    111118            'section_order' => 10,
    112             'fields'        => array(
    113                 array(
    114                     'id'      => 'primary',
    115                     'title'   => 'Primary',
    116                     'desc'    => 'Set color for overall popup background',
    117                     'type'    => 'color',
    118                     'default' => 'false',
    119                 ),
    120                 array(
    121                     'id'      => 'secondary',
    122                     'title'   => 'Secondary',
    123                     'desc'    => 'Set background color for popup header (if it exists)',
    124                     'type'    => 'color',
    125                     'default' => 'false',
    126                 ),
    127                 array(
    128                     'id'      => 'tertiary',
    129                     'title'   => 'Tertiary',
    130                     'desc'    => 'Set background color for popup version (if it exists)',
    131                     'type'    => 'color',
    132                     'default' => 'false',
    133                 ),
    134                 array(
    135                     'id'      => 'header_color',
    136                     'title'   => 'Header Color',
    137                     'desc'    => 'Font color for popup header (if it exists).<br>
     119            'fields' => array(
     120                array(
     121                    'id' => 'primary',
     122                    'title' => 'Primary',
     123                    'desc' => 'Set color for overall popup background',
     124                    'type' => 'color',
     125                    'default' => 'false',
     126                ),
     127                array(
     128                    'id' => 'secondary',
     129                    'title' => 'Secondary',
     130                    'desc' => 'Set background color for popup header (if it exists)',
     131                    'type' => 'color',
     132                    'default' => 'false',
     133                ),
     134                array(
     135                    'id' => 'tertiary',
     136                    'title' => 'Tertiary',
     137                    'desc' => 'Set background color for popup version (if it exists)',
     138                    'type' => 'color',
     139                    'default' => 'false',
     140                ),
     141                array(
     142                    'id' => 'header_color',
     143                    'title' => 'Header Color',
     144                    'desc' => 'Font color for popup header (if it exists).<br>
    138145                    This will override the default font color for text in the header only',
    139                     'type'    => 'color',
    140                     'default' => 'false',
    141                 ),
    142                 array(
    143                     'id'      => 'font_color',
    144                     'title'   => 'Font Color',
    145                     'desc'    => 'The default font color for the popup',
    146                     'type'    => 'color',
    147                     'default' => 'false',
    148                 ),
    149                 array(
    150                     'id'      => 'version_color',
    151                     'title'   => 'Version Color',
    152                     'desc'    => 'Font color for popup version (if it exists).<br>
     146                    'type' => 'color',
     147                    'default' => 'false',
     148                ),
     149                array(
     150                    'id' => 'font_color',
     151                    'title' => 'Font Color',
     152                    'desc' => 'The default font color for the popup',
     153                    'type' => 'color',
     154                    'default' => 'false',
     155                ),
     156                array(
     157                    'id' => 'version_color',
     158                    'title' => 'Version Color',
     159                    'desc' => 'Font color for popup version (if it exists).<br>
    153160                    This will override the default font color for text in the version box only',
    154                     'type'    => 'color',
    155                     'default' => 'false',
    156                 ),
    157                 array(
    158                     'id'      => 'close_color',
    159                     'title'   => 'Close Color',
    160                     'desc'    => 'Set color for close button (if it exists).<br>
     161                    'type' => 'color',
     162                    'default' => 'false',
     163                ),
     164                array(
     165                    'id' => 'close_color',
     166                    'title' => 'Close Color',
     167                    'desc' => 'Set color for close button (if it exists).<br>
    161168                    The close button only exists on popup type "wiki" ',
    162                     'type'    => 'color',
    163                     'default' => 'false',
    164                 ),
    165                 array(
    166                     'id'      => 'border_radius',
    167                     'title'   => 'Border Radius',
    168                     'desc'    => 'Set border radius for popup (in units)',
    169                     'type'    => 'text',
     169                    'type' => 'color',
     170                    'default' => 'false',
     171                ),
     172                array(
     173                    'id' => 'border_radius',
     174                    'title' => 'Border Radius',
     175                    'desc' => 'Set border radius for popup (in units)',
     176                    'type' => 'text',
    170177                    'placeholder' => '5px',
    171178                    'default' => 'false',
    172179                ),
    173180                array(
    174                     'id'      => 'box_shadow',
    175                     'title'   => 'Box Shadow',
    176                     'desc'    => 'Set a drop shadow for the popup (using CSS syntax)',
    177                     'type'    => 'text',
     181                    'id' => 'box_shadow',
     182                    'title' => 'Box Shadow',
     183                    'desc' => 'Set a drop shadow for the popup (using CSS syntax)',
     184                    'type' => 'text',
    178185                    'placeholder' => '2px 6px 10px #404040',
    179186                    'default' => 'false',
    180187                ),
    181188                array(
    182                     'id'      => 'font_size',
    183                     'title'   => 'Font Size',
    184                     'desc'    => 'Set font size for all popup (text in units)',
    185                     'type'    => 'text',
     189                    'id' => 'font_size',
     190                    'title' => 'Font Size',
     191                    'desc' => 'Set font size for all popup (text in units)',
     192                    'type' => 'text',
    186193                    'placeholder' => '16px',
    187194                    'default' => 'false',
     
    190197        ),
    191198
    192         array(
    193             'tab_id'        => 'tab_1',
    194             'section_id'    => 'additional',
     199        array(
     200            'tab_id' => 'tab_1',
     201            'section_id' => 'additional',
    195202            'section_title' => 'Additional Settings',
    196203            'section_description' => 'Use these options to configure BibleUp behaviour.',
    197204            'section_order' => 10,
    198             'fields'        => array(
    199                 array(
    200                     'id'      => 'ignoreCase',
    201                     'title'   => 'Ignore letter case when tagging references',
    202                     'desc'    => "Allow BibleUp match references in any letter case.",
    203                     'type'    => 'radio',
     205            'fields' => array(
     206                array(
     207                    'id' => 'ignoreCase',
     208                    'title' => 'Ignore letter case when tagging references',
     209                    'desc' => "Allow BibleUp match references in any letter case.",
     210                    'type' => 'radio',
    204211                    'default' => 'false',
    205212                    'choices' => array(
    206                         'true'   => 'True',
     213                        'true' => 'True',
    207214                        'false' => 'False',
    208215                    ),
    209216                ),
    210217                array(
    211                     'id'      => 'bu_ignore',
    212                     'title'   => 'Ignore Specific HTML Elements',
    213                     'desc'    => "BibleUp won't tag element listed here.<br>
     218                    'id' => 'bu_ignore',
     219                    'title' => 'Ignore Specific HTML Elements',
     220                    'subtitle' => 'bu_ignore',
     221                    'desc' => "BibleUp won't tag element listed here.<br>
    214222                    Seperate these elements using a comma and put inside a square bracket.",
    215                     'type'    => 'text',
    216                     'placeholder'    => "['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'IMG', 'A']",
    217                     'default' => 'false',
    218                     'link'     => array(
    219                         'url'      => esc_url( 'https://bibleup.netlify.app/docs/guide/options.html#bu-ignore' ),
    220                         'type'     => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
    221                         'text'     => 'Learn More',
     223                    'type' => 'text',
     224                    'placeholder' => "['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'IMG', 'A']",
     225                    'default' => 'false',
     226                    'link' => array(
     227                        'url' => esc_url('https://bibleup.netlify.app/docs/guide/options.html#bu-ignore'),
     228                        'type' => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
     229                        'text' => 'Learn More',
    222230                        'external' => true,
    223231                    ),
    224232                ),
    225233                array(
    226                     'id'      => 'bu_allow',
    227                     'title'   => 'Allow Specific HTML Elements',
    228                     'desc'    => "Override the default elements ignored by BibleUp by placing them here.<br>
     234                    'id' => 'bu_allow',
     235                    'title' => 'Allow Specific HTML Elements',
     236                    'subtitle' => 'bu_allow',
     237                    'desc' => "Override the default elements ignored by BibleUp by placing them here.<br>
    229238                    Seperate these elements using a comma and put inside a square bracket.",
    230                     'type'    => 'text',
    231                     'placeholder'    => "['H1', 'H2']",
    232                     'default' => 'false',
    233                     'link'     => array(
    234                         'url'      => esc_url( 'https://bibleup.netlify.app/docs/guide/options.html#bu-allow' ),
    235                         'type'     => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
    236                         'text'     => 'Learn More',
     239                    'type' => 'text',
     240                    'placeholder' => "['H1', 'H2']",
     241                    'default' => 'false',
     242                    'link' => array(
     243                        'url' => esc_url('https://bibleup.netlify.app/docs/guide/options.html#bu-allow'),
     244                        'type' => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
     245                        'text' => 'Learn More',
    237246                        'external' => true,
    238247                    ),
    239248                ),
    240249                array(
    241                     'id'      => 'buid',
    242                     'title'   => 'BibleUp ID (buid)',
    243                     'desc'    => "Attach a specific HTML ID attribute to popovers and links",
    244                     'type'    => 'text',
    245                     'placeholder'    => "buid string",
    246                     'default' => 'false',
    247                     'link'     => array(
    248                         'url'      => esc_url( 'https://bibleup.netlify.app/docs/customisation/#buid' ),
    249                         'type'     => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
    250                         'text'     => 'Learn More',
     250                    'id' => 'buid',
     251                    'title' => 'BibleUp ID (buid)',
     252                    'subtitle' => 'buid',
     253                    'desc' => "Attach a specific HTML ID attribute to popovers and links",
     254                    'type' => 'text',
     255                    'placeholder' => "buid string",
     256                    'default' => 'false',
     257                    'link' => array(
     258                        'url' => esc_url('https://bibleup.netlify.app/docs/customisation/#buid'),
     259                        'type' => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
     260                        'text' => 'Learn More',
    251261                        'external' => true,
    252262                    ),
    253263                ),
    254264            ),
    255         ),
    256 
    257         array(
    258             'tab_id'        => 'tab_2',
    259             'section_id'    => 'paste_config',
     265        ),
     266
     267        array(
     268            'tab_id' => 'tab_2',
     269            'section_id' => 'paste_config',
    260270            'section_title' => 'Paste Config',
    261271            'section_description' => 'Use the instant <a target="_blank" href="https://bibleup.netlify.app/demo/editor">editor</a> to style popup in real-time, then copy and paste the generated config options.<br>
     
    263273            Leave the editor blank if you want to manually seclect options instead.',
    264274            'section_order' => 10,
    265             'fields'        => array(
    266                 array(
    267                     'id'      => 'raw_options',
    268                     'title'   => 'Raw Options',
    269                     'desc'    => 'Paste the raw config options here',
    270                     'type'        => 'code_editor',
     275            'fields' => array(
     276                array(
     277                    'id' => 'raw_options',
     278                    'title' => 'Raw Options',
     279                    'desc' => 'Paste the raw config options here',
     280                    'type' => 'code_editor',
    271281                    'mimetype' => 'application/json',
    272282                    'default' => '',
     
    276286
    277287        array(
    278             'tab_id'        => 'tab_2',
    279             'section_id'    => 'custom_css',
     288            'tab_id' => 'tab_2',
     289            'section_id' => 'custom_css',
    280290            'section_title' => 'Custom CSS',
    281291            'section_description' => 'Enter any custom CSS here to extensively style popup and links. <br>You can also re-define BibleUp CSS variables using the <b>:root</b> selector.<br> Check the guide <a href="">here</a> for how to style using the <b>buid</b> property.',
    282292            'section_order' => 10,
    283             'fields'        => array(
    284                 array(
    285                     'id'      => 'custom_css',
    286                     'title'   => 'Custom CSS',
    287                     'desc'    => 'Enter custom CSS',
    288                     'type'        => 'code_editor',
     293            'fields' => array(
     294                array(
     295                    'id' => 'custom_css',
     296                    'title' => 'Custom CSS',
     297                    'subtitle' => 'customisation',
     298                    'desc' => 'Enter custom CSS',
     299                    'type' => 'code_editor',
    289300                    'mimetype' => 'text/css',
    290301                    'default' => '',
    291                     'link'     => array(
    292                         'url'      => esc_url( 'https://bibleup.netlify.app/docs/customisation/' ),
    293                         'type'     => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
    294                         'text'     => 'Learn More',
     302                    'link' => array(
     303                        'url' => esc_url('https://bibleup.netlify.app/docs/customisation/'),
     304                        'type' => 'link', // Can be 'tooltip' or 'link'. Default is 'tooltip'.
     305                        'text' => 'Learn More',
    295306                        'external' => true,
    296307                    ),
  • bibleup/trunk/wp-settings-framework/wp-settings-framework.php

    r2862460 r3175163  
    99 */
    1010
    11 if ( ! class_exists( 'Bibleup_WordPressSettingsFramework' ) ) {
     11if (!class_exists('Bibleup_WordPressSettingsFramework')) {
    1212    /**
    1313     * Bibleup_WordPressSettingsFramework class
    1414     */
    15     class Bibleup_WordPressSettingsFramework {
     15    class Bibleup_WordPressSettingsFramework
     16    {
    1617        /**
    1718         * @access private
     
    6162         */
    6263        protected $setting_defaults = array(
    63             'id'          => 'default_field',
    64             'title'       => 'Default Field',
    65             'desc'        => '',
    66             'std'         => '',
    67             'type'        => 'text',
     64            'id' => 'default_field',
     65            'title' => 'Default Field',
     66            'desc' => '',
     67            'std' => '',
     68            'type' => 'text',
    6869            'placeholder' => '',
    69             'choices'     => array(),
    70             'class'       => '',
    71             'subfields'   => array(),
     70            'choices' => array(),
     71            'class' => '',
     72            'subfields' => array(),
    7273        );
    7374
     
    7879         * @param bool|string $option_group  Option group name, usually a short slug.
    7980         */
    80         public function __construct( $settings_file = null, $option_group = false ) {
     81        public function __construct($settings_file = null, $option_group = false)
     82        {
    8183            $this->option_group = $option_group;
    8284
    83             if ( $settings_file ) {
    84                 if ( ! is_file( $settings_file ) ) {
     85            if ($settings_file) {
     86                if (!is_file($settings_file)) {
    8587                    return;
    8688                }
     
    8890                require_once $settings_file;
    8991
    90                 if ( ! $this->option_group ) {
    91                     $this->option_group = preg_replace( '/[^a-z0-9]+/i', '', basename( $settings_file, '.php' ) );
     92                if (!$this->option_group) {
     93                    $this->option_group = preg_replace('/[^a-z0-9]+/i', '', basename($settings_file, '.php'));
    9294                }
    9395            }
    9496
    95             if ( empty( $this->option_group ) ) {
     97            if (empty($this->option_group)) {
    9698                return;
    9799            }
    98100
    99             $this->options_path = plugin_dir_path( __FILE__ );
    100             $this->options_url  = plugin_dir_url( __FILE__ );
     101            $this->options_path = plugin_dir_path(__FILE__);
     102            $this->options_url = plugin_dir_url(__FILE__);
    101103
    102104            $this->construct_settings();
    103105
    104             if ( is_admin() ) {
     106            if (is_admin()) {
    105107                global $pagenow;
    106108
    107                 add_action( 'admin_init', array( $this, 'admin_init' ) );
    108                 add_action( 'wpsf_do_settings_sections_' . $this->option_group, array( $this, 'do_tabless_settings_sections' ), 10 );
    109 
    110                 if ( isset( $_GET['page'] ) && $_GET['page'] === $this->settings_page['slug'] ) {
    111                     if ( $pagenow !== 'options-general.php' ) {
    112                         add_action( 'admin_notices', array( $this, 'admin_notices' ) );
     109                add_action('admin_init', array($this, 'admin_init'));
     110                add_action('wpsf_do_settings_sections_' . $this->option_group, array($this, 'do_tabless_settings_sections'), 10);
     111
     112                if (isset($_GET['page']) && $_GET['page'] === $this->settings_page['slug']) {
     113                    if ($pagenow !== 'options-general.php') {
     114                        add_action('admin_notices', array($this, 'admin_notices'));
    113115                    }
    114                     add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
     116                    add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
    115117                }
    116118
    117                 if ( $this->has_tabs() ) {
    118                     add_action( 'wpsf_before_settings_' . $this->option_group, array( $this, 'tab_links' ) );
    119 
    120                     remove_action( 'wpsf_do_settings_sections_' . $this->option_group, array( $this, 'do_tabless_settings_sections' ), 10 );
    121                     add_action( 'wpsf_do_settings_sections_' . $this->option_group, array( $this, 'do_tabbed_settings_sections' ), 10 );
     119                if ($this->has_tabs()) {
     120                    add_action('wpsf_before_settings_' . $this->option_group, array($this, 'tab_links'));
     121
     122                    remove_action('wpsf_do_settings_sections_' . $this->option_group, array($this, 'do_tabless_settings_sections'), 10);
     123                    add_action('wpsf_do_settings_sections_' . $this->option_group, array($this, 'do_tabbed_settings_sections'), 10);
    122124                }
    123125
    124                 add_action( 'wp_ajax_wpsf_export_settings', array( $this, 'export_settings' ) );
    125                 add_action( 'wp_ajax_wpsf_import_settings', array( $this, 'import_settings' ) );
     126                add_action('wp_ajax_wpsf_export_settings', array($this, 'export_settings'));
     127                add_action('wp_ajax_wpsf_import_settings', array($this, 'import_settings'));
    126128            }
    127129        }
     
    130132         * Construct Settings.
    131133         */
    132         public function construct_settings() {
    133             $this->settings_wrapper = apply_filters( 'wpsf_register_settings_' . $this->option_group, array() );
    134 
    135             if ( ! is_array( $this->settings_wrapper ) ) {
    136                 return new WP_Error( 'broke', esc_html__( 'WPSF settings must be an array', 'wpsf' ) );
     134        public function construct_settings()
     135        {
     136            $this->settings_wrapper = apply_filters('wpsf_register_settings_' . $this->option_group, array());
     137
     138            if (!is_array($this->settings_wrapper)) {
     139                return new WP_Error('broke', esc_html__('WPSF settings must be an array', 'wpsf'));
    137140            }
    138141
    139142            // If "sections" is set, this settings group probably has tabs
    140             if ( isset( $this->settings_wrapper['sections'] ) ) {
    141                 $this->tabs     = ( isset( $this->settings_wrapper['tabs'] ) ) ? $this->settings_wrapper['tabs'] : array();
     143            if (isset($this->settings_wrapper['sections'])) {
     144                $this->tabs = (isset($this->settings_wrapper['tabs'])) ? $this->settings_wrapper['tabs'] : array();
    142145                $this->settings = $this->settings_wrapper['sections'];
    143146                // If not, it's probably just an array of settings
     
    146149            }
    147150
    148             $this->settings_page['slug'] = sprintf( '%s-settings', str_replace( '_', '-', $this->option_group ) );
     151            $this->settings_page['slug'] = sprintf('%s-settings', str_replace('_', '-', $this->option_group));
    149152        }
    150153
     
    154157         * @return string the "option_group"
    155158         */
    156         public function get_option_group() {
     159        public function get_option_group()
     160        {
    157161            return $this->option_group;
    158162        }
     
    161165         * Registers the internal WordPress settings
    162166         */
    163         public function admin_init() {
    164             register_setting( $this->option_group, $this->option_group . '_settings', array( $this, 'settings_validate' ) );
     167        public function admin_init()
     168        {
     169            register_setting($this->option_group, $this->option_group . '_settings', array($this, 'settings_validate'));
    165170            $this->process_settings();
    166171        }
     
    171176         * @param array $args
    172177         */
    173         public function add_settings_page( $args ) {
     178        public function add_settings_page($args)
     179        {
    174180            $defaults = array(
    175181                'parent_slug' => false,
    176                 'page_slug'   => '',
    177                 'page_title'  => '',
    178                 'menu_title'  => '',
    179                 'capability'  => 'manage_options',
     182                'page_slug' => '',
     183                'page_title' => '',
     184                'menu_title' => '',
     185                'capability' => 'manage_options',
    180186            );
    181187
    182             $args = wp_parse_args( $args, $defaults );
    183 
    184             $this->settings_page['title']      = $args['page_title'];
     188            $args = wp_parse_args($args, $defaults);
     189
     190            $this->settings_page['title'] = $args['page_title'];
    185191            $this->settings_page['capability'] = $args['capability'];
    186192
    187             if ( $args['parent_slug'] ) {
     193            if ($args['parent_slug']) {
    188194                add_submenu_page(
    189195                    $args['parent_slug'],
     
    192198                    $args['capability'],
    193199                    $this->settings_page['slug'],
    194                     array( $this, 'settings_page_content' )
     200                    array($this, 'settings_page_content')
    195201                );
    196202            } else {
     
    200206                    $args['capability'],
    201207                    $this->settings_page['slug'],
    202                     array( $this, 'settings_page_content' ),
    203                     apply_filters( 'wpsf_menu_icon_url_' . $this->option_group, '' ),
    204                     apply_filters( 'wpsf_menu_position_' . $this->option_group, null )
     208                    array($this, 'settings_page_content'),
     209                    apply_filters('wpsf_menu_icon_url_' . $this->option_group, ''),
     210                    apply_filters('wpsf_menu_position_' . $this->option_group, null)
    205211                );
    206212            }
     
    211217         */
    212218
    213         public function settings_page_content() {
    214             if ( ! current_user_can( $this->settings_page['capability'] ) ) {
    215                 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wpsf' ) );
     219        public function settings_page_content()
     220        {
     221            if (!current_user_can($this->settings_page['capability'])) {
     222                wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'wpsf'));
    216223            }
    217224            ?>
    218             <div class="wpsf-settings wpsf-settings--<?php echo esc_attr( $this->option_group ); ?>">
     225            <div class="wpsf-settings wpsf-settings--<?php echo esc_attr($this->option_group); ?>">
    219226                <?php $this->settings_header(); ?>
    220227                <div class="wpsf-settings__content">
     
    228235         * Settings Header.
    229236         */
    230         public function settings_header() {
     237        public function settings_header()
     238        {
    231239            ?>
    232240            <div class="wpsf-settings__header">
    233                 <img src="<?php echo plugin_dir_url( __FILE__ ) . 'assets/img/logo.png'; ?>" width="50" height="50" alt="BibleUp Logo"/>
    234                 <h1><?php echo apply_filters( 'wpsf_title_' . $this->option_group, $this->settings_page['title'] ); ?></h1>
    235                 <?php do_action( 'wpsf_after_title_' . $this->option_group ); ?>
     241                <img src="<?php echo plugin_dir_url(__FILE__) . 'assets/img/logo.png'; ?>" width="50" height="50"
     242                    alt="BibleUp Logo" />
     243                <h1><?php echo apply_filters('wpsf_title_' . $this->option_group, $this->settings_page['title']); ?></h1>
     244                <?php do_action('wpsf_after_title_' . $this->option_group); ?>
    236245            </div>
    237246            <?php
     
    241250         * Displays any errors from the WordPress settings API
    242251         */
    243         public function admin_notices() {
     252        public function admin_notices()
     253        {
    244254            settings_errors();
    245255        }
     
    248258         * Enqueue scripts and styles
    249259         */
    250         public function admin_enqueue_scripts() {
     260        public function admin_enqueue_scripts()
     261        {
    251262            // scripts
    252             wp_register_script( 'wpsf', $this->options_url . 'assets/js/main.js', array( 'jquery' ), false, true );
    253 
    254             wp_enqueue_script( 'jquery' );
    255             wp_enqueue_script( 'farbtastic' );
    256             wp_enqueue_script( 'media-upload' );
    257             wp_enqueue_script( 'thickbox' );
    258             wp_enqueue_script( 'jquery-ui-core' );
    259             wp_enqueue_script( 'jquery-ui-datepicker' );
    260             wp_enqueue_script( 'wpsf' );
     263            wp_register_script('wpsf', $this->options_url . 'assets/js/main.js', array('jquery'), false, true);
     264
     265            wp_enqueue_script('jquery');
     266            wp_enqueue_script('farbtastic');
     267            wp_enqueue_script('media-upload');
     268            wp_enqueue_script('thickbox');
     269            wp_enqueue_script('jquery-ui-core');
     270            wp_enqueue_script('jquery-ui-datepicker');
     271            wp_enqueue_script('wpsf');
    261272
    262273            $data = array(
    263                 'select_file'          => esc_html__( 'Please select a file to import', 'wpsf' ),
    264                 'invalid_file'         => esc_html__( 'Invalid file', 'wpsf' ),
    265                 'something_went_wrong' => esc_html__( 'Something went wrong', 'wpsf' ),
     274                'select_file' => esc_html__('Please select a file to import', 'wpsf'),
     275                'invalid_file' => esc_html__('Invalid file', 'wpsf'),
     276                'something_went_wrong' => esc_html__('Something went wrong', 'wpsf'),
    266277            );
    267             wp_localize_script( 'wpsf', 'wpsf_vars', $data );
     278            wp_localize_script('wpsf', 'wpsf_vars', $data);
    268279
    269280            // styles
    270             wp_register_style( 'wpsf', $this->options_url . 'assets/css/main.css' );
    271             wp_register_style( 'jquery-ui-css', 'assets/css/jquery-ui-css.css' );
    272 
    273             wp_enqueue_style( 'farbtastic' );
    274             wp_enqueue_style( 'thickbox' );
    275             wp_enqueue_style( 'jquery-ui-css' );
    276             wp_enqueue_style( 'wpsf' );
     281            wp_register_style('wpsf', $this->options_url . 'assets/css/main.css');
     282            wp_register_style('jquery-ui-css', 'assets/css/jquery-ui-css.css');
     283
     284            wp_enqueue_style('farbtastic');
     285            wp_enqueue_style('thickbox');
     286            wp_enqueue_style('jquery-ui-css');
     287            wp_enqueue_style('wpsf');
    277288        }
    278289
     
    284295         * @return array
    285296         */
    286         public function settings_validate( $input ) {
    287             return apply_filters( $this->option_group . '_settings_validate', $input );
     297        public function settings_validate($input)
     298        {
     299            return apply_filters($this->option_group . '_settings_validate', $input);
    288300        }
    289301
     
    293305         * @param array callback args from add_settings_section()
    294306         */
    295         public function section_intro( $args ) {
    296             if ( ! empty( $this->settings ) ) {
    297                 foreach ( $this->settings as $section ) {
    298                     if ( $section['section_id'] == $args['id'] ) {
     307        public function section_intro($args)
     308        {
     309            if (!empty($this->settings)) {
     310                foreach ($this->settings as $section) {
     311                    if ($section['section_id'] == $args['id']) {
    299312                        $renderClass = '';
    300313
    301                         $renderClass .= self::add_show_hide_classes( $section );
    302 
    303                         if ( $renderClass ) {
    304                             echo '<span class="' . esc_attr( $renderClass ) . '"></span>';
     314                        $renderClass .= self::add_show_hide_classes($section);
     315
     316                        if ($renderClass) {
     317                            echo '<span class="' . esc_attr($renderClass) . '"></span>';
    305318                        }
    306                         if ( isset( $section['section_description'] ) && $section['section_description'] ) {
    307                             echo '<div class="wpsf-section-description wpsf-section-description--' . esc_attr( $section['section_id'] ) . '">' . $section['section_description'] . '</div>';
     319                        if (isset($section['section_description']) && $section['section_description']) {
     320                            echo '<div class="wpsf-section-description wpsf-section-description--' . esc_attr($section['section_id']) . '">' . $section['section_description'] . '</div>';
    308321                        }
    309322                        break;
     
    316329         * Processes $this->settings and adds the sections and fields via the WordPress settings API
    317330         */
    318         private function process_settings() {
    319             if ( ! empty( $this->settings ) ) {
    320                 usort( $this->settings, array( $this, 'sort_array' ) );
    321 
    322                 foreach ( $this->settings as $section ) {
    323                     if ( isset( $section['section_id'] ) && $section['section_id'] && isset( $section['section_title'] ) ) {
    324                         $page_name = ( $this->has_tabs() ) ? sprintf( '%s_%s', $this->option_group, $section['tab_id'] ) : $this->option_group;
    325 
    326                         add_settings_section( $section['section_id'], $section['section_title'], array( $this, 'section_intro' ), $page_name );
    327 
    328                         if ( isset( $section['fields'] ) && is_array( $section['fields'] ) && ! empty( $section['fields'] ) ) {
    329                             foreach ( $section['fields'] as $field ) {
    330                                 if ( isset( $field['id'] ) && $field['id'] && isset( $field['title'] ) ) {
    331                                     $tooltip     = '';
    332 
    333                                     if ( isset( $field['link'] ) && is_array( $field['link'] ) ) {
    334                                         $link_url      = ( isset( $field['link']['url'] ) ) ? esc_html( $field['link']['url'] ) : '';
    335                                         $link_text     = ( isset( $field['link']['text'] ) ) ? esc_html( $field['link']['text'] ) : esc_html__( 'Learn More', 'wpsf' );
    336                                         $link_external = ( isset( $field['link']['external'] ) ) ? (bool) $field['link']['external'] : true;
    337                                         $link_type     = ( isset( $field['link']['type'] ) ) ? esc_attr( $field['link']['type'] ) : 'tooltip';
    338                                         $link_target   = ( $link_external ) ? ' target="_blank"' : '';
    339 
    340                                         if ( 'tooltip' === $link_type ) {
    341                                             $link_text = sprintf( '<i class="dashicons dashicons-info wpsf-link-icon" title="%s"><span class="screen-reader-text">%s</span></i>', $link_text, $link_text );
     331        private function process_settings()
     332        {
     333            if (!empty($this->settings)) {
     334                usort($this->settings, array($this, 'sort_array'));
     335
     336                foreach ($this->settings as $section) {
     337                    if (isset($section['section_id']) && $section['section_id'] && isset($section['section_title'])) {
     338                        $page_name = ($this->has_tabs()) ? sprintf('%s_%s', $this->option_group, $section['tab_id']) : $this->option_group;
     339
     340                        add_settings_section($section['section_id'], $section['section_title'], array($this, 'section_intro'), $page_name);
     341
     342                        if (isset($section['fields']) && is_array($section['fields']) && !empty($section['fields'])) {
     343                            foreach ($section['fields'] as $field) {
     344                                if (isset($field['id']) && $field['id'] && isset($field['title'])) {
     345                                    $tooltip = '';
     346
     347                                    if (isset($field['link']) && is_array($field['link'])) {
     348                                        $link_url = (isset($field['link']['url'])) ? esc_html($field['link']['url']) : '';
     349                                        $link_text = (isset($field['link']['text'])) ? esc_html($field['link']['text']) : esc_html__('Learn More', 'wpsf');
     350                                        $link_external = (isset($field['link']['external'])) ? (bool) $field['link']['external'] : true;
     351                                        $link_type = (isset($field['link']['type'])) ? esc_attr($field['link']['type']) : 'tooltip';
     352                                        $link_target = ($link_external) ? ' target="_blank"' : '';
     353
     354                                        if ('tooltip' === $link_type) {
     355                                            $link_text = sprintf('<i class="dashicons dashicons-info wpsf-link-icon" title="%s"><span class="screen-reader-text">%s</span></i>', $link_text, $link_text);
    342356                                        }
    343357
    344                                         $link = ( $link_url ) ? sprintf( '<a class="wpsf-link" href="%s"%s>%s</a>', $link_url, $link_target, $link_text ) : '';
    345 
    346                                         if ( $link && 'tooltip' === $link_type ) {
     358                                        $link = ($link_url) ? sprintf('<a class="wpsf-link" href="%s"%s>%s</a>', $link_url, $link_target, $link_text) : '';
     359
     360                                        if ($link && 'tooltip' === $link_type) {
    347361                                            $tooltip = $link;
    348                                         } elseif ( $link ) {
    349                                             $field['subtitle'] .= ( empty( $field['subtitle'] ) ) ? $link : sprintf( '<br/><br/>%s', $link );
     362                                        } elseif ($link) {
     363                                            $field['subtitle'] .= (empty($field['subtitle'])) ? $link : sprintf('<br/><br/>%s', $link);
    350364                                        }
    351365                                    }
    352366
    353                                     $title = ( ! empty( $field['subtitle'] ) ) ? sprintf( '%s %s<span class="wpsf-subtitle">%s</span>', $field['title'], $tooltip, $field['subtitle'] ) : sprintf( '%s %s', $field['title'], $tooltip );
     367                                    $title = sprintf('<span class="wpsf-label">%s %s</span>', $field['title'], $tooltip);
     368
     369                                    if (!empty($field['subtitle'])) {
     370                                        $title .= sprintf('<span class="wpsf-subtitle">%s</span>', $field['subtitle']);
     371                                    }
    354372
    355373                                    add_settings_field(
    356374                                        $field['id'],
    357375                                        $title,
    358                                         array( $this, 'generate_setting' ),
     376                                        array($this, 'generate_setting'),
    359377                                        $page_name,
    360378                                        $section['section_id'],
    361379                                        array(
    362380                                            'section' => $section,
    363                                             'field'   => $field,
     381                                            'field' => $field,
    364382                                        )
    365383                                    );
     
    380398         * @return array
    381399         */
    382         public function sort_array( $a, $b ) {
    383             if ( ! isset( $a['section_order'] ) ) {
     400        public function sort_array($a, $b)
     401        {
     402            if (!isset($a['section_order'])) {
    384403                return 0;
    385404            }
    386405
    387             return ( $a['section_order'] > $b['section_order'] ) ? 1 : 0;
     406            return ($a['section_order'] > $b['section_order']) ? 1 : 0;
    388407        }
    389408
     
    393412         * @param array $args callback args from add_settings_field()
    394413         */
    395         public function generate_setting( $args ) {
    396             $section                = $args['section'];
    397             $this->setting_defaults = apply_filters( 'wpsf_defaults_' . $this->option_group, $this->setting_defaults );
    398 
    399             $args = wp_parse_args( $args['field'], $this->setting_defaults );
    400 
    401             $options = get_option( $this->option_group . '_settings' );
    402 
    403             $args['id']    = ( $this->has_tabs() ) ? sprintf( '%s_%s_%s', $section['tab_id'], $section['section_id'], $args['id'] ) : sprintf( '%s_%s', $section['section_id'], $args['id'] );
    404             $args['value'] = ( isset( $options[ $args['id'] ] ) ) ? $options[ $args['id'] ] : ( isset( $args['default'] ) ? $args['default'] : '' );
    405             $args['name']  = $this->generate_field_name( $args['id'] );
    406 
    407             $args['class'] .= self::add_show_hide_classes( $args );
    408 
    409             do_action( 'wpsf_before_field_' . $this->option_group );
    410             do_action( 'wpsf_before_field_' . $this->option_group . '_' . $args['id'] );
    411 
    412             $this->do_field_method( $args );
    413 
    414             do_action( 'wpsf_after_field_' . $this->option_group );
    415             do_action( 'wpsf_after_field_' . $this->option_group . '_' . $args['id'] );
     414        public function generate_setting($args)
     415        {
     416            $section = $args['section'];
     417            $this->setting_defaults = apply_filters('wpsf_defaults_' . $this->option_group, $this->setting_defaults);
     418
     419            $args = wp_parse_args($args['field'], $this->setting_defaults);
     420
     421            $options = get_option($this->option_group . '_settings');
     422
     423            $args['id'] = ($this->has_tabs()) ? sprintf('%s_%s_%s', $section['tab_id'], $section['section_id'], $args['id']) : sprintf('%s_%s', $section['section_id'], $args['id']);
     424            $args['value'] = (isset($options[$args['id']])) ? $options[$args['id']] : (isset($args['default']) ? $args['default'] : '');
     425            $args['name'] = $this->generate_field_name($args['id']);
     426
     427            $args['class'] .= self::add_show_hide_classes($args);
     428
     429            do_action('wpsf_before_field_' . $this->option_group);
     430            do_action('wpsf_before_field_' . $this->option_group . '_' . $args['id']);
     431
     432            $this->do_field_method($args);
     433
     434            do_action('wpsf_after_field_' . $this->option_group);
     435            do_action('wpsf_after_field_' . $this->option_group . '_' . $args['id']);
    416436        }
    417437
     
    421441         * @param array $args
    422442         */
    423         public function do_field_method( $args ) {
    424             $generate_field_method = sprintf( 'generate_%s_field', $args['type'] );
    425 
    426             if ( method_exists( $this, $generate_field_method ) ) {
    427                 $this->$generate_field_method( $args );
     443        public function do_field_method($args)
     444        {
     445            $generate_field_method = sprintf('generate_%s_field', $args['type']);
     446
     447            if (method_exists($this, $generate_field_method)) {
     448                $this->$generate_field_method($args);
    428449            }
    429450        }
     
    434455         * @param array $args
    435456         */
    436         public function generate_text_field( $args ) {
    437             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    438 
    439             echo '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . $args['value'] . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="regular-text ' . esc_attr( $args['class'] ) . '" />';
    440 
    441             $this->generate_description( $args['desc'] );
     457        public function generate_text_field($args)
     458        {
     459            $args['value'] = esc_attr(stripslashes($args['value']));
     460
     461            echo '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="' . $args['value'] . '" placeholder="' . esc_attr($args['placeholder']) . '" class="regular-text ' . esc_attr($args['class']) . '" />';
     462
     463            $this->generate_description($args['desc']);
    442464        }
    443465
     
    447469         * @param array $args
    448470         */
    449         public function generate_hidden_field( $args ) {
    450             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    451 
    452             echo '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . $args['value'] . '"  class="hidden-field ' . esc_attr( $args['class'] ) . '" />';
     471        public function generate_hidden_field($args)
     472        {
     473            $args['value'] = esc_attr(stripslashes($args['value']));
     474
     475            echo '<input type="hidden" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="' . $args['value'] . '"  class="hidden-field ' . esc_attr($args['class']) . '" />';
    453476        }
    454477
     
    458481         * @param array $args
    459482         */
    460         public function generate_number_field( $args ) {
    461             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    462 
    463             echo '<input type="number" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . $args['value'] . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="regular-text ' . esc_attr( $args['class'] ) . '" />';
    464 
    465             $this->generate_description( $args['desc'] );
     483        public function generate_number_field($args)
     484        {
     485            $args['value'] = esc_attr(stripslashes($args['value']));
     486
     487            echo '<input type="number" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="' . $args['value'] . '" placeholder="' . esc_attr($args['placeholder']) . '" class="regular-text ' . esc_attr($args['class']) . '" />';
     488
     489            $this->generate_description($args['desc']);
    466490        }
    467491
     
    471495         * @param array $args
    472496         */
    473         public function generate_date_field( $args ) {
    474             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    475 
    476             $datepicker = ( ! empty( $args['datepicker'] ) ) ? htmlentities( json_encode( $args['datepicker'] ) ) : null;
    477 
    478             echo '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . $args['value'] . '" class="datepicker regular-text ' . esc_attr( $args['class'] ) . '" data-datepicker="' . $datepicker . '" />';
    479 
    480             $this->generate_description( $args['desc'] );
     497        public function generate_date_field($args)
     498        {
     499            $args['value'] = esc_attr(stripslashes($args['value']));
     500
     501            $datepicker = (!empty($args['datepicker'])) ? htmlentities(json_encode($args['datepicker'])) : null;
     502
     503            echo '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="' . $args['value'] . '" class="datepicker regular-text ' . esc_attr($args['class']) . '" data-datepicker="' . $datepicker . '" />';
     504
     505            $this->generate_description($args['desc']);
    481506        }
    482507
     
    486511         * @param array $args Arguments.
    487512         */
    488         public function generate_export_field( $args ) {
    489             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    490             $args['value'] = empty( $args['value'] ) ? esc_html__( 'Export Settings', 'wpsf' ) : $args['value'];
    491             $option_group  = $this->option_group;
    492             $export_url    = site_url() . '/wp-admin/admin-ajax.php?action=wpsf_export_settings&_wpnonce=' . wp_create_nonce( 'wpsf_export_settings' ) . '&option_group=' . $option_group;
    493 
    494             echo '<a target=_blank href="' . $export_url . '" class="button" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '">' . $args['value'] . '</a>';
    495 
    496             $options = get_option( $option_group . '_settings' );
    497             $this->generate_description( $args['desc'] );
     513        public function generate_export_field($args)
     514        {
     515            $args['value'] = esc_attr(stripslashes($args['value']));
     516            $args['value'] = empty($args['value']) ? esc_html__('Export Settings', 'wpsf') : $args['value'];
     517            $option_group = $this->option_group;
     518            $export_url = site_url() . '/wp-admin/admin-ajax.php?action=wpsf_export_settings&_wpnonce=' . wp_create_nonce('wpsf_export_settings') . '&option_group=' . $option_group;
     519
     520            echo '<a target=_blank href="' . $export_url . '" class="button" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '">' . $args['value'] . '</a>';
     521
     522            $options = get_option($option_group . '_settings');
     523            $this->generate_description($args['desc']);
    498524        }
    499525
     
    503529         * @param array $args Arguments.
    504530         */
    505         public function generate_import_field( $args ) {
    506             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    507             $args['value'] = empty( $args['value'] ) ? esc_html__( 'Import Settings', 'wpsf' ) : $args['value'];
    508             $option_group  = $this->option_group;
     531        public function generate_import_field($args)
     532        {
     533            $args['value'] = esc_attr(stripslashes($args['value']));
     534            $args['value'] = empty($args['value']) ? esc_html__('Import Settings', 'wpsf') : $args['value'];
     535            $option_group = $this->option_group;
    509536
    510537            echo sprintf(
     
    519546                    <span class="spinner"></span>
    520547                </div>',
    521                 esc_attr( $args['id'] ),
    522                 esc_attr( $args['id'] ),
    523                 esc_attr( $args['value'] ),
    524                 esc_attr( wp_create_nonce( 'wpsf_import_settings' ) ),
    525                 esc_attr( $this->option_group )
     548                esc_attr($args['id']),
     549                esc_attr($args['id']),
     550                esc_attr($args['value']),
     551                esc_attr(wp_create_nonce('wpsf_import_settings')),
     552                esc_attr($this->option_group)
    526553            );
    527554
    528             $this->generate_description( $args['desc'] );
     555            $this->generate_description($args['desc']);
    529556        }
    530557
     
    536563         * @param array $args
    537564         */
    538         public function generate_group_field( $args ) {
    539             $value     = (array) $args['value'];
    540             $row_count = ( ! empty( $value ) ) ? count( $value ) : 1;
     565        public function generate_group_field($args)
     566        {
     567            $value = (array) $args['value'];
     568            $row_count = (!empty($value)) ? count($value) : 1;
    541569
    542570            echo '<table class="widefat wpsf-group" cellspacing="0">';
     
    544572            echo '<tbody>';
    545573
    546             for ( $row = 0; $row < $row_count; $row ++ ) {
    547                 echo $this->generate_group_row_template( $args, false, $row );
     574            for ($row = 0; $row < $row_count; $row++) {
     575                echo $this->generate_group_row_template($args, false, $row);
    548576            }
    549577
     
    551579            echo '</table>';
    552580
    553             printf( '<script type="text/html" id="%s_template">%s</script>', esc_attr( $args['id'] ), $this->generate_group_row_template( $args, true ) );
    554 
    555             $this->generate_description( $args['desc'] );
     581            printf('<script type="text/html" id="%s_template">%s</script>', esc_attr($args['id']), $this->generate_group_row_template($args, true));
     582
     583            $this->generate_description($args['desc']);
    556584        }
    557585
     
    564592         * @return void
    565593         */
    566         public function generate_image_checkboxes_field( $args ) {
    567 
    568             echo '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
     594        public function generate_image_checkboxes_field($args)
     595        {
     596
     597            echo '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />';
    569598
    570599            echo '<ul class="wpsf-visual-field wpsf-visual-field--image-checkboxes wpsf-visual-field--grid wpsf-visual-field--cols">';
    571600
    572             foreach ( $args['choices'] as $value => $choice ) {
    573                 $field_id      = sprintf( '%s_%s', esc_attr( $args['id'] ), $value );
    574                 $is_checked    = is_array( $args['value'] ) && in_array( $value, $args['value'] );
     601            foreach ($args['choices'] as $value => $choice) {
     602                $field_id = sprintf('%s_%s', esc_attr($args['id']), $value);
     603                $is_checked = is_array($args['value']) && in_array($value, $args['value']);
    575604                $checked_class = $is_checked ? 'wpsf-visual-field__item--checked' : '';
    576605
     
    587616                        </label>
    588617                    </li>',
    589                     esc_attr( $checked_class ),
    590                     esc_url( $choice['image'] ),
    591                     esc_attr( $args['name'] ),
    592                     esc_attr( $field_id ),
    593                     esc_attr( $value ),
    594                     esc_attr( $args['class'] ),
    595                     checked( true, $is_checked, false ),
    596                     esc_attr( $choice['text'] )
     618                    esc_attr($checked_class),
     619                    esc_url($choice['image']),
     620                    esc_attr($args['name']),
     621                    esc_attr($field_id),
     622                    esc_attr($value),
     623                    esc_attr($args['class']),
     624                    checked(true, $is_checked, false),
     625                    esc_attr($choice['text'])
    597626                );
    598627            }
     
    600629            echo '</ul>';
    601630
    602             $this->generate_description( $args['desc'] );
     631            $this->generate_description($args['desc']);
    603632        }
    604633
     
    608637         * @param array $args Arguments.
    609638         */
    610         public function generate_image_radio_field( $args ) {
    611             $args['value'] = esc_html( esc_attr( $args['value'] ) );
    612             $count         = count( $args['choices'] );
    613 
    614             echo sprintf( '<ul class="wpsf-visual-field wpsf-visual-field--image-radio wpsf-visual-field--grid wpsf-visual-field--cols wpsf-visual-field--col-%s ">', esc_attr( $count ) );
    615 
    616             foreach ( $args['choices'] as $value => $choice ) {
    617                 $field_id = sprintf( '%s_%s', esc_attr( $args['id'] ), $value );
    618                 $checked  = $value == $args['value'] ? 'checked="checked"' : '';
     639        public function generate_image_radio_field($args)
     640        {
     641            $args['value'] = esc_html(esc_attr($args['value']));
     642            $count = count($args['choices']);
     643
     644            echo sprintf('<ul class="wpsf-visual-field wpsf-visual-field--image-radio wpsf-visual-field--grid wpsf-visual-field--cols wpsf-visual-field--col-%s ">', esc_attr($count));
     645
     646            foreach ($args['choices'] as $value => $choice) {
     647                $field_id = sprintf('%s_%s', esc_attr($args['id']), $value);
     648                $checked = $value == $args['value'] ? 'checked="checked"' : '';
    619649
    620650                echo sprintf(
     
    630660                        </label>
    631661                    </li>',
    632                     ( $checked ? 'wpsf-visual-field__item--checked' : '' ),
    633                     esc_attr( $choice['image'] ),
    634                     esc_attr( $args['name'] ),
    635                     esc_attr( $field_id ),
    636                     esc_attr( $value ),
    637                     esc_attr( $args['class'] ),
    638                     esc_attr( $checked ),
    639                     esc_attr( $choice['text'] )
     662                    ($checked ? 'wpsf-visual-field__item--checked' : ''),
     663                    esc_attr($choice['image']),
     664                    esc_attr($args['name']),
     665                    esc_attr($field_id),
     666                    esc_attr($value),
     667                    esc_attr($args['class']),
     668                    esc_attr($checked),
     669                    esc_attr($choice['text'])
    640670                );
    641671            }
    642672            echo '</ul>';
    643673
    644             $this->generate_description( $args['desc'] );
     674            $this->generate_description($args['desc']);
    645675        }
    646676
     
    654684         * @return string|bool
    655685         */
    656         public function generate_group_row_template( $args, $blank = false, $row = 0 ) {
     686        public function generate_group_row_template($args, $blank = false, $row = 0)
     687        {
    657688            $row_template = false;
    658             $row_id       = ( ! empty( $args['value'][ $row ]['row_id'] ) ) ? $args['value'][ $row ]['row_id'] : $row;
    659             $row_id_value = ( $blank ) ? '' : $row_id;
    660 
    661             if ( $args['subfields'] ) {
    662                 $row_class = ( $row % 2 == 0 ) ? 'alternate' : '';
    663 
    664                 $row_template .= sprintf( '<tr class="wpsf-group__row %s">', $row_class );
    665 
    666                 $row_template .= sprintf( '<td class="wpsf-group__row-index"><span>%d</span></td>', $row );
     689            $row_id = (!empty($args['value'][$row]['row_id'])) ? $args['value'][$row]['row_id'] : $row;
     690            $row_id_value = ($blank) ? '' : $row_id;
     691
     692            if ($args['subfields']) {
     693                $row_class = ($row % 2 == 0) ? 'alternate' : '';
     694
     695                $row_template .= sprintf('<tr class="wpsf-group__row %s">', $row_class);
     696
     697                $row_template .= sprintf('<td class="wpsf-group__row-index"><span>%d</span></td>', $row);
    667698
    668699                $row_template .= '<td class="wpsf-group__row-fields">';
    669700
    670                 $row_template .= '<input type="hidden" class="wpsf-group__row-id" name="' . sprintf( '%s[%d][row_id]', esc_attr( $args['name'] ), esc_attr( $row ) ) . '" value="' . esc_attr( $row_id_value ) . '" />';
    671 
    672                 foreach ( $args['subfields'] as $subfield ) {
    673                     $subfield = wp_parse_args( $subfield, $this->setting_defaults );
    674 
    675                     $subfield['value'] = ( $blank ) ? '' : ( isset( $args['value'][ $row ][ $subfield['id'] ] ) ? $args['value'][ $row ][ $subfield['id'] ] : '' );
    676                     $subfield['name']  = sprintf( '%s[%d][%s]', esc_attr( $args['name'] ), $row, $subfield['id'] );
    677                     $subfield['id']    = sprintf( '%s_%d_%s', esc_attr( $args['id'] ), $row, $subfield['id'] );
    678 
    679                     $class = sprintf( 'wpsf-group__field-wrapper--%s', $subfield['type'] );
    680 
    681                     $row_template .= sprintf( '<div class="wpsf-group__field-wrapper %s">', $class );
    682                     $row_template .= sprintf( '<label for="%s" class="wpsf-group__field-label">%s</label>', $subfield['id'], $subfield['title'] );
     701                $row_template .= '<input type="hidden" class="wpsf-group__row-id" name="' . sprintf('%s[%d][row_id]', esc_attr($args['name']), esc_attr($row)) . '" value="' . esc_attr($row_id_value) . '" />';
     702
     703                foreach ($args['subfields'] as $subfield) {
     704                    $subfield = wp_parse_args($subfield, $this->setting_defaults);
     705
     706                    $subfield['value'] = ($blank) ? '' : (isset($args['value'][$row][$subfield['id']]) ? $args['value'][$row][$subfield['id']] : '');
     707                    $subfield['name'] = sprintf('%s[%d][%s]', esc_attr($args['name']), $row, $subfield['id']);
     708                    $subfield['id'] = sprintf('%s_%d_%s', esc_attr($args['id']), $row, $subfield['id']);
     709
     710                    $class = sprintf('wpsf-group__field-wrapper--%s', $subfield['type']);
     711
     712                    $row_template .= sprintf('<div class="wpsf-group__field-wrapper %s">', $class);
     713                    $row_template .= sprintf('<label for="%s" class="wpsf-group__field-label">%s</label>', $subfield['id'], $subfield['title']);
    683714
    684715                    ob_start();
    685                     $this->do_field_method( $subfield );
     716                    $this->do_field_method($subfield);
    686717                    $row_template .= ob_get_clean();
    687718
     
    693724                $row_template .= '<td class="wpsf-group__row-actions">';
    694725
    695                 $row_template .= sprintf( '<a href="javascript: void(0);" class="wpsf-group__row-add" data-template="%s_template"><span class="dashicons dashicons-plus-alt"></span></a>', esc_attr( $args['id'] ) );
     726                $row_template .= sprintf('<a href="javascript: void(0);" class="wpsf-group__row-add" data-template="%s_template"><span class="dashicons dashicons-plus-alt"></span></a>', esc_attr($args['id']));
    696727                $row_template .= '<a href="javascript: void(0);" class="wpsf-group__row-remove"><span class="dashicons dashicons-trash"></span></a>';
    697728
     
    709740         * @param array $args Arguments.
    710741         */
    711         public function generate_select_field( $args ) {
    712             $args['value'] = esc_html( esc_attr( $args['value'] ) );
    713 
    714             echo '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="' . esc_attr( $args['class'] ) . '">';
    715 
    716             foreach ( $args['choices'] as $value => $text ) {
    717                 if ( is_array( $text ) ) {
    718                     echo sprintf( '<optgroup label="%s">', esc_html( $value ) );
    719                     foreach ( $text as $group_value => $group_text ) {
    720                         $selected = ( $group_value === $args['value'] ) ? 'selected="selected"' : '';
    721                         echo sprintf( '<option value="%s" %s>%s</option>', esc_attr( $group_value ), esc_html( $selected ), esc_html( $group_text ) );
     742        public function generate_select_field($args)
     743        {
     744            $args['value'] = esc_html(esc_attr($args['value']));
     745
     746            echo '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="' . esc_attr($args['class']) . '">';
     747
     748            foreach ($args['choices'] as $value => $text) {
     749                if (is_array($text)) {
     750                    echo sprintf('<optgroup label="%s">', esc_html($value));
     751                    foreach ($text as $group_value => $group_text) {
     752                        $selected = ($group_value === $args['value']) ? 'selected="selected"' : '';
     753                        echo sprintf('<option value="%s" %s>%s</option>', esc_attr($group_value), esc_html($selected), esc_html($group_text));
    722754                    }
    723755                    echo '</optgroup>';
     
    725757                }
    726758
    727                 $selected = ( strval( $value ) === $args['value'] ) ? 'selected="selected"' : '';
    728 
    729                 echo sprintf( '<option value="%s" %s>%s</option>', esc_attr( $value ), esc_html( $selected ), esc_html( $text ) );
     759                $selected = (strval($value) === $args['value']) ? 'selected="selected"' : '';
     760
     761                echo sprintf('<option value="%s" %s>%s</option>', esc_attr($value), esc_html($selected), esc_html($text));
    730762            }
    731763
    732764            echo '</select>';
    733765
    734             $this->generate_description( $args['desc'] );
     766            $this->generate_description($args['desc']);
    735767        }
    736768
     
    740772         * @param array $args
    741773         */
    742         public function generate_password_field( $args ) {
    743             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    744 
    745             echo '<input type="password" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . $args['value'] . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="regular-text ' . esc_attr( $args['class'] ) . '" />';
    746 
    747             $this->generate_description( $args['desc'] );
     774        public function generate_password_field($args)
     775        {
     776            $args['value'] = esc_attr(stripslashes($args['value']));
     777
     778            echo '<input type="password" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="' . $args['value'] . '" placeholder="' . esc_attr($args['placeholder']) . '" class="regular-text ' . esc_attr($args['class']) . '" />';
     779
     780            $this->generate_description($args['desc']);
    748781        }
    749782
     
    753786         * @param array $args
    754787         */
    755         public function generate_textarea_field( $args ) {
    756             $args['value'] = esc_html( esc_attr( $args['value'] ) );
    757 
    758             echo '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" rows="15" cols="60" class="' . esc_attr( $args['class'] ) . '">' . $args['value'] . '</textarea>';
    759 
    760             $this->generate_description( $args['desc'] );
     788        public function generate_textarea_field($args)
     789        {
     790            $args['value'] = esc_html(esc_attr($args['value']));
     791
     792            echo '<textarea name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" placeholder="' . esc_attr($args['placeholder']) . '" rows="15" cols="60" class="' . esc_attr($args['class']) . '">' . $args['value'] . '</textarea>';
     793
     794            $this->generate_description($args['desc']);
    761795        }
    762796
     
    766800         * @param array $args
    767801         */
    768         public function generate_radio_field( $args ) {
    769             $args['value'] = esc_html( esc_attr( $args['value'] ) );
    770 
    771             foreach ( $args['choices'] as $value => $text ) {
    772                 $field_id = sprintf( '%s_%s', esc_attr( $args['id'] ), $value );
    773                 $checked  = ( $value == $args['value'] ) ? 'checked="checked"' : '';
    774 
    775                 echo sprintf( '<label><input type="radio" name="%s" id="%s" value="%s" class="%s" %s> %s</label><br />', esc_attr( $args['name'] ), $field_id, $value, $args['class'], $checked, $text );
    776             }
    777 
    778             $this->generate_description( $args['desc'] );
     802        public function generate_radio_field($args)
     803        {
     804            $args['value'] = esc_html(esc_attr($args['value']));
     805
     806            foreach ($args['choices'] as $value => $text) {
     807                $field_id = sprintf('%s_%s', esc_attr($args['id']), $value);
     808                $checked = ($value == $args['value']) ? 'checked="checked"' : '';
     809
     810                echo sprintf('<label><input type="radio" name="%s" id="%s" value="%s" class="%s" %s> %s</label><br />', esc_attr($args['name']), $field_id, $value, $args['class'], $checked, $text);
     811            }
     812
     813            $this->generate_description($args['desc']);
    779814        }
    780815
     
    784819         * @param array $args
    785820         */
    786         public function generate_checkbox_field( $args ) {
    787             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    788             $checked       = ( $args['value'] ) ? 'checked="checked"' : '';
    789 
    790             echo '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
    791             echo '<label><input type="checkbox" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="1" class="' . esc_attr( $args['class'] ) . '" ' . $checked . '> ' . esc_attr( $args['desc'] ) . '</label>';
     821        public function generate_checkbox_field($args)
     822        {
     823            $args['value'] = esc_attr(stripslashes($args['value']));
     824            $checked = ($args['value']) ? 'checked="checked"' : '';
     825
     826            echo '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />';
     827            echo '<label><input type="checkbox" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="1" class="' . esc_attr($args['class']) . '" ' . $checked . '> ' . esc_attr($args['desc']) . '</label>';
    792828        }
    793829
     
    797833         * @param array $args
    798834         */
    799         public function generate_toggle_field( $args ) {
    800             $args['value'] = esc_attr( stripslashes( $args['value'] ) );
    801             $checked       = ( $args['value'] ) ? 'checked="checked"' : '';
    802 
    803             echo '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
    804             echo '<label class="switch"><input type="checkbox" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" value="1" class="' . esc_attr( $args['class'] ) . '" ' . $checked . '> ' . esc_attr( $args['desc'] ) . '<span class="slider"></span></label>';
     835        public function generate_toggle_field($args)
     836        {
     837            $args['value'] = esc_attr(stripslashes($args['value']));
     838            $checked = ($args['value']) ? 'checked="checked"' : '';
     839
     840            echo '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />';
     841            echo '<label class="switch"><input type="checkbox" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" value="1" class="' . esc_attr($args['class']) . '" ' . $checked . '> ' . esc_attr($args['desc']) . '<span class="slider"></span></label>';
    805842        }
    806843
     
    810847         * @param array $args
    811848         */
    812         public function generate_checkboxes_field( $args ) {
    813             echo '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
     849        public function generate_checkboxes_field($args)
     850        {
     851            echo '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />';
    814852
    815853            echo '<ul class="wpsf-list wpsf-list--checkboxes">';
    816854
    817             foreach ( $args['choices'] as $value => $text ) {
    818                 $checked  = ( is_array( $args['value'] ) && in_array( strval( $value ), array_map( 'strval', $args['value'] ), true ) ) ? 'checked="checked"' : '';
    819                 $field_id = sprintf( '%s_%s', esc_attr( $args['id'] ), $value );
    820 
    821                 echo sprintf( '<li><label><input type="checkbox" name="%s[]" id="%s" value="%s" class="%s" %s> %s</label></li>', esc_attr( $args['name'] ), $field_id, $value, esc_attr($args['class']), $checked, $text );
     855            foreach ($args['choices'] as $value => $text) {
     856                $checked = (is_array($args['value']) && in_array(strval($value), array_map('strval', $args['value']), true)) ? 'checked="checked"' : '';
     857                $field_id = sprintf('%s_%s', esc_attr($args['id']), $value);
     858
     859                echo sprintf('<li><label><input type="checkbox" name="%s[]" id="%s" value="%s" class="%s" %s> %s</label></li>', esc_attr($args['name']), $field_id, $value, esc_attr($args['class']), $checked, $text);
    822860            }
    823861
    824862            echo '</ul>';
    825863
    826             $this->generate_description( $args['desc'] );
     864            $this->generate_description($args['desc']);
    827865        }
    828866
     
    832870         * @param array $args
    833871         */
    834         public function generate_color_field( $args ) {
    835             $color_picker_id = sprintf( '%s_cp', esc_attr( $args['id'] ) );
    836             $args['value']   = esc_attr( stripslashes( $args['value'] ) );
     872        public function generate_color_field($args)
     873        {
     874            $color_picker_id = sprintf('%s_cp', esc_attr($args['id']));
     875            $args['value'] = esc_attr(stripslashes($args['value']));
    837876
    838877            echo '<div style="position:relative;">';
    839878
    840             echo sprintf( '<input type="text" name="%s" id="%s" value="%s" class="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ), $args['value'], esc_attr( $args['class'] ) );
    841 
    842             echo sprintf( '<div id="%s" style="position:absolute;top:0;left:190px;background:#fff;z-index:9999;"></div>', $color_picker_id );
    843 
    844             $this->generate_description( $args['desc'] );
     879            echo sprintf('<input type="text" name="%s" id="%s" value="%s" class="%s">', esc_attr($args['name']), esc_attr($args['id']), $args['value'], esc_attr($args['class']));
     880
     881            echo sprintf('<div id="%s" style="position:absolute;top:0;left:190px;background:#fff;z-index:9999;"></div>', $color_picker_id);
     882
     883            $this->generate_description($args['desc']);
    845884
    846885            echo '<script type="text/javascript">
    847886                jQuery(document).ready(function($){
    848887                    var colorPicker = $("#' . $color_picker_id . '");
    849                     colorPicker.farbtastic("#' . esc_attr( $args['id'] ) . '");
     888                    colorPicker.farbtastic("#' . esc_attr($args['id']) . '");
    850889                    colorPicker.hide();
    851                     $("#' . esc_attr( $args['id'] ) . '").on("focus", function(){
     890                    $("#' . esc_attr($args['id']) . '").on("focus", function(){
    852891                        colorPicker.show();
    853892                    });
    854                     $("#' . esc_attr( $args['id'] ) . '").on("blur", function(){
     893                    $("#' . esc_attr($args['id']) . '").on("blur", function(){
    855894                        colorPicker.hide();
    856895                        if($(this).val() == "") $(this).val("#");
     
    867906         * @param array $args
    868907         */
    869         public function generate_file_field( $args ) {
    870             $args['value'] = esc_attr( $args['value'] );
    871             $button_id     = sprintf( '%s_button', esc_attr( $args['id'] ) );
    872 
    873             echo sprintf( '<input type="text" name="%s" id="%s" value="%s" class="regular-text %s"> ', esc_attr( $args['name'] ), esc_attr( $args['id'] ), $args['value'], esc_attr( $args['class'] ) );
    874 
    875             echo sprintf( '<input type="button" class="button wpsf-browse" id="%s" value="Browse" />', $button_id );
     908        public function generate_file_field($args)
     909        {
     910            $args['value'] = esc_attr($args['value']);
     911            $button_id = sprintf('%s_button', esc_attr($args['id']));
     912
     913            echo sprintf('<input type="text" name="%s" id="%s" value="%s" class="regular-text %s"> ', esc_attr($args['name']), esc_attr($args['id']), $args['value'], esc_attr($args['class']));
     914
     915            echo sprintf('<input type="button" class="button wpsf-browse" id="%s" value="Browse" />', $button_id);
    876916
    877917            ?>
    878918            <script type='text/javascript'>
    879                 jQuery( document ).ready( function( $ ) {
     919                jQuery(document).ready(function ($) {
    880920
    881921                    // Uploading files
     
    884924                    var set_to_post_id = 0;
    885925
    886                     jQuery( document.body ).on('click', '#<?php echo esc_attr( $button_id );?>', function( event ){
     926                    jQuery(document.body).on('click', '#<?php echo esc_attr($button_id); ?>', function (event) {
    887927
    888928                        event.preventDefault();
    889929
    890930                        // If the media frame already exists, reopen it.
    891                         if ( file_frame ) {
     931                        if (file_frame) {
    892932                            // Set the post ID to what we want
    893                             file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
     933                            file_frame.uploader.uploader.param('post_id', set_to_post_id);
    894934                            // Open frame
    895935                            file_frame.open();
     
    902942                        // Create the media frame.
    903943                        file_frame = wp.media.frames.file_frame = wp.media({
    904                             title: '<?php echo esc_html__( 'Select a image to upload', 'wpsf' ); ?>',
     944                            title: '<?php echo esc_html__('Select a image to upload', 'wpsf'); ?>',
    905945                            button: {
    906                                 text: '<?php echo esc_html__( 'Use this image', 'wpsf' ); ?>',
     946                                text: '<?php echo esc_html__('Use this image', 'wpsf'); ?>',
    907947                            },
    908948                            multiple: false // Set to true to allow multiple files to be selected
     
    910950
    911951                        // When an image is selected, run a callback.
    912                         file_frame.on( 'select', function() {
     952                        file_frame.on('select', function () {
    913953                            // We set multiple to false so only get one image from the uploader
    914954                            attachment = file_frame.state().get('selection').first().toJSON();
    915955
    916956                            // Do something with attachment.id and/or attachment.url here
    917                             $( '#image-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
    918                             $( '#image_attachment_id' ).val( attachment.id );
    919                             $( '#<?php echo esc_attr( $args['id']) ;?>' ).val( attachment.url );
     957                            $('#image-preview').attr('src', attachment.url).css('width', 'auto');
     958                            $('#image_attachment_id').val(attachment.id);
     959                            $('#<?php echo esc_attr($args['id']); ?>').val(attachment.url);
    920960
    921961                            // Restore the main post ID
     
    928968
    929969                    // Restore the main ID when the add media button is pressed
    930                     jQuery( 'a.add_media' ).on( 'click', function() {
     970                    jQuery('a.add_media').on('click', function () {
    931971                        wp.media.model.settings.post.id = wp_media_post_id;
    932972                    });
    933973                });
    934                 </script>
     974            </script>
    935975            <?php
    936976        }
     
    941981         * @param array $args
    942982         */
    943         public function generate_editor_field( $args ) {
    944             wp_editor( esc_attr( $args['value'] ), esc_attr( $args['id'] ), array( 'textarea_name' => esc_attr( $args['name'] ) ) );
    945 
    946             $this->generate_description( $args['desc'] );
     983        public function generate_editor_field($args)
     984        {
     985            wp_editor(esc_attr($args['value']), esc_attr($args['id']), array('textarea_name' => esc_attr($args['name'])));
     986
     987            $this->generate_description($args['desc']);
    947988        }
    948989
     
    952993         * @param array $args
    953994         */
    954         public function generate_code_editor_field( $args ) {
    955 
    956             $this->generate_description( $args['desc'] );
     995        public function generate_code_editor_field($args)
     996        {
     997
     998            $this->generate_description($args['desc']);
    957999            printf(
    9581000                '<textarea
     
    9641006                    class="%s"
    9651007                >%s</textarea>',
    966                 esc_attr( $args['name'] ),
    967                 esc_attr( $args['id'] ),
    968                 esc_attr( $args['placeholder'] ),
    969                 esc_attr( $args['class'] ),
    970                 esc_html( $args['value'] )
     1008                esc_attr($args['name']),
     1009                esc_attr($args['id']),
     1010                esc_attr($args['placeholder']),
     1011                esc_attr($args['class']),
     1012                esc_html($args['value'])
    9711013            );
    9721014
    973             $settings = wp_enqueue_code_editor( array( 'type' => esc_attr( $args['mimetype'] ) ) );
     1015            $settings = wp_enqueue_code_editor(array('type' => esc_attr($args['mimetype'])));
    9741016            $css = ".CodeMirror {
    9751017                margin: 10px;
     
    9821024                sprintf(
    9831025                    'jQuery( function() { wp.codeEditor.initialize( "%s", %s ); } );',
    984                     esc_attr( $args['id'] ),
    985                     wp_json_encode( $settings )
     1026                    esc_attr($args['id']),
     1027                    wp_json_encode($settings)
    9861028                )
    9871029            );
     
    9951037         * @param array $args
    9961038         */
    997         public function generate_custom_field( $args ) {
    998             if ( isset( $args['output'] ) && is_callable( $args['output'] ) ) {
    999                 call_user_func( $args['output'], $args );
     1039        public function generate_custom_field($args)
     1040        {
     1041            if (isset($args['output']) && is_callable($args['output'])) {
     1042                call_user_func($args['output'], $args);
    10001043                return;
    10011044            }
    10021045
    1003             echo ( isset( $args['output'] ) ) ? $args['output'] : $args['default'];
     1046            echo (isset($args['output'])) ? $args['output'] : $args['default'];
    10041047        }
    10051048
     
    10091052         * @param array $args
    10101053         */
    1011         public function generate_multiinputs_field( $args ) {
    1012             $field_titles = array_keys( $args['default'] );
    1013             $values       = array_values( $args['value'] );
     1054        public function generate_multiinputs_field($args)
     1055        {
     1056            $field_titles = array_keys($args['default']);
     1057            $values = array_values($args['value']);
    10141058
    10151059            echo '<div class="wpsf-multifields">';
    10161060
    10171061            $i = 0;
    1018             while ( $i < count( $values ) ) :
    1019 
    1020                 $field_id = sprintf( '%s_%s', esc_attr( $args['id'] ), $i );
    1021                 $value    = esc_attr( stripslashes( $values[ $i ] ) );
     1062            while ($i < count($values)):
     1063
     1064                $field_id = sprintf('%s_%s', esc_attr($args['id']), $i);
     1065                $value = esc_attr(stripslashes($values[$i]));
    10221066
    10231067                echo '<div class="wpsf-multifields__field">';
    1024                 echo '<input type="text" name="' . esc_attr( $args['name'] ) . '[]" id="' . $field_id . '" value="' . $value . '" class="regular-text ' . esc_attr( $args['class'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" />';
    1025                 echo '<br><span>' . $field_titles[ $i ] . '</span>';
     1068                echo '<input type="text" name="' . esc_attr($args['name']) . '[]" id="' . $field_id . '" value="' . $value . '" class="regular-text ' . esc_attr($args['class']) . '" placeholder="' . esc_attr($args['placeholder']) . '" />';
     1069                echo '<br><span>' . $field_titles[$i] . '</span>';
    10261070                echo '</div>';
    10271071
    1028                 $i ++;
    1029 endwhile;
     1072                $i++;
     1073            endwhile;
    10301074
    10311075            echo '</div>';
    10321076
    1033             $this->generate_description( $args['desc'] );
     1077            $this->generate_description($args['desc']);
    10341078        }
    10351079
     
    10411085         * @return string
    10421086         */
    1043         public function generate_field_name( $id ) {
    1044             return sprintf( '%s_settings[%s]', $this->option_group, $id );
     1087        public function generate_field_name($id)
     1088        {
     1089            return sprintf('%s_settings[%s]', $this->option_group, $id);
    10451090        }
    10461091
     
    10501095         * @param mixed $description
    10511096         */
    1052         public function generate_description( $description ) {
    1053             if ( $description && $description !== '' ) {
     1097        public function generate_description($description)
     1098        {
     1099            if ($description && $description !== '') {
    10541100                echo '<p class="description">' . $description . '</p>';
    10551101            }
     
    10591105         * Output the settings form
    10601106         */
    1061         public function settings() {
    1062             do_action( 'wpsf_before_settings_' . $this->option_group );
     1107        public function settings()
     1108        {
     1109            do_action('wpsf_before_settings_' . $this->option_group);
    10631110            ?>
    10641111            <form action="options.php" method="post" novalidate enctype="multipart/form-data">
    1065                 <?php do_action( 'wpsf_before_settings_fields_' . $this->option_group ); ?>
    1066                 <?php settings_fields( $this->option_group ); ?>
    1067 
    1068                 <?php do_action( 'wpsf_do_settings_sections_' . $this->option_group ); ?>
    1069 
    1070                 <?php if ( apply_filters( 'wpsf_show_save_changes_button_' . $this->option_group, true ) ) { ?>
     1112                <?php do_action('wpsf_before_settings_fields_' . $this->option_group); ?>
     1113                <?php settings_fields($this->option_group); ?>
     1114
     1115                <?php do_action('wpsf_do_settings_sections_' . $this->option_group); ?>
     1116
     1117                <?php if (apply_filters('wpsf_show_save_changes_button_' . $this->option_group, true)) { ?>
    10711118                    <p class="submit">
    1072                         <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
     1119                        <input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" />
    10731120                    </p>
    10741121                <?php } ?>
    10751122            </form>
    10761123            <?php
    1077             do_action( 'wpsf_after_settings_' . $this->option_group );
     1124            do_action('wpsf_after_settings_' . $this->option_group);
    10781125        }
    10791126
     
    10831130         * @return array
    10841131         */
    1085         public function get_settings() {
     1132        public function get_settings()
     1133        {
    10861134            $settings_name = $this->option_group . '_settings';
    10871135
    10881136            static $settings = array();
    10891137
    1090             if ( isset( $settings[ $settings_name ] ) ) {
    1091                 return $settings[ $settings_name ];
    1092             }
    1093 
    1094             $saved_settings             = get_option( $this->option_group . '_settings' );
    1095             $settings[ $settings_name ] = array();
    1096 
    1097             foreach ( $this->settings as $section ) {
    1098                 if ( empty( $section['fields'] ) ) {
     1138            if (isset($settings[$settings_name])) {
     1139                return $settings[$settings_name];
     1140            }
     1141
     1142            $saved_settings = get_option($this->option_group . '_settings');
     1143            $settings[$settings_name] = array();
     1144
     1145            foreach ($this->settings as $section) {
     1146                if (empty($section['fields'])) {
    10991147                    continue;
    11001148                }
    11011149
    1102                 foreach ( $section['fields'] as $field ) {
    1103                     if ( ! empty( $field['default'] ) && is_array( $field['default'] ) ) {
    1104                         $field['default'] = array_values( $field['default'] );
     1150                foreach ($section['fields'] as $field) {
     1151                    if (!empty($field['default']) && is_array($field['default'])) {
     1152                        $field['default'] = array_values($field['default']);
    11051153                    }
    11061154
    1107                     $setting_key = ( $this->has_tabs() ) ? sprintf( '%s_%s_%s', $section['tab_id'], $section['section_id'], $field['id'] ) : sprintf( '%s_%s', $section['section_id'], $field['id'] );
    1108 
    1109                     if ( isset( $saved_settings[ $setting_key ] ) ) {
    1110                         $settings[ $settings_name ][ $setting_key ] = $saved_settings[ $setting_key ];
     1155                    $setting_key = ($this->has_tabs()) ? sprintf('%s_%s_%s', $section['tab_id'], $section['section_id'], $field['id']) : sprintf('%s_%s', $section['section_id'], $field['id']);
     1156
     1157                    if (isset($saved_settings[$setting_key])) {
     1158                        $settings[$settings_name][$setting_key] = $saved_settings[$setting_key];
    11111159                    } else {
    1112                         $settings[ $settings_name ][ $setting_key ] = ( isset( $field['default'] ) ) ? $field['default'] : false;
     1160                        $settings[$settings_name][$setting_key] = (isset($field['default'])) ? $field['default'] : false;
    11131161                    }
    11141162                }
    11151163            }
    11161164
    1117             return $settings[ $settings_name ];
     1165            return $settings[$settings_name];
    11181166        }
    11191167
     
    11211169         * Tabless Settings sections
    11221170         */
    1123         public function do_tabless_settings_sections() {
     1171        public function do_tabless_settings_sections()
     1172        {
    11241173            ?>
    11251174            <div class="wpsf-section wpsf-tabless">
    1126                 <?php do_settings_sections( $this->option_group ); ?>
     1175                <?php do_settings_sections($this->option_group); ?>
    11271176            </div>
    11281177            <?php
     
    11321181         * Tabbed Settings sections
    11331182         */
    1134         public function do_tabbed_settings_sections() {
     1183        public function do_tabbed_settings_sections()
     1184        {
    11351185            $i = 0;
    1136             foreach ( $this->tabs as $tab_data ) {
     1186            foreach ($this->tabs as $tab_data) {
    11371187                ?>
    11381188                <div id="tab-<?php echo $tab_data['id']; ?>" class="wpsf-section wpsf-tab wpsf-tab--<?php echo $tab_data['id']; ?> <?php
    1139                 if ( $i == 0 ) {
    1140                     echo 'wpsf-tab--active';
    1141                 }
    1142                 ?>
     1189                       if ($i == 0) {
     1190                           echo 'wpsf-tab--active';
     1191                       }
     1192                       ?>
    11431193                ">
    11441194                    <div class="postbox">
    1145                         <?php do_settings_sections( sprintf( '%s_%s', $this->option_group, $tab_data['id'] ) ); ?>
     1195                        <?php do_settings_sections(sprintf('%s_%s', $this->option_group, $tab_data['id'])); ?>
    11461196                    </div>
    11471197                </div>
    11481198                <?php
    1149                 $i ++;
     1199                $i++;
    11501200            }
    11511201        }
     
    11541204         * Output the tab links
    11551205         */
    1156         public function tab_links() {
    1157             if ( ! apply_filters( 'wpsf_show_tab_links_' . $this->option_group, true ) ) {
     1206        public function tab_links()
     1207        {
     1208            if (!apply_filters('wpsf_show_tab_links_' . $this->option_group, true)) {
    11581209                return;
    11591210            }
    11601211
    1161             do_action( 'wpsf_before_tab_links_' . $this->option_group );
     1212            do_action('wpsf_before_tab_links_' . $this->option_group);
    11621213            ?>
    11631214            <ul class="wpsf-nav">
    11641215                <?php
    11651216                $i = 0;
    1166                 foreach ( $this->tabs as $tab_data ) {
    1167                     if ( ! $this->tab_has_settings( $tab_data['id'] ) ) {
     1217                foreach ($this->tabs as $tab_data) {
     1218                    if (!$this->tab_has_settings($tab_data['id'])) {
    11681219                        continue;
    11691220                    }
    11701221
    1171                     if ( ! isset( $tab_data['class'] ) ) {
     1222                    if (!isset($tab_data['class'])) {
    11721223                        $tab_data['class'] = '';
    11731224                    }
    11741225
    1175                     $tab_data['class'] .= self::add_show_hide_classes( $tab_data );
    1176 
    1177                     $active = ( $i == 0 ) ? 'wpsf-nav__item--active' : '';
     1226                    $tab_data['class'] .= self::add_show_hide_classes($tab_data);
     1227
     1228                    $active = ($i == 0) ? 'wpsf-nav__item--active' : '';
    11781229                    ?>
    11791230                    <li class="wpsf-nav__item <?php echo $active; ?>">
    1180                         <a class="wpsf-nav__item-link <?php echo esc_attr( $tab_data['class'] ); ?>" href="#tab-<?php echo $tab_data['id']; ?>"><?php echo $tab_data['title']; ?></a>
     1231                        <a class="wpsf-nav__item-link <?php echo esc_attr($tab_data['class']); ?>"
     1232                            href="#tab-<?php echo $tab_data['id']; ?>"><?php echo $tab_data['title']; ?></a>
    11811233                    </li>
    11821234                    <?php
    1183                     $i ++;
     1235                    $i++;
    11841236                }
    11851237                ?>
    11861238                <li class="wpsf-nav__item wpsf-nav__item--last">
    1187                     <input type="submit" class="button-primary wpsf-button-submit" value="<?php esc_attr_e( 'Save Changes' ); ?>">
     1239                    <input type="submit" class="button-primary wpsf-button-submit" value="<?php esc_attr_e('Save Changes'); ?>">
    11881240                </li>
    11891241            </ul>
    11901242
    11911243            <?php // Add this here so notices are moved. ?>
    1192             <div class="wrap wpsf-notices"><h2>&nbsp;</h2></div>
     1244            <div class="wrap wpsf-notices">
     1245                <h2>&nbsp;</h2>
     1246            </div>
    11931247            <?php
    1194             do_action( 'wpsf_after_tab_links_' . $this->option_group );
     1248            do_action('wpsf_after_tab_links_' . $this->option_group);
    11951249        }
    11961250
     
    12021256         * @return bool
    12031257         */
    1204         public function tab_has_settings( $tab_id ) {
    1205             if ( empty( $this->settings ) ) {
     1258        public function tab_has_settings($tab_id)
     1259        {
     1260            if (empty($this->settings)) {
    12061261                return false;
    12071262            }
    12081263
    1209             foreach ( $this->settings as $settings_section ) {
    1210                 if ( $tab_id !== $settings_section['tab_id'] ) {
     1264            foreach ($this->settings as $settings_section) {
     1265                if ($tab_id !== $settings_section['tab_id']) {
    12111266                    continue;
    12121267                }
     
    12211276         * Check if this settings instance has tabs
    12221277         */
    1223         public function has_tabs() {
    1224             if ( ! empty( $this->tabs ) ) {
     1278        public function has_tabs()
     1279        {
     1280            if (!empty($this->tabs)) {
    12251281                return true;
    12261282            }
     
    12321288         * Add Show Hide Classes.
    12331289         */
    1234         public static function add_show_hide_classes( $args, $type = 'show_if' ) {
     1290        public static function add_show_hide_classes($args, $type = 'show_if')
     1291        {
    12351292            $class = '';
    1236             $slug  = ' ' . str_replace( '_', '-', $type );
    1237             if ( isset( $args[ $type ] ) && is_array( $args[ $type ] ) ) {
     1293            $slug = ' ' . str_replace('_', '-', $type);
     1294            if (isset($args[$type]) && is_array($args[$type])) {
    12381295                $class .= $slug;
    1239                 foreach ( $args[ $type ] as $condition ) {
    1240                     if ( isset( $condition['field'] ) && $condition['value'] ) {
     1296                foreach ($args[$type] as $condition) {
     1297                    if (isset($condition['field']) && $condition['value']) {
    12411298                        $value_string = '';
    1242                         foreach ( $condition['value'] as $value ) {
    1243                             if ( ! empty( $value_string ) ) {
     1299                        foreach ($condition['value'] as $value) {
     1300                            if (!empty($value_string)) {
    12441301                                $value_string .= '||';
    12451302                            }
     
    12471304                        }
    12481305
    1249                         if ( ! empty( $value_string ) ) {
     1306                        if (!empty($value_string)) {
    12501307                            $class .= $slug . '--' . $condition['field'] . '===' . $value_string;
    12511308                        }
    12521309                    } else {
    12531310                        $and_string = '';
    1254                         foreach( $condition as $and_condition ) {
    1255                             if ( ! isset( $and_condition['field'] ) || ! isset( $and_condition['value'] ) ) {
     1311                        foreach ($condition as $and_condition) {
     1312                            if (!isset($and_condition['field']) || !isset($and_condition['value'])) {
    12561313                                continue;
    12571314                            }
    12581315
    1259                             if ( ! empty( $and_string ) ) {
     1316                            if (!empty($and_string)) {
    12601317                                $and_string .= '&&';
    12611318                            }
    12621319
    12631320                            $value_string = '';
    1264                             foreach ( $and_condition['value'] as $value ) {
    1265                                 if ( ! empty( $value_string ) ) {
     1321                            foreach ($and_condition['value'] as $value) {
     1322                                if (!empty($value_string)) {
    12661323                                    $value_string .= '||';
    12671324                                }
     
    12691326                            }
    12701327
    1271                             if ( ! empty( $value_string ) ) {
     1328                            if (!empty($value_string)) {
    12721329                                $and_string .= $and_condition['field'] . '===' . $value_string;
    12731330                            }
    12741331                        }
    12751332
    1276                         if ( ! empty( $and_string ) ) {
     1333                        if (!empty($and_string)) {
    12771334                            $class .= $slug . '--' . $and_string;
    12781335                        }
     
    12821339
    12831340            // Run the function again with hide if.
    1284             if ( 'hide_if' !== $type ) {
    1285                 $class .= self::add_show_hide_classes( $args, 'hide_if' );
     1341            if ('hide_if' !== $type) {
     1342                $class .= self::add_show_hide_classes($args, 'hide_if');
    12861343            }
    12871344
     
    12921349         * Handle export settings action.
    12931350         */
    1294         public static function export_settings() {
    1295             $_wpnonce     = filter_input( INPUT_GET, '_wpnonce' );
    1296             $option_group = filter_input( INPUT_GET, 'option_group' );
    1297 
    1298             if ( empty( $_wpnonce ) || ! wp_verify_nonce( $_wpnonce, 'wpsf_export_settings' ) ) {
    1299                 wp_die( esc_html__( 'Action failed.', 'wpsf' ) );
    1300             }
    1301 
    1302             if ( empty( $option_group ) ) {
    1303                 wp_die( esc_html__( 'No option group specified.', 'wpsf' ) );
    1304             }
    1305 
    1306             $options = get_option( $option_group . '_settings' );
    1307             $options = wp_json_encode( $options );
     1351        public static function export_settings()
     1352        {
     1353            $_wpnonce = filter_input(INPUT_GET, '_wpnonce');
     1354            $option_group = filter_input(INPUT_GET, 'option_group');
     1355
     1356            if (empty($_wpnonce) || !wp_verify_nonce($_wpnonce, 'wpsf_export_settings')) {
     1357                wp_die(esc_html__('Action failed.', 'wpsf'));
     1358            }
     1359
     1360            if (empty($option_group)) {
     1361                wp_die(esc_html__('No option group specified.', 'wpsf'));
     1362            }
     1363
     1364            $options = get_option($option_group . '_settings');
     1365            $options = wp_json_encode($options);
    13081366
    13091367            // output the file contents to the browser.
    1310             header( 'Content-Type: text/json; charset=utf-8' );
    1311             header( 'Content-Disposition: attachment; filename=wpsf-settings-' . $option_group . '.json' );
     1368            header('Content-Type: text/json; charset=utf-8');
     1369            header('Content-Disposition: attachment; filename=wpsf-settings-' . $option_group . '.json');
    13121370            echo $options;
    13131371            exit;
     
    13171375         * Import settings.
    13181376         */
    1319         public function import_settings() {
    1320             $_wpnonce     = filter_input( INPUT_POST, '_wpnonce' );
    1321             $option_group = filter_input( INPUT_POST, 'option_group' );
    1322             $settings     = filter_input( INPUT_POST, 'settings' );
    1323 
    1324             if ( $option_group !== $this->option_group ) {
     1377        public function import_settings()
     1378        {
     1379            $_wpnonce = filter_input(INPUT_POST, '_wpnonce');
     1380            $option_group = filter_input(INPUT_POST, 'option_group');
     1381            $settings = filter_input(INPUT_POST, 'settings');
     1382
     1383            if ($option_group !== $this->option_group) {
    13251384                return;
    13261385            }
    13271386
    13281387            // verify nonce.
    1329             if ( empty( $_wpnonce ) || ! wp_verify_nonce( $_wpnonce, 'wpsf_import_settings' ) ) {
     1388            if (empty($_wpnonce) || !wp_verify_nonce($_wpnonce, 'wpsf_import_settings')) {
    13301389                wp_send_json_error();
    13311390            }
    13321391
    13331392            // check if $settings is a valid json.
    1334             if ( ! is_string( $settings ) || ! is_array( json_decode( $settings, true ) ) ) {
     1393            if (!is_string($settings) || !is_array(json_decode($settings, true))) {
    13351394                wp_send_json_error();
    13361395            }
    13371396
    1338             $settings_data = json_decode( $settings, true );
    1339             update_option( $option_group . '_settings', $settings_data );
     1397            $settings_data = json_decode($settings, true);
     1398            update_option($option_group . '_settings', $settings_data);
    13401399
    13411400            wp_send_json_success();
     
    13441403}
    13451404
    1346 if ( ! function_exists( 'wpsf_get_setting_bibleup' ) ) {
     1405if (!function_exists('wpsf_get_setting_bibleup')) {
    13471406    /**
    13481407     * Get a setting from an option group
     
    13541413     * @return mixed
    13551414     */
    1356     function wpsf_get_setting_bibleup( $option_group, $section_id, $field_id ) {
    1357         $options = get_option( $option_group . '_settings' );
    1358         if ( isset( $options[ $section_id . '_' . $field_id ] ) ) {
    1359             return $options[ $section_id . '_' . $field_id ];
     1415    function wpsf_get_setting_bibleup($option_group, $section_id, $field_id)
     1416    {
     1417        $options = get_option($option_group . '_settings');
     1418        if (isset($options[$section_id . '_' . $field_id])) {
     1419            return $options[$section_id . '_' . $field_id];
    13601420        }
    13611421
     
    13641424}
    13651425
    1366 if ( ! function_exists( 'wpsf_delete_settings_bibleup' ) ) {
     1426if (!function_exists('wpsf_delete_settings_bibleup')) {
    13671427    /**
    13681428     * Delete all the saved settings from a settings file/option group
     
    13701430     * @param string $option_group
    13711431     */
    1372     function wpsf_delete_settings_bibleup( $option_group ) {
    1373         delete_option( $option_group . '_settings' );
     1432    function wpsf_delete_settings_bibleup($option_group)
     1433    {
     1434        delete_option($option_group . '_settings');
    13741435    }
    13751436}
Note: See TracChangeset for help on using the changeset viewer.