Changeset 3175163
- Timestamp:
- 10/24/2024 04:47:55 PM (16 months ago)
- Location:
- bibleup/trunk
- Files:
-
- 4 edited
-
bibleup.php (modified) (12 diffs)
-
readme.txt (modified) (5 diffs)
-
settings/settings-general.php (modified) (8 diffs)
-
wp-settings-framework/wp-settings-framework.php (modified) (77 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bibleup/trunk/bibleup.php
r2951254 r3175163 1 1 <?php 2 2 /* 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 */ 12 14 13 class BibleUp { 15 class BibleUp 16 { 14 17 15 18 private $plugin_path; // @var string … … 19 22 20 23 // 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__); 23 27 //this service is documented and delivery is pegged to major version @1 24 28 $this->script = 'https://cdn.jsdelivr.net/npm/@bibleup/bibleup@1/dist/umd/bibleup-core.min.js'; … … 26 30 27 31 // 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'); 30 34 31 35 // 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); 33 37 34 38 // 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')); 36 40 } 37 41 … … 39 43 * Add settings page. 40 44 */ 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( 43 48 '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', 47 52 )); 48 53 } … … 53 58 * @return mixed 54 59 */ 55 function validate_settings( $input ) { 60 function validate_settings($input) 61 { 56 62 // Do your settings validation here 57 63 // Same as $sanitize_callback from http://codex.wordpress.org/Function_Reference/register_setting … … 60 66 } 61 67 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')); 64 71 } 65 72 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); 70 78 wp_enqueue_style('bibleup-style', $this->style, null, 'v1'); 71 79 … … 84 92 } 85 93 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'); 90 116 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)) { 115 119 return ($isArray) ? $default : "'$default'"; 116 120 } else if ($prop == 'true') { … … 118 122 } else { 119 123 $prop = esc_js($prop); 120 return "' ${prop}'";124 return "'{$prop}'"; 121 125 } 122 126 }; … … 124 128 $r = " 125 129 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') . ", 133 137 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') . ", 144 148 } 145 149 }) … … 149 153 } 150 154 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'); 153 158 154 159 $r = " 155 let b = new BibleUp(document.body, " .$raw_options.");160 let b = new BibleUp(document.body, " . $raw_options . "); 156 161 b.create();"; 157 162 … … 159 164 } 160 165 161 function bibleup_deactivate() { 166 public static function bibleup_deactivate() 167 { 162 168 // Delete all saved settings from option group - bibleup 163 wpsf_delete_settings_bibleup( 'bibleup');169 wpsf_delete_settings_bibleup('bibleup'); 164 170 } 165 171 … … 168 174 $bibleup = new BibleUp(); 169 175 $bibleup->start(); 170 register_deactivation_hook( __FILE__, array( 'BibleUp', 'bibleup_deactivate' ));176 register_deactivation_hook(__FILE__, array('BibleUp', 'bibleup_deactivate')); -
bibleup/trunk/readme.txt
r2951254 r3175163 3 3 Tags: bible, references, reftagging, christian, scripture, popup 4 4 Requires at least: 5.6 5 Tested up to: 6. 35 Tested up to: 6.6 6 6 Requires PHP: 7.0 7 Stable tag: 1. 0.17 Stable tag: 1.1.0 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 23 23 ## Features 💡 24 24 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. 26 26 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. 28 28 29 29 - **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. 30 30 31 - **Agile development and contributions:** BibleUp is free and open-sourced, contributions can be made by anyone. Issues and requests will alsobe 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. 32 32 33 33 ## Demo 🛸 … … 38 38 39 39 == 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 = 41 BibleUp 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 = 45 We 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. 42 46 43 47 = How to report an issue or submit feature requests = … … 46 50 47 51 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) 55 55 56 56 = How can I help support = … … 81 81 3) Click on the 'Upload Plugin' button at the top left corner to reveal the file picker. 82 82 4) Select and upload the downloaded zip file. 83 5) Install the Plugin and activate once done. Configure the options as you want!83 5) Install the Plugin and activate it once done. Configure the options as you want! 84 84 85 You can find the settings page at **settings >> BibleUp** after activating the plugin. 85 After activating the plugin, you can find the settings page at **settings > BibleUp** 86 86 87 87 == Changelog == 88 = 1.1.0 = 89 * Added support for five more versions* 90 * Performance and bug fixes * 91 88 92 = 1.0.0 = 89 93 * Initial Release -
bibleup/trunk/settings/settings-general.php
r2862460 r3175163 21 21 */ 22 22 23 add_filter( 'wpsf_register_settings_bibleup', 'wpsf_tabbed_settings');23 add_filter('wpsf_register_settings_bibleup', 'wpsf_tabbed_settings'); 24 24 25 25 /** … … 32 32 * @param array $wpsf_settings settings. 33 33 */ 34 function wpsf_tabbed_settings( $wpsf_settings ) { 34 function wpsf_tabbed_settings($wpsf_settings) 35 { 35 36 // Tabs. 36 37 $wpsf_settings['tabs'] = array( 37 38 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'), 44 45 ), 45 46 ); … … 48 49 $wpsf_settings['sections'] = array( 49 50 array( 50 'tab_id' => 'tab_1',51 'section_id' => 'note',51 'tab_id' => 'tab_1', 52 'section_id' => 'note', 52 53 'section_description' => '<b>Please read the following before you begin to configure BibleUp</b><br> 53 54 There are two methods you can use to configure BibleUp - <b>select Options</b> or <b>Paste Config</b><br> … … 59 60 ), 60 61 array( 61 'tab_id' => 'tab_1',62 'section_id' => 'select_options',62 'tab_id' => 'tab_1', 63 'section_id' => 'select_options', 63 64 'section_title' => 'Select Options', 64 65 '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', 71 72 'default' => 'classic', 72 73 'choices' => array( 73 'classic' => 'classic',74 'classic' => 'classic', 74 75 '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', 83 84 'default' => 'KJV', 84 85 'choices' => array( 85 'KJV' => 'King James Version (KJV)',86 'KJV' => 'King James Version (KJV)', 86 87 '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> 95 102 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', 97 104 'default' => 'false', 98 105 'choices' => array( 99 'true' => 'True',106 'true' => 'True', 100 107 'false' => 'False', 101 108 ), … … 105 112 106 113 array( 107 'tab_id' => 'tab_1',108 'section_id' => 'popup_style',114 'tab_id' => 'tab_1', 115 'section_id' => 'popup_style', 109 116 'section_title' => 'Popup Style', 110 117 'section_description' => 'Set popup background and font colors.', 111 118 '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> 138 145 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> 153 160 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> 161 168 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', 170 177 'placeholder' => '5px', 171 178 'default' => 'false', 172 179 ), 173 180 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', 178 185 'placeholder' => '2px 6px 10px #404040', 179 186 'default' => 'false', 180 187 ), 181 188 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', 186 193 'placeholder' => '16px', 187 194 'default' => 'false', … … 190 197 ), 191 198 192 array(193 'tab_id' => 'tab_1',194 'section_id' => 'additional',199 array( 200 'tab_id' => 'tab_1', 201 'section_id' => 'additional', 195 202 'section_title' => 'Additional Settings', 196 203 'section_description' => 'Use these options to configure BibleUp behaviour.', 197 204 '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', 204 211 'default' => 'false', 205 212 'choices' => array( 206 'true' => 'True',213 'true' => 'True', 207 214 'false' => 'False', 208 215 ), 209 216 ), 210 217 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> 214 222 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', 222 230 'external' => true, 223 231 ), 224 232 ), 225 233 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> 229 238 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', 237 246 'external' => true, 238 247 ), 239 248 ), 240 249 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', 251 261 'external' => true, 252 262 ), 253 263 ), 254 264 ), 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', 260 270 'section_title' => 'Paste Config', 261 271 '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> … … 263 273 Leave the editor blank if you want to manually seclect options instead.', 264 274 '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', 271 281 'mimetype' => 'application/json', 272 282 'default' => '', … … 276 286 277 287 array( 278 'tab_id' => 'tab_2',279 'section_id' => 'custom_css',288 'tab_id' => 'tab_2', 289 'section_id' => 'custom_css', 280 290 'section_title' => 'Custom CSS', 281 291 '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.', 282 292 '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', 289 300 'mimetype' => 'text/css', 290 301 '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', 295 306 'external' => true, 296 307 ), -
bibleup/trunk/wp-settings-framework/wp-settings-framework.php
r2862460 r3175163 9 9 */ 10 10 11 if ( ! class_exists( 'Bibleup_WordPressSettingsFramework' )) {11 if (!class_exists('Bibleup_WordPressSettingsFramework')) { 12 12 /** 13 13 * Bibleup_WordPressSettingsFramework class 14 14 */ 15 class Bibleup_WordPressSettingsFramework { 15 class Bibleup_WordPressSettingsFramework 16 { 16 17 /** 17 18 * @access private … … 61 62 */ 62 63 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', 68 69 'placeholder' => '', 69 'choices' => array(),70 'class' => '',71 'subfields' => array(),70 'choices' => array(), 71 'class' => '', 72 'subfields' => array(), 72 73 ); 73 74 … … 78 79 * @param bool|string $option_group Option group name, usually a short slug. 79 80 */ 80 public function __construct( $settings_file = null, $option_group = false ) { 81 public function __construct($settings_file = null, $option_group = false) 82 { 81 83 $this->option_group = $option_group; 82 84 83 if ( $settings_file) {84 if ( ! is_file( $settings_file )) {85 if ($settings_file) { 86 if (!is_file($settings_file)) { 85 87 return; 86 88 } … … 88 90 require_once $settings_file; 89 91 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')); 92 94 } 93 95 } 94 96 95 if ( empty( $this->option_group )) {97 if (empty($this->option_group)) { 96 98 return; 97 99 } 98 100 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__); 101 103 102 104 $this->construct_settings(); 103 105 104 if ( is_admin()) {106 if (is_admin()) { 105 107 global $pagenow; 106 108 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')); 113 115 } 114 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ));116 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); 115 117 } 116 118 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); 122 124 } 123 125 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')); 126 128 } 127 129 } … … 130 132 * Construct Settings. 131 133 */ 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')); 137 140 } 138 141 139 142 // 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(); 142 145 $this->settings = $this->settings_wrapper['sections']; 143 146 // If not, it's probably just an array of settings … … 146 149 } 147 150 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)); 149 152 } 150 153 … … 154 157 * @return string the "option_group" 155 158 */ 156 public function get_option_group() { 159 public function get_option_group() 160 { 157 161 return $this->option_group; 158 162 } … … 161 165 * Registers the internal WordPress settings 162 166 */ 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')); 165 170 $this->process_settings(); 166 171 } … … 171 176 * @param array $args 172 177 */ 173 public function add_settings_page( $args ) { 178 public function add_settings_page($args) 179 { 174 180 $defaults = array( 175 181 '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', 180 186 ); 181 187 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']; 185 191 $this->settings_page['capability'] = $args['capability']; 186 192 187 if ( $args['parent_slug']) {193 if ($args['parent_slug']) { 188 194 add_submenu_page( 189 195 $args['parent_slug'], … … 192 198 $args['capability'], 193 199 $this->settings_page['slug'], 194 array( $this, 'settings_page_content')200 array($this, 'settings_page_content') 195 201 ); 196 202 } else { … … 200 206 $args['capability'], 201 207 $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) 205 211 ); 206 212 } … … 211 217 */ 212 218 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')); 216 223 } 217 224 ?> 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); ?>"> 219 226 <?php $this->settings_header(); ?> 220 227 <div class="wpsf-settings__content"> … … 228 235 * Settings Header. 229 236 */ 230 public function settings_header() { 237 public function settings_header() 238 { 231 239 ?> 232 240 <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); ?> 236 245 </div> 237 246 <?php … … 241 250 * Displays any errors from the WordPress settings API 242 251 */ 243 public function admin_notices() { 252 public function admin_notices() 253 { 244 254 settings_errors(); 245 255 } … … 248 258 * Enqueue scripts and styles 249 259 */ 250 public function admin_enqueue_scripts() { 260 public function admin_enqueue_scripts() 261 { 251 262 // 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'); 261 272 262 273 $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'), 266 277 ); 267 wp_localize_script( 'wpsf', 'wpsf_vars', $data);278 wp_localize_script('wpsf', 'wpsf_vars', $data); 268 279 269 280 // 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'); 277 288 } 278 289 … … 284 295 * @return array 285 296 */ 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); 288 300 } 289 301 … … 293 305 * @param array callback args from add_settings_section() 294 306 */ 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']) { 299 312 $renderClass = ''; 300 313 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>'; 305 318 } 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>'; 308 321 } 309 322 break; … … 316 329 * Processes $this->settings and adds the sections and fields via the WordPress settings API 317 330 */ 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); 342 356 } 343 357 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) { 347 361 $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); 350 364 } 351 365 } 352 366 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 } 354 372 355 373 add_settings_field( 356 374 $field['id'], 357 375 $title, 358 array( $this, 'generate_setting'),376 array($this, 'generate_setting'), 359 377 $page_name, 360 378 $section['section_id'], 361 379 array( 362 380 'section' => $section, 363 'field' => $field,381 'field' => $field, 364 382 ) 365 383 ); … … 380 398 * @return array 381 399 */ 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'])) { 384 403 return 0; 385 404 } 386 405 387 return ( $a['section_order'] > $b['section_order']) ? 1 : 0;406 return ($a['section_order'] > $b['section_order']) ? 1 : 0; 388 407 } 389 408 … … 393 412 * @param array $args callback args from add_settings_field() 394 413 */ 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']); 416 436 } 417 437 … … 421 441 * @param array $args 422 442 */ 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); 428 449 } 429 450 } … … 434 455 * @param array $args 435 456 */ 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']); 442 464 } 443 465 … … 447 469 * @param array $args 448 470 */ 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']) . '" />'; 453 476 } 454 477 … … 458 481 * @param array $args 459 482 */ 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']); 466 490 } 467 491 … … 471 495 * @param array $args 472 496 */ 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']); 481 506 } 482 507 … … 486 511 * @param array $args Arguments. 487 512 */ 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']); 498 524 } 499 525 … … 503 529 * @param array $args Arguments. 504 530 */ 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; 509 536 510 537 echo sprintf( … … 519 546 <span class="spinner"></span> 520 547 </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) 526 553 ); 527 554 528 $this->generate_description( $args['desc']);555 $this->generate_description($args['desc']); 529 556 } 530 557 … … 536 563 * @param array $args 537 564 */ 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; 541 569 542 570 echo '<table class="widefat wpsf-group" cellspacing="0">'; … … 544 572 echo '<tbody>'; 545 573 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); 548 576 } 549 577 … … 551 579 echo '</table>'; 552 580 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']); 556 584 } 557 585 … … 564 592 * @return void 565 593 */ 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" />'; 569 598 570 599 echo '<ul class="wpsf-visual-field wpsf-visual-field--image-checkboxes wpsf-visual-field--grid wpsf-visual-field--cols">'; 571 600 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']); 575 604 $checked_class = $is_checked ? 'wpsf-visual-field__item--checked' : ''; 576 605 … … 587 616 </label> 588 617 </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']) 597 626 ); 598 627 } … … 600 629 echo '</ul>'; 601 630 602 $this->generate_description( $args['desc']);631 $this->generate_description($args['desc']); 603 632 } 604 633 … … 608 637 * @param array $args Arguments. 609 638 */ 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"' : ''; 619 649 620 650 echo sprintf( … … 630 660 </label> 631 661 </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']) 640 670 ); 641 671 } 642 672 echo '</ul>'; 643 673 644 $this->generate_description( $args['desc']);674 $this->generate_description($args['desc']); 645 675 } 646 676 … … 654 684 * @return string|bool 655 685 */ 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 { 657 688 $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); 667 698 668 699 $row_template .= '<td class="wpsf-group__row-fields">'; 669 700 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']); 683 714 684 715 ob_start(); 685 $this->do_field_method( $subfield);716 $this->do_field_method($subfield); 686 717 $row_template .= ob_get_clean(); 687 718 … … 693 724 $row_template .= '<td class="wpsf-group__row-actions">'; 694 725 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'])); 696 727 $row_template .= '<a href="javascript: void(0);" class="wpsf-group__row-remove"><span class="dashicons dashicons-trash"></span></a>'; 697 728 … … 709 740 * @param array $args Arguments. 710 741 */ 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)); 722 754 } 723 755 echo '</optgroup>'; … … 725 757 } 726 758 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)); 730 762 } 731 763 732 764 echo '</select>'; 733 765 734 $this->generate_description( $args['desc']);766 $this->generate_description($args['desc']); 735 767 } 736 768 … … 740 772 * @param array $args 741 773 */ 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']); 748 781 } 749 782 … … 753 786 * @param array $args 754 787 */ 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']); 761 795 } 762 796 … … 766 800 * @param array $args 767 801 */ 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']); 779 814 } 780 815 … … 784 819 * @param array $args 785 820 */ 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>'; 792 828 } 793 829 … … 797 833 * @param array $args 798 834 */ 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>'; 805 842 } 806 843 … … 810 847 * @param array $args 811 848 */ 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" />'; 814 852 815 853 echo '<ul class="wpsf-list wpsf-list--checkboxes">'; 816 854 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); 822 860 } 823 861 824 862 echo '</ul>'; 825 863 826 $this->generate_description( $args['desc']);864 $this->generate_description($args['desc']); 827 865 } 828 866 … … 832 870 * @param array $args 833 871 */ 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'])); 837 876 838 877 echo '<div style="position:relative;">'; 839 878 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']); 845 884 846 885 echo '<script type="text/javascript"> 847 886 jQuery(document).ready(function($){ 848 887 var colorPicker = $("#' . $color_picker_id . '"); 849 colorPicker.farbtastic("#' . esc_attr( $args['id']) . '");888 colorPicker.farbtastic("#' . esc_attr($args['id']) . '"); 850 889 colorPicker.hide(); 851 $("#' . esc_attr( $args['id']) . '").on("focus", function(){890 $("#' . esc_attr($args['id']) . '").on("focus", function(){ 852 891 colorPicker.show(); 853 892 }); 854 $("#' . esc_attr( $args['id']) . '").on("blur", function(){893 $("#' . esc_attr($args['id']) . '").on("blur", function(){ 855 894 colorPicker.hide(); 856 895 if($(this).val() == "") $(this).val("#"); … … 867 906 * @param array $args 868 907 */ 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); 876 916 877 917 ?> 878 918 <script type='text/javascript'> 879 jQuery( document ).ready( function( $) {919 jQuery(document).ready(function ($) { 880 920 881 921 // Uploading files … … 884 924 var set_to_post_id = 0; 885 925 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) { 887 927 888 928 event.preventDefault(); 889 929 890 930 // If the media frame already exists, reopen it. 891 if ( file_frame) {931 if (file_frame) { 892 932 // 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); 894 934 // Open frame 895 935 file_frame.open(); … … 902 942 // Create the media frame. 903 943 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'); ?>', 905 945 button: { 906 text: '<?php echo esc_html__( 'Use this image', 'wpsf'); ?>',946 text: '<?php echo esc_html__('Use this image', 'wpsf'); ?>', 907 947 }, 908 948 multiple: false // Set to true to allow multiple files to be selected … … 910 950 911 951 // When an image is selected, run a callback. 912 file_frame.on( 'select', function() {952 file_frame.on('select', function () { 913 953 // We set multiple to false so only get one image from the uploader 914 954 attachment = file_frame.state().get('selection').first().toJSON(); 915 955 916 956 // 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); 920 960 921 961 // Restore the main post ID … … 928 968 929 969 // 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 () { 931 971 wp.media.model.settings.post.id = wp_media_post_id; 932 972 }); 933 973 }); 934 </script>974 </script> 935 975 <?php 936 976 } … … 941 981 * @param array $args 942 982 */ 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']); 947 988 } 948 989 … … 952 993 * @param array $args 953 994 */ 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']); 957 999 printf( 958 1000 '<textarea … … 964 1006 class="%s" 965 1007 >%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']) 971 1013 ); 972 1014 973 $settings = wp_enqueue_code_editor( array( 'type' => esc_attr( $args['mimetype'] ) ));1015 $settings = wp_enqueue_code_editor(array('type' => esc_attr($args['mimetype']))); 974 1016 $css = ".CodeMirror { 975 1017 margin: 10px; … … 982 1024 sprintf( 983 1025 '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) 986 1028 ) 987 1029 ); … … 995 1037 * @param array $args 996 1038 */ 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); 1000 1043 return; 1001 1044 } 1002 1045 1003 echo ( isset( $args['output'] )) ? $args['output'] : $args['default'];1046 echo (isset($args['output'])) ? $args['output'] : $args['default']; 1004 1047 } 1005 1048 … … 1009 1052 * @param array $args 1010 1053 */ 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']); 1014 1058 1015 1059 echo '<div class="wpsf-multifields">'; 1016 1060 1017 1061 $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])); 1022 1066 1023 1067 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>'; 1026 1070 echo '</div>'; 1027 1071 1028 $i ++;1029 endwhile;1072 $i++; 1073 endwhile; 1030 1074 1031 1075 echo '</div>'; 1032 1076 1033 $this->generate_description( $args['desc']);1077 $this->generate_description($args['desc']); 1034 1078 } 1035 1079 … … 1041 1085 * @return string 1042 1086 */ 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); 1045 1090 } 1046 1091 … … 1050 1095 * @param mixed $description 1051 1096 */ 1052 public function generate_description( $description ) { 1053 if ( $description && $description !== '' ) { 1097 public function generate_description($description) 1098 { 1099 if ($description && $description !== '') { 1054 1100 echo '<p class="description">' . $description . '</p>'; 1055 1101 } … … 1059 1105 * Output the settings form 1060 1106 */ 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); 1063 1110 ?> 1064 1111 <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)) { ?> 1071 1118 <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'); ?>" /> 1073 1120 </p> 1074 1121 <?php } ?> 1075 1122 </form> 1076 1123 <?php 1077 do_action( 'wpsf_after_settings_' . $this->option_group);1124 do_action('wpsf_after_settings_' . $this->option_group); 1078 1125 } 1079 1126 … … 1083 1130 * @return array 1084 1131 */ 1085 public function get_settings() { 1132 public function get_settings() 1133 { 1086 1134 $settings_name = $this->option_group . '_settings'; 1087 1135 1088 1136 static $settings = array(); 1089 1137 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'])) { 1099 1147 continue; 1100 1148 } 1101 1149 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']); 1105 1153 } 1106 1154 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]; 1111 1159 } 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; 1113 1161 } 1114 1162 } 1115 1163 } 1116 1164 1117 return $settings[ $settings_name];1165 return $settings[$settings_name]; 1118 1166 } 1119 1167 … … 1121 1169 * Tabless Settings sections 1122 1170 */ 1123 public function do_tabless_settings_sections() { 1171 public function do_tabless_settings_sections() 1172 { 1124 1173 ?> 1125 1174 <div class="wpsf-section wpsf-tabless"> 1126 <?php do_settings_sections( $this->option_group); ?>1175 <?php do_settings_sections($this->option_group); ?> 1127 1176 </div> 1128 1177 <?php … … 1132 1181 * Tabbed Settings sections 1133 1182 */ 1134 public function do_tabbed_settings_sections() { 1183 public function do_tabbed_settings_sections() 1184 { 1135 1185 $i = 0; 1136 foreach ( $this->tabs as $tab_data) {1186 foreach ($this->tabs as $tab_data) { 1137 1187 ?> 1138 1188 <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 ?> 1143 1193 "> 1144 1194 <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'])); ?> 1146 1196 </div> 1147 1197 </div> 1148 1198 <?php 1149 $i ++;1199 $i++; 1150 1200 } 1151 1201 } … … 1154 1204 * Output the tab links 1155 1205 */ 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)) { 1158 1209 return; 1159 1210 } 1160 1211 1161 do_action( 'wpsf_before_tab_links_' . $this->option_group);1212 do_action('wpsf_before_tab_links_' . $this->option_group); 1162 1213 ?> 1163 1214 <ul class="wpsf-nav"> 1164 1215 <?php 1165 1216 $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'])) { 1168 1219 continue; 1169 1220 } 1170 1221 1171 if ( ! isset( $tab_data['class'] )) {1222 if (!isset($tab_data['class'])) { 1172 1223 $tab_data['class'] = ''; 1173 1224 } 1174 1225 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' : ''; 1178 1229 ?> 1179 1230 <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> 1181 1233 </li> 1182 1234 <?php 1183 $i ++;1235 $i++; 1184 1236 } 1185 1237 ?> 1186 1238 <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'); ?>"> 1188 1240 </li> 1189 1241 </ul> 1190 1242 1191 1243 <?php // Add this here so notices are moved. ?> 1192 <div class="wrap wpsf-notices"><h2> </h2></div> 1244 <div class="wrap wpsf-notices"> 1245 <h2> </h2> 1246 </div> 1193 1247 <?php 1194 do_action( 'wpsf_after_tab_links_' . $this->option_group);1248 do_action('wpsf_after_tab_links_' . $this->option_group); 1195 1249 } 1196 1250 … … 1202 1256 * @return bool 1203 1257 */ 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)) { 1206 1261 return false; 1207 1262 } 1208 1263 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']) { 1211 1266 continue; 1212 1267 } … … 1221 1276 * Check if this settings instance has tabs 1222 1277 */ 1223 public function has_tabs() { 1224 if ( ! empty( $this->tabs ) ) { 1278 public function has_tabs() 1279 { 1280 if (!empty($this->tabs)) { 1225 1281 return true; 1226 1282 } … … 1232 1288 * Add Show Hide Classes. 1233 1289 */ 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 { 1235 1292 $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])) { 1238 1295 $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']) { 1241 1298 $value_string = ''; 1242 foreach ( $condition['value'] as $value) {1243 if ( ! empty( $value_string )) {1299 foreach ($condition['value'] as $value) { 1300 if (!empty($value_string)) { 1244 1301 $value_string .= '||'; 1245 1302 } … … 1247 1304 } 1248 1305 1249 if ( ! empty( $value_string )) {1306 if (!empty($value_string)) { 1250 1307 $class .= $slug . '--' . $condition['field'] . '===' . $value_string; 1251 1308 } 1252 1309 } else { 1253 1310 $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'])) { 1256 1313 continue; 1257 1314 } 1258 1315 1259 if ( ! empty( $and_string )) {1316 if (!empty($and_string)) { 1260 1317 $and_string .= '&&'; 1261 1318 } 1262 1319 1263 1320 $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)) { 1266 1323 $value_string .= '||'; 1267 1324 } … … 1269 1326 } 1270 1327 1271 if ( ! empty( $value_string )) {1328 if (!empty($value_string)) { 1272 1329 $and_string .= $and_condition['field'] . '===' . $value_string; 1273 1330 } 1274 1331 } 1275 1332 1276 if ( ! empty( $and_string )) {1333 if (!empty($and_string)) { 1277 1334 $class .= $slug . '--' . $and_string; 1278 1335 } … … 1282 1339 1283 1340 // 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'); 1286 1343 } 1287 1344 … … 1292 1349 * Handle export settings action. 1293 1350 */ 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); 1308 1366 1309 1367 // 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'); 1312 1370 echo $options; 1313 1371 exit; … … 1317 1375 * Import settings. 1318 1376 */ 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) { 1325 1384 return; 1326 1385 } 1327 1386 1328 1387 // verify nonce. 1329 if ( empty( $_wpnonce ) || ! wp_verify_nonce( $_wpnonce, 'wpsf_import_settings' )) {1388 if (empty($_wpnonce) || !wp_verify_nonce($_wpnonce, 'wpsf_import_settings')) { 1330 1389 wp_send_json_error(); 1331 1390 } 1332 1391 1333 1392 // 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))) { 1335 1394 wp_send_json_error(); 1336 1395 } 1337 1396 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); 1340 1399 1341 1400 wp_send_json_success(); … … 1344 1403 } 1345 1404 1346 if ( ! function_exists( 'wpsf_get_setting_bibleup' )) {1405 if (!function_exists('wpsf_get_setting_bibleup')) { 1347 1406 /** 1348 1407 * Get a setting from an option group … … 1354 1413 * @return mixed 1355 1414 */ 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]; 1360 1420 } 1361 1421 … … 1364 1424 } 1365 1425 1366 if ( ! function_exists( 'wpsf_delete_settings_bibleup' )) {1426 if (!function_exists('wpsf_delete_settings_bibleup')) { 1367 1427 /** 1368 1428 * Delete all the saved settings from a settings file/option group … … 1370 1430 * @param string $option_group 1371 1431 */ 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'); 1374 1435 } 1375 1436 }
Note: See TracChangeset
for help on using the changeset viewer.