@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function register_hook_listener() { |
| 59 | 59 | |
| 60 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 60 | + add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 61 | 61 | add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
| 62 | 62 | add_action( 'init', array( $this, 'general_init' ) ); |
| 63 | 63 | |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @return void |
| 294 | 294 | */ |
| 295 | 295 | public function settings_screen () |
| 296 | - { |
|
| 296 | + { |
|
| 297 | 297 | |
| 298 | - ?> |
|
| 298 | + ?> |
|
| 299 | 299 | <div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"> |
| 300 | 300 | <?php screen_icon('woothemes-sensei'); ?> |
| 301 | 301 | <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { |
| 302 | - echo ' <span class="version">' . $this->settings_version . '</span>'; |
|
| 303 | - } ?></h2> |
|
| 302 | + echo ' <span class="version">' . $this->settings_version . '</span>'; |
|
| 303 | + } ?></h2> |
|
| 304 | 304 | <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" |
| 305 | 305 | title="WooThemes"><img |
| 306 | 306 | src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes"/></a></p> |
@@ -308,26 +308,26 @@ discard block |
||
| 308 | 308 | <form action="options.php" method="post"> |
| 309 | 309 | |
| 310 | 310 | <?php |
| 311 | - $this->settings_tabs(); |
|
| 312 | - settings_fields($this->token); |
|
| 313 | - $page = 'woothemes-sensei-settings'; |
|
| 314 | - foreach ($this->sections as $section_id => $section) { |
|
| 311 | + $this->settings_tabs(); |
|
| 312 | + settings_fields($this->token); |
|
| 313 | + $page = 'woothemes-sensei-settings'; |
|
| 314 | + foreach ($this->sections as $section_id => $section) { |
|
| 315 | 315 | |
| 316 | - echo '<section id="' . $section_id . '">'; |
|
| 316 | + echo '<section id="' . $section_id . '">'; |
|
| 317 | 317 | |
| 318 | - if ($section['name']) |
|
| 319 | - echo "<h2>{$section['name']}</h2>\n"; |
|
| 318 | + if ($section['name']) |
|
| 319 | + echo "<h2>{$section['name']}</h2>\n"; |
|
| 320 | 320 | |
| 321 | - echo '<table class="form-table">'; |
|
| 322 | - do_settings_fields($page, $section_id ); |
|
| 323 | - echo '</table>'; |
|
| 321 | + echo '<table class="form-table">'; |
|
| 322 | + do_settings_fields($page, $section_id ); |
|
| 323 | + echo '</table>'; |
|
| 324 | 324 | |
| 325 | - echo '</section>'; |
|
| 325 | + echo '</section>'; |
|
| 326 | 326 | |
| 327 | - } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - submit_button(); |
|
| 330 | - ?> |
|
| 329 | + submit_button(); |
|
| 330 | + ?> |
|
| 331 | 331 | </form> |
| 332 | 332 | <?php do_action( 'settings_after_form' ); ?> |
| 333 | 333 | </div><!--/#woothemes-sensei--> |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | * @return void |
| 377 | 377 | */ |
| 378 | 378 | public function settings_errors () { |
| 379 | - settings_errors( $this->token . '-errors' ); |
|
| 379 | + settings_errors( $this->token . '-errors' ); |
|
| 380 | 380 | } // End settings_errors() |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
| 443 | 443 | if ( $has_description ) { |
| 444 | 444 | echo wp_kses( $args['data']['description'], array( 'a' => array( |
| 445 | - 'href' => array(), |
|
| 446 | - 'title' => array() |
|
| 447 | - ) |
|
| 445 | + 'href' => array(), |
|
| 446 | + 'title' => array() |
|
| 447 | + ) |
|
| 448 | 448 | ) |
| 449 | 449 | ) . '</label>' . "\n"; |
| 450 | 450 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | */ |
| 834 | 834 | public function enqueue_scripts () { |
| 835 | 835 | |
| 836 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 836 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 837 | 837 | |
| 838 | 838 | wp_enqueue_script( 'farbtastic' ); |
| 839 | 839 | wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version ); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * A settings API (wrapping the WordPress Settings API). |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @access public |
| 32 | 32 | * @since 1.0.0 |
| 33 | 33 | */ |
| 34 | - public function __construct () { |
|
| 34 | + public function __construct() { |
|
| 35 | 35 | |
| 36 | 36 | $this->token = 'woothemes-sensei-settings'; |
| 37 | 37 | $this->page_slug = 'woothemes-sensei-settings-api'; |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function register_hook_listener() { |
| 59 | 59 | |
| 60 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 61 | - add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
|
| 62 | - add_action( 'init', array( $this, 'general_init' ) ); |
|
| 60 | + add_action('admin_menu', array($this, 'register_settings_screen'), 60); |
|
| 61 | + add_action('admin_init', array($this, 'settings_fields')); |
|
| 62 | + add_action('init', array($this, 'general_init')); |
|
| 63 | 63 | |
| 64 | 64 | } // End setup_settings() |
| 65 | 65 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $this->init_sections(); |
| 74 | 74 | $this->init_fields(); |
| 75 | 75 | $this->get_settings(); |
| 76 | - if ( $this->has_tabs == true ) { |
|
| 76 | + if ($this->has_tabs == true) { |
|
| 77 | 77 | $this->create_tabs(); |
| 78 | 78 | } // End If Statement |
| 79 | 79 | } // End general_init() |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | * @since 1.0.0 |
| 85 | 85 | * @return void |
| 86 | 86 | */ |
| 87 | - public function init_sections () { |
|
| 87 | + public function init_sections() { |
|
| 88 | 88 | // Override this function in your class and assign the array of sections to $this->sections. |
| 89 | - _e( 'Override init_sections() in your class.', 'woothemes-sensei' ); |
|
| 89 | + _e('Override init_sections() in your class.', 'woothemes-sensei'); |
|
| 90 | 90 | } // End init_sections() |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | * @since 1.0.0 |
| 96 | 96 | * @return void |
| 97 | 97 | */ |
| 98 | - public function init_fields () { |
|
| 98 | + public function init_fields() { |
|
| 99 | 99 | // Override this function in your class and assign the array of sections to $this->fields. |
| 100 | - _e( 'Override init_fields() in your class.', 'woothemes-sensei' ); |
|
| 100 | + _e('Override init_fields() in your class.', 'woothemes-sensei'); |
|
| 101 | 101 | } // End init_fields() |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,34 +106,34 @@ discard block |
||
| 106 | 106 | * @since 1.1.0 |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - public function settings_tabs () { |
|
| 109 | + public function settings_tabs() { |
|
| 110 | 110 | |
| 111 | - if ( ! $this->has_tabs ) { return; } |
|
| 111 | + if ( ! $this->has_tabs) { return; } |
|
| 112 | 112 | |
| 113 | - if ( count( $this->tabs ) > 0 ) { |
|
| 113 | + if (count($this->tabs) > 0) { |
|
| 114 | 114 | $html = ''; |
| 115 | 115 | |
| 116 | - $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n"; |
|
| 116 | + $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n"; |
|
| 117 | 117 | |
| 118 | 118 | $sections = array( |
| 119 | - 'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' ) |
|
| 119 | + 'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab') |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - foreach ( $this->tabs as $k => $v ) { |
|
| 123 | - $sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' ); |
|
| 122 | + foreach ($this->tabs as $k => $v) { |
|
| 123 | + $sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $count = 1; |
| 127 | - foreach ( $sections as $k => $v ) { |
|
| 127 | + foreach ($sections as $k => $v) { |
|
| 128 | 128 | $count++; |
| 129 | - $html .= '<li><a href="' . $v['href'] . '"'; |
|
| 130 | - if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; } |
|
| 131 | - $html .= '>' . esc_attr( $v['name'] ) . '</a>'; |
|
| 132 | - if ( $count <= count( $sections ) ) { $html .= ' | '; } |
|
| 133 | - $html .= '</li>' . "\n"; |
|
| 129 | + $html .= '<li><a href="'.$v['href'].'"'; |
|
| 130 | + if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; } |
|
| 131 | + $html .= '>'.esc_attr($v['name']).'</a>'; |
|
| 132 | + if ($count <= count($sections)) { $html .= ' | '; } |
|
| 133 | + $html .= '</li>'."\n"; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $html .= '</ul><div class="clear"></div>' . "\n"; |
|
| 136 | + $html .= '</ul><div class="clear"></div>'."\n"; |
|
| 137 | 137 | |
| 138 | 138 | echo $html; |
| 139 | 139 | } |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | * @since 1.1.0 |
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | - private function create_tabs () { |
|
| 149 | - if ( count( $this->sections ) > 0 ) { |
|
| 148 | + private function create_tabs() { |
|
| 149 | + if (count($this->sections) > 0) { |
|
| 150 | 150 | $tabs = array(); |
| 151 | - foreach ( $this->sections as $k => $v ) { |
|
| 151 | + foreach ($this->sections as $k => $v) { |
|
| 152 | 152 | $tabs[$k] = $v; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | * @since 1.0.0 |
| 163 | 163 | * @return void |
| 164 | 164 | */ |
| 165 | - public function create_sections () { |
|
| 166 | - if ( count( $this->sections ) > 0 ) { |
|
| 167 | - foreach ( $this->sections as $k => $v ) { |
|
| 168 | - add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token ); |
|
| 165 | + public function create_sections() { |
|
| 166 | + if (count($this->sections) > 0) { |
|
| 167 | + foreach ($this->sections as $k => $v) { |
|
| 168 | + add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } // End create_sections() |
@@ -176,18 +176,18 @@ discard block |
||
| 176 | 176 | * @since 1.0.0 |
| 177 | 177 | * @return void |
| 178 | 178 | */ |
| 179 | - public function create_fields () { |
|
| 180 | - if ( count( $this->sections ) > 0 ) { |
|
| 179 | + public function create_fields() { |
|
| 180 | + if (count($this->sections) > 0) { |
|
| 181 | 181 | // $this->parse_fields( $this->fields ); |
| 182 | 182 | |
| 183 | - foreach ( $this->fields as $k => $v ) { |
|
| 184 | - $method = $this->determine_method( $v, 'form' ); |
|
| 183 | + foreach ($this->fields as $k => $v) { |
|
| 184 | + $method = $this->determine_method($v, 'form'); |
|
| 185 | 185 | $name = $v['name']; |
| 186 | - if ( $v['type'] == 'info' ) { $name = ''; } |
|
| 187 | - add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) ); |
|
| 186 | + if ($v['type'] == 'info') { $name = ''; } |
|
| 187 | + add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v)); |
|
| 188 | 188 | |
| 189 | 189 | // Let the API know that we have a colourpicker field. |
| 190 | - if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; } |
|
| 190 | + if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; } |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | } // End create_fields() |
@@ -199,43 +199,43 @@ discard block |
||
| 199 | 199 | * @param array $data |
| 200 | 200 | * @return callable, array or string |
| 201 | 201 | */ |
| 202 | - protected function determine_method ( $data, $type = 'form' ) { |
|
| 202 | + protected function determine_method($data, $type = 'form') { |
|
| 203 | 203 | $method = ''; |
| 204 | 204 | |
| 205 | - if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; } |
|
| 205 | + if ( ! in_array($type, array('form', 'validate', 'check'))) { return; } |
|
| 206 | 206 | |
| 207 | 207 | // Check for custom functions. |
| 208 | - if ( isset( $data[$type] ) ) { |
|
| 209 | - if ( function_exists( $data[$type] ) ) { |
|
| 208 | + if (isset($data[$type])) { |
|
| 209 | + if (function_exists($data[$type])) { |
|
| 210 | 210 | $method = $data[$type]; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( $method == '' && method_exists( $this, $data[$type] ) ) { |
|
| 214 | - if ( $type == 'form' ) { |
|
| 215 | - $method = array( $this, $data[$type] ); |
|
| 213 | + if ($method == '' && method_exists($this, $data[$type])) { |
|
| 214 | + if ($type == 'form') { |
|
| 215 | + $method = array($this, $data[$type]); |
|
| 216 | 216 | } else { |
| 217 | 217 | $method = $data[$type]; |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) { |
|
| 223 | - if ( $type == 'form' ) { |
|
| 224 | - $method = array( $this, $type . '_field_' . $data['type'] ); |
|
| 222 | + if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) { |
|
| 223 | + if ($type == 'form') { |
|
| 224 | + $method = array($this, $type.'_field_'.$data['type']); |
|
| 225 | 225 | } else { |
| 226 | - $method = $type . '_field_' . $data['type']; |
|
| 226 | + $method = $type.'_field_'.$data['type']; |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) { |
|
| 231 | - $method = $this->token . '_' . $type . '_field_' . $data['type']; |
|
| 230 | + if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) { |
|
| 231 | + $method = $this->token.'_'.$type.'_field_'.$data['type']; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if ( $method == '' ) { |
|
| 235 | - if ( $type == 'form' ) { |
|
| 236 | - $method = array( $this, $type . '_field_text' ); |
|
| 234 | + if ($method == '') { |
|
| 235 | + if ($type == 'form') { |
|
| 236 | + $method = array($this, $type.'_field_text'); |
|
| 237 | 237 | } else { |
| 238 | - $method = $type . '_field_text'; |
|
| 238 | + $method = $type.'_field_text'; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | * @param array $fields |
| 250 | 250 | * @return void |
| 251 | 251 | */ |
| 252 | - public function parse_fields ( $fields ) { |
|
| 253 | - foreach ( $fields as $k => $v ) { |
|
| 254 | - if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) { |
|
| 255 | - if ( ! isset( $this->sections[$v['section']]['fields'] ) ) { |
|
| 252 | + public function parse_fields($fields) { |
|
| 253 | + foreach ($fields as $k => $v) { |
|
| 254 | + if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) { |
|
| 255 | + if ( ! isset($this->sections[$v['section']]['fields'])) { |
|
| 256 | 256 | $this->sections[$v['section']]['fields'] = array(); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -269,19 +269,19 @@ discard block |
||
| 269 | 269 | * @since 1.0.0 |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | - public function register_settings_screen () { |
|
| 272 | + public function register_settings_screen() { |
|
| 273 | 273 | |
| 274 | - if ( current_user_can( 'manage_sensei' ) ) { |
|
| 275 | - $hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) ); |
|
| 274 | + if (current_user_can('manage_sensei')) { |
|
| 275 | + $hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen')); |
|
| 276 | 276 | |
| 277 | 277 | $this->hook = $hook; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
| 280 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
| 281 | 281 | |
| 282 | - add_action( 'admin_notices', array( $this, 'settings_errors' ) ); |
|
| 283 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 284 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
| 282 | + add_action('admin_notices', array($this, 'settings_errors')); |
|
| 283 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
| 284 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
| 285 | 285 | |
| 286 | 286 | } |
| 287 | 287 | } // End register_settings_screen() |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | * @since 1.0.0 |
| 293 | 293 | * @return void |
| 294 | 294 | */ |
| 295 | - public function settings_screen () |
|
| 295 | + public function settings_screen() |
|
| 296 | 296 | { |
| 297 | 297 | |
| 298 | 298 | ?> |
| 299 | 299 | <div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"> |
| 300 | 300 | <?php screen_icon('woothemes-sensei'); ?> |
| 301 | 301 | <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { |
| 302 | - echo ' <span class="version">' . $this->settings_version . '</span>'; |
|
| 302 | + echo ' <span class="version">'.$this->settings_version.'</span>'; |
|
| 303 | 303 | } ?></h2> |
| 304 | 304 | <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" |
| 305 | 305 | title="WooThemes"><img |
@@ -313,13 +313,13 @@ discard block |
||
| 313 | 313 | $page = 'woothemes-sensei-settings'; |
| 314 | 314 | foreach ($this->sections as $section_id => $section) { |
| 315 | 315 | |
| 316 | - echo '<section id="' . $section_id . '">'; |
|
| 316 | + echo '<section id="'.$section_id.'">'; |
|
| 317 | 317 | |
| 318 | 318 | if ($section['name']) |
| 319 | 319 | echo "<h2>{$section['name']}</h2>\n"; |
| 320 | 320 | |
| 321 | 321 | echo '<table class="form-table">'; |
| 322 | - do_settings_fields($page, $section_id ); |
|
| 322 | + do_settings_fields($page, $section_id); |
|
| 323 | 323 | echo '</table>'; |
| 324 | 324 | |
| 325 | 325 | echo '</section>'; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | submit_button(); |
| 330 | 330 | ?> |
| 331 | 331 | </form> |
| 332 | - <?php do_action( 'settings_after_form' ); ?> |
|
| 332 | + <?php do_action('settings_after_form'); ?> |
|
| 333 | 333 | </div><!--/#woothemes-sensei--> |
| 334 | 334 | <?php |
| 335 | 335 | } // End settings_screen() |
@@ -340,16 +340,16 @@ discard block |
||
| 340 | 340 | * @since 1.0.0 |
| 341 | 341 | * @return array |
| 342 | 342 | */ |
| 343 | - public function get_settings () { |
|
| 344 | - if ( ! is_array( $this->settings ) ) { |
|
| 345 | - $this->settings = get_option( $this->token, array() ); |
|
| 343 | + public function get_settings() { |
|
| 344 | + if ( ! is_array($this->settings)) { |
|
| 345 | + $this->settings = get_option($this->token, array()); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - foreach ( $this->fields as $k => $v ) { |
|
| 349 | - if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) { |
|
| 348 | + foreach ($this->fields as $k => $v) { |
|
| 349 | + if ( ! isset($this->settings[$k]) && isset($v['default'])) { |
|
| 350 | 350 | $this->settings[$k] = $v['default']; |
| 351 | 351 | } |
| 352 | - if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) { |
|
| 352 | + if ($v['type'] == 'checkbox' && $this->settings[$k] != true) { |
|
| 353 | 353 | $this->settings[$k] = 0; |
| 354 | 354 | } |
| 355 | 355 | } |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * @since 1.0.0 |
| 364 | 364 | * @return void |
| 365 | 365 | */ |
| 366 | - public function settings_fields () { |
|
| 367 | - register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) ); |
|
| 366 | + public function settings_fields() { |
|
| 367 | + register_setting($this->token, $this->token, array($this, 'validate_fields')); |
|
| 368 | 368 | $this->create_sections(); |
| 369 | 369 | $this->create_fields(); |
| 370 | 370 | } // End settings_fields() |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @since 1.0.0 |
| 376 | 376 | * @return void |
| 377 | 377 | */ |
| 378 | - public function settings_errors () { |
|
| 379 | - settings_errors( $this->token . '-errors' ); |
|
| 378 | + public function settings_errors() { |
|
| 379 | + settings_errors($this->token.'-errors'); |
|
| 380 | 380 | } // End settings_errors() |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -385,9 +385,9 @@ discard block |
||
| 385 | 385 | * @since 1.0.0 |
| 386 | 386 | * @return void |
| 387 | 387 | */ |
| 388 | - public function section_description ( $section ) { |
|
| 389 | - if ( isset( $this->sections[$section['id']]['description'] ) ) { |
|
| 390 | - echo wpautop( $this->sections[$section['id']]['description'] ); |
|
| 388 | + public function section_description($section) { |
|
| 389 | + if (isset($this->sections[$section['id']]['description'])) { |
|
| 390 | + echo wpautop($this->sections[$section['id']]['description']); |
|
| 391 | 391 | } |
| 392 | 392 | } // End section_description_main() |
| 393 | 393 | |
@@ -398,12 +398,12 @@ discard block |
||
| 398 | 398 | * @param array $args |
| 399 | 399 | * @return void |
| 400 | 400 | */ |
| 401 | - public function form_field_text ( $args ) { |
|
| 401 | + public function form_field_text($args) { |
|
| 402 | 402 | $options = $this->get_settings(); |
| 403 | 403 | |
| 404 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 405 | - if ( isset( $args['data']['description'] ) ) { |
|
| 406 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 404 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 405 | + if (isset($args['data']['description'])) { |
|
| 406 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 407 | 407 | } |
| 408 | 408 | } // End form_field_text() |
| 409 | 409 | |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | * @param array $args |
| 415 | 415 | * @return void |
| 416 | 416 | */ |
| 417 | - public function form_field_color ( $args ) { |
|
| 417 | + public function form_field_color($args) { |
|
| 418 | 418 | $options = $this->get_settings(); |
| 419 | 419 | |
| 420 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 420 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 421 | 421 | echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>'; |
| 422 | - if ( isset( $args['data']['description'] ) ) { |
|
| 423 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 422 | + if (isset($args['data']['description'])) { |
|
| 423 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 424 | 424 | } |
| 425 | 425 | } // End form_field_text() |
| 426 | 426 | |
@@ -431,22 +431,22 @@ discard block |
||
| 431 | 431 | * @param array $args |
| 432 | 432 | * @return void |
| 433 | 433 | */ |
| 434 | - public function form_field_checkbox ( $args ) { |
|
| 434 | + public function form_field_checkbox($args) { |
|
| 435 | 435 | $options = $this->get_settings(); |
| 436 | 436 | |
| 437 | 437 | $has_description = false; |
| 438 | - if ( isset( $args['data']['description'] ) ) { |
|
| 438 | + if (isset($args['data']['description'])) { |
|
| 439 | 439 | $has_description = true; |
| 440 | - echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n"; |
|
| 440 | + echo '<label for="'.esc_attr($args['key']).'">'."\n"; |
|
| 441 | 441 | } |
| 442 | - echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
|
| 443 | - if ( $has_description ) { |
|
| 444 | - echo wp_kses( $args['data']['description'], array( 'a' => array( |
|
| 442 | + echo '<input id="'.$args['key'].'" name="'.$this->token.'['.esc_attr($args['key']).']" type="checkbox" value="1"'.checked(esc_attr($options[$args['key']]), '1', false).' />'."\n"; |
|
| 443 | + if ($has_description) { |
|
| 444 | + echo wp_kses($args['data']['description'], array('a' => array( |
|
| 445 | 445 | 'href' => array(), |
| 446 | 446 | 'title' => array() |
| 447 | 447 | ) |
| 448 | 448 | ) |
| 449 | - ) . '</label>' . "\n"; |
|
| 449 | + ).'</label>'."\n"; |
|
| 450 | 450 | } |
| 451 | 451 | } // End form_field_checkbox() |
| 452 | 452 | |
@@ -457,12 +457,12 @@ discard block |
||
| 457 | 457 | * @param array $args |
| 458 | 458 | * @return void |
| 459 | 459 | */ |
| 460 | - public function form_field_textarea ( $args ) { |
|
| 460 | + public function form_field_textarea($args) { |
|
| 461 | 461 | $options = $this->get_settings(); |
| 462 | 462 | |
| 463 | - echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n"; |
|
| 464 | - if ( isset( $args['data']['description'] ) ) { |
|
| 465 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 463 | + echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n"; |
|
| 464 | + if (isset($args['data']['description'])) { |
|
| 465 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 466 | 466 | } |
| 467 | 467 | } // End form_field_textarea() |
| 468 | 468 | |
@@ -473,20 +473,20 @@ discard block |
||
| 473 | 473 | * @param array $args |
| 474 | 474 | * @return void |
| 475 | 475 | */ |
| 476 | - public function form_field_select ( $args ) { |
|
| 476 | + public function form_field_select($args) { |
|
| 477 | 477 | $options = $this->get_settings(); |
| 478 | 478 | |
| 479 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 479 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 480 | 480 | $html = ''; |
| 481 | - $html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n"; |
|
| 482 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 483 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 481 | + $html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n"; |
|
| 482 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 483 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 484 | 484 | } |
| 485 | - $html .= '</select>' . "\n"; |
|
| 485 | + $html .= '</select>'."\n"; |
|
| 486 | 486 | echo $html; |
| 487 | 487 | |
| 488 | - if ( isset( $args['data']['description'] ) ) { |
|
| 489 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 488 | + if (isset($args['data']['description'])) { |
|
| 489 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | } // End form_field_select() |
@@ -498,18 +498,18 @@ discard block |
||
| 498 | 498 | * @param array $args |
| 499 | 499 | * @return void |
| 500 | 500 | */ |
| 501 | - public function form_field_radio ( $args ) { |
|
| 501 | + public function form_field_radio($args) { |
|
| 502 | 502 | $options = $this->get_settings(); |
| 503 | 503 | |
| 504 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 504 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 505 | 505 | $html = ''; |
| 506 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 507 | - $html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 506 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 507 | + $html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 508 | 508 | } |
| 509 | 509 | echo $html; |
| 510 | 510 | |
| 511 | - if ( isset( $args['data']['description'] ) ) { |
|
| 512 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 511 | + if (isset($args['data']['description'])) { |
|
| 512 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | } // End form_field_radio() |
@@ -521,28 +521,28 @@ discard block |
||
| 521 | 521 | * @param array $args |
| 522 | 522 | * @return void |
| 523 | 523 | */ |
| 524 | - public function form_field_multicheck ( $args ) { |
|
| 524 | + public function form_field_multicheck($args) { |
|
| 525 | 525 | $options = $this->get_settings(); |
| 526 | 526 | |
| 527 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 528 | - $html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n"; |
|
| 529 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 527 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 528 | + $html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n"; |
|
| 529 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 530 | 530 | $checked = ''; |
| 531 | 531 | |
| 532 | - if( isset( $options[ $args['key'] ] ) ) { |
|
| 533 | - if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; } |
|
| 532 | + if (isset($options[$args['key']])) { |
|
| 533 | + if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; } |
|
| 534 | 534 | } else { |
| 535 | - if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; } |
|
| 535 | + if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; } |
|
| 536 | 536 | } |
| 537 | - $html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n"; |
|
| 538 | - $html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n"; |
|
| 539 | - $html .= '</label><br />' . "\n"; |
|
| 537 | + $html .= '<label for="checkbox-'.esc_attr($k).'">'."\n"; |
|
| 538 | + $html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n"; |
|
| 539 | + $html .= '</label><br />'."\n"; |
|
| 540 | 540 | } |
| 541 | - $html .= '</div>' . "\n"; |
|
| 541 | + $html .= '</div>'."\n"; |
|
| 542 | 542 | echo $html; |
| 543 | 543 | |
| 544 | - if ( isset( $args['data']['description'] ) ) { |
|
| 545 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 544 | + if (isset($args['data']['description'])) { |
|
| 545 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | } // End form_field_multicheck() |
@@ -554,20 +554,20 @@ discard block |
||
| 554 | 554 | * @param array $args |
| 555 | 555 | * @return void |
| 556 | 556 | */ |
| 557 | - public function form_field_range ( $args ) { |
|
| 557 | + public function form_field_range($args) { |
|
| 558 | 558 | $options = $this->get_settings(); |
| 559 | 559 | |
| 560 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 560 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 561 | 561 | $html = ''; |
| 562 | - $html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n"; |
|
| 563 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 564 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 562 | + $html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n"; |
|
| 563 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 564 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 565 | 565 | } |
| 566 | - $html .= '</select>' . "\n"; |
|
| 566 | + $html .= '</select>'."\n"; |
|
| 567 | 567 | echo $html; |
| 568 | 568 | |
| 569 | - if ( isset( $args['data']['description'] ) ) { |
|
| 570 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 569 | + if (isset($args['data']['description'])) { |
|
| 570 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | } // End form_field_range() |
@@ -579,18 +579,18 @@ discard block |
||
| 579 | 579 | * @param array $args |
| 580 | 580 | * @return void |
| 581 | 581 | */ |
| 582 | - public function form_field_images ( $args ) { |
|
| 582 | + public function form_field_images($args) { |
|
| 583 | 583 | $options = $this->get_settings(); |
| 584 | 584 | |
| 585 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 585 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 586 | 586 | $html = ''; |
| 587 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 588 | - $html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 587 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 588 | + $html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 589 | 589 | } |
| 590 | 590 | echo $html; |
| 591 | 591 | |
| 592 | - if ( isset( $args['data']['description'] ) ) { |
|
| 593 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 592 | + if (isset($args['data']['description'])) { |
|
| 593 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | } // End form_field_images() |
@@ -602,19 +602,19 @@ discard block |
||
| 602 | 602 | * @param array $args |
| 603 | 603 | * @return void |
| 604 | 604 | */ |
| 605 | - public function form_field_info ( $args ) { |
|
| 605 | + public function form_field_info($args) { |
|
| 606 | 606 | $class = ''; |
| 607 | - if ( isset( $args['data']['class'] ) ) { |
|
| 608 | - $class = ' ' . esc_attr( $args['data']['class'] ); |
|
| 607 | + if (isset($args['data']['class'])) { |
|
| 608 | + $class = ' '.esc_attr($args['data']['class']); |
|
| 609 | 609 | } |
| 610 | - $html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n"; |
|
| 611 | - if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) { |
|
| 612 | - $html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n"; |
|
| 610 | + $html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n"; |
|
| 611 | + if (isset($args['data']['name']) && ($args['data']['name'] != '')) { |
|
| 612 | + $html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n"; |
|
| 613 | 613 | } |
| 614 | - if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) { |
|
| 615 | - $html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n"; |
|
| 614 | + if (isset($args['data']['description']) && ($args['data']['description'] != '')) { |
|
| 615 | + $html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n"; |
|
| 616 | 616 | } |
| 617 | - $html .= '</div>' . "\n"; |
|
| 617 | + $html .= '</div>'."\n"; |
|
| 618 | 618 | |
| 619 | 619 | echo $html; |
| 620 | 620 | } // End form_field_info() |
@@ -626,14 +626,14 @@ discard block |
||
| 626 | 626 | * @since 1.9.0 |
| 627 | 627 | * @param array $args |
| 628 | 628 | */ |
| 629 | - public function form_field_button( $args ) { |
|
| 629 | + public function form_field_button($args) { |
|
| 630 | 630 | $options = $this->get_settings(); |
| 631 | 631 | |
| 632 | - if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) { |
|
| 633 | - printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) ); |
|
| 632 | + if (isset($args['data']['target']) && isset($args['data']['label'])) { |
|
| 633 | + printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label'])); |
|
| 634 | 634 | |
| 635 | - if ( isset( $args['data']['description'] ) ) { |
|
| 636 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 635 | + if (isset($args['data']['description'])) { |
|
| 636 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | } // End form_field_button() |
@@ -647,23 +647,23 @@ discard block |
||
| 647 | 647 | * @uses $this->parse_errors() |
| 648 | 648 | * @return array $options |
| 649 | 649 | */ |
| 650 | - public function validate_fields ( $input ) { |
|
| 650 | + public function validate_fields($input) { |
|
| 651 | 651 | $options = $this->get_settings(); |
| 652 | 652 | |
| 653 | - foreach ( $this->fields as $k => $v ) { |
|
| 653 | + foreach ($this->fields as $k => $v) { |
|
| 654 | 654 | // Make sure checkboxes are present even when false. |
| 655 | - if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 656 | - if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 655 | + if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 656 | + if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 657 | 657 | |
| 658 | - if ( isset( $input[$k] ) ) { |
|
| 658 | + if (isset($input[$k])) { |
|
| 659 | 659 | // Perform checks on required fields. |
| 660 | - if ( isset( $v['required'] ) && ( $v['required'] == true ) ) { |
|
| 661 | - if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) { |
|
| 662 | - $this->add_error( $k, $v ); |
|
| 660 | + if (isset($v['required']) && ($v['required'] == true)) { |
|
| 661 | + if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) { |
|
| 662 | + $this->add_error($k, $v); |
|
| 663 | 663 | continue; |
| 664 | 664 | } else { |
| 665 | - if ( $input[$k] == '' ) { |
|
| 666 | - $this->add_error( $k, $v ); |
|
| 665 | + if ($input[$k] == '') { |
|
| 666 | + $this->add_error($k, $v); |
|
| 667 | 667 | continue; |
| 668 | 668 | } |
| 669 | 669 | } |
@@ -672,28 +672,28 @@ discard block |
||
| 672 | 672 | $value = $input[$k]; |
| 673 | 673 | |
| 674 | 674 | // Check if the field is valid. |
| 675 | - $method = $this->determine_method( $v, 'check' ); |
|
| 675 | + $method = $this->determine_method($v, 'check'); |
|
| 676 | 676 | |
| 677 | - if ( function_exists ( $method ) ) { |
|
| 678 | - $is_valid = $method( $value ); |
|
| 677 | + if (function_exists($method)) { |
|
| 678 | + $is_valid = $method($value); |
|
| 679 | 679 | } else { |
| 680 | - if ( method_exists( $this, $method ) ) { |
|
| 681 | - $is_valid = $this->$method( $value ); |
|
| 680 | + if (method_exists($this, $method)) { |
|
| 681 | + $is_valid = $this->$method($value); |
|
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( ! $is_valid ) { |
|
| 686 | - $this->add_error( $k, $v ); |
|
| 685 | + if ( ! $is_valid) { |
|
| 686 | + $this->add_error($k, $v); |
|
| 687 | 687 | continue; |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - $method = $this->determine_method( $v, 'validate' ); |
|
| 690 | + $method = $this->determine_method($v, 'validate'); |
|
| 691 | 691 | |
| 692 | - if ( function_exists ( $method ) ) { |
|
| 693 | - $options[$k] = $method( $value ); |
|
| 692 | + if (function_exists($method)) { |
|
| 693 | + $options[$k] = $method($value); |
|
| 694 | 694 | } else { |
| 695 | - if ( method_exists( $this, $method ) ) { |
|
| 696 | - $options[$k] = $this->$method( $value ); |
|
| 695 | + if (method_exists($this, $method)) { |
|
| 696 | + $options[$k] = $this->$method($value); |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | } |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | * @param string $input |
| 712 | 712 | * @return string |
| 713 | 713 | */ |
| 714 | - public function validate_field_text ( $input ) { |
|
| 715 | - return trim( esc_attr( $input ) ); |
|
| 714 | + public function validate_field_text($input) { |
|
| 715 | + return trim(esc_attr($input)); |
|
| 716 | 716 | } // End validate_field_text() |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -722,11 +722,11 @@ discard block |
||
| 722 | 722 | * @param string $input |
| 723 | 723 | * @return string |
| 724 | 724 | */ |
| 725 | - public function validate_field_checkbox ( $input ) { |
|
| 726 | - if ( ! isset( $input ) ) { |
|
| 725 | + public function validate_field_checkbox($input) { |
|
| 726 | + if ( ! isset($input)) { |
|
| 727 | 727 | return 0; |
| 728 | 728 | } else { |
| 729 | - return (bool)$input; |
|
| 729 | + return (bool) $input; |
|
| 730 | 730 | } |
| 731 | 731 | } // End validate_field_checkbox() |
| 732 | 732 | |
@@ -737,10 +737,10 @@ discard block |
||
| 737 | 737 | * @param string $input |
| 738 | 738 | * @return string |
| 739 | 739 | */ |
| 740 | - public function validate_field_multicheck ( $input ) { |
|
| 740 | + public function validate_field_multicheck($input) { |
|
| 741 | 741 | $input = (array) $input; |
| 742 | 742 | |
| 743 | - $input = array_map( 'esc_attr', $input ); |
|
| 743 | + $input = array_map('esc_attr', $input); |
|
| 744 | 744 | |
| 745 | 745 | return $input; |
| 746 | 746 | } // End validate_field_multicheck() |
@@ -752,8 +752,8 @@ discard block |
||
| 752 | 752 | * @param string $input |
| 753 | 753 | * @return string |
| 754 | 754 | */ |
| 755 | - public function validate_field_range ( $input ) { |
|
| 756 | - $input = number_format( floatval( $input ), 0 ); |
|
| 755 | + public function validate_field_range($input) { |
|
| 756 | + $input = number_format(floatval($input), 0); |
|
| 757 | 757 | |
| 758 | 758 | return $input; |
| 759 | 759 | } // End validate_field_range() |
@@ -765,8 +765,8 @@ discard block |
||
| 765 | 765 | * @param string $input |
| 766 | 766 | * @return string |
| 767 | 767 | */ |
| 768 | - public function validate_field_url ( $input ) { |
|
| 769 | - return trim( esc_url( $input ) ); |
|
| 768 | + public function validate_field_url($input) { |
|
| 769 | + return trim(esc_url($input)); |
|
| 770 | 770 | } // End validate_field_url() |
| 771 | 771 | |
| 772 | 772 | /** |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | * @since 1.1.0 |
| 776 | 776 | * @return boolean Is the value valid? |
| 777 | 777 | */ |
| 778 | - public function check_field_text ( $input ) { |
|
| 778 | + public function check_field_text($input) { |
|
| 779 | 779 | $is_valid = true; |
| 780 | 780 | |
| 781 | 781 | return $is_valid; |
@@ -789,11 +789,11 @@ discard block |
||
| 789 | 789 | * @param array $data |
| 790 | 790 | * @return void |
| 791 | 791 | */ |
| 792 | - protected function add_error ( $key, $data ) { |
|
| 793 | - if ( isset( $data['error_message'] ) ) { |
|
| 792 | + protected function add_error($key, $data) { |
|
| 793 | + if (isset($data['error_message'])) { |
|
| 794 | 794 | $message = $data['error_message']; |
| 795 | 795 | } else { |
| 796 | - $message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] ); |
|
| 796 | + $message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']); |
|
| 797 | 797 | } |
| 798 | 798 | $this->errors[$key] = $message; |
| 799 | 799 | } // End add_error() |
@@ -804,14 +804,14 @@ discard block |
||
| 804 | 804 | * @since 1.0.0 |
| 805 | 805 | * @return void |
| 806 | 806 | */ |
| 807 | - protected function parse_errors () { |
|
| 808 | - if ( count ( $this->errors ) > 0 ) { |
|
| 809 | - foreach ( $this->errors as $k => $v ) { |
|
| 810 | - add_settings_error( $this->token . '-errors', $k, $v, 'error' ); |
|
| 807 | + protected function parse_errors() { |
|
| 808 | + if (count($this->errors) > 0) { |
|
| 809 | + foreach ($this->errors as $k => $v) { |
|
| 810 | + add_settings_error($this->token.'-errors', $k, $v, 'error'); |
|
| 811 | 811 | } |
| 812 | 812 | } else { |
| 813 | - $message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name ); |
|
| 814 | - add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' ); |
|
| 813 | + $message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name); |
|
| 814 | + add_settings_error($this->token.'-errors', $this->token, $message, 'updated'); |
|
| 815 | 815 | } |
| 816 | 816 | } // End parse_errors() |
| 817 | 817 | |
@@ -821,8 +821,8 @@ discard block |
||
| 821 | 821 | * @since 1.0.0 |
| 822 | 822 | * @return array |
| 823 | 823 | */ |
| 824 | - protected function get_array_field_types () { |
|
| 825 | - return array( 'multicheck' ); |
|
| 824 | + protected function get_array_field_types() { |
|
| 825 | + return array('multicheck'); |
|
| 826 | 826 | } // End get_array_field_types() |
| 827 | 827 | |
| 828 | 828 | /** |
@@ -831,21 +831,21 @@ discard block |
||
| 831 | 831 | * @since 1.0.0 |
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | - public function enqueue_scripts () { |
|
| 834 | + public function enqueue_scripts() { |
|
| 835 | 835 | |
| 836 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 836 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 837 | 837 | |
| 838 | - wp_enqueue_script( 'farbtastic' ); |
|
| 839 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version ); |
|
| 838 | + wp_enqueue_script('farbtastic'); |
|
| 839 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version); |
|
| 840 | 840 | |
| 841 | - if ( $this->has_range ) { |
|
| 842 | - wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version ); |
|
| 841 | + if ($this->has_range) { |
|
| 842 | + wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version ); |
|
| 845 | + wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version); |
|
| 846 | 846 | |
| 847 | - if ( $this->has_imageselector ) { |
|
| 848 | - wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' ); |
|
| 847 | + if ($this->has_imageselector) { |
|
| 848 | + wp_enqueue_script('woothemes-sensei-settings-imageselectors'); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | } // End enqueue_scripts() |
@@ -856,12 +856,12 @@ discard block |
||
| 856 | 856 | * @since 1.0.0 |
| 857 | 857 | * @return void |
| 858 | 858 | */ |
| 859 | - public function enqueue_styles () { |
|
| 859 | + public function enqueue_styles() { |
|
| 860 | 860 | |
| 861 | - wp_enqueue_style( $this->token . '-admin' ); |
|
| 861 | + wp_enqueue_style($this->token.'-admin'); |
|
| 862 | 862 | |
| 863 | - wp_enqueue_style( 'farbtastic' ); |
|
| 864 | - wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version ); |
|
| 863 | + wp_enqueue_style('farbtastic'); |
|
| 864 | + wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version); |
|
| 865 | 865 | |
| 866 | 866 | $this->enqueue_field_styles(); |
| 867 | 867 | } // End enqueue_styles() |
@@ -872,16 +872,16 @@ discard block |
||
| 872 | 872 | * @since 1.0.0 |
| 873 | 873 | * @return void |
| 874 | 874 | */ |
| 875 | - public function enqueue_field_styles () { |
|
| 875 | + public function enqueue_field_styles() { |
|
| 876 | 876 | |
| 877 | - if ( $this->has_range ) { |
|
| 878 | - wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version ); |
|
| 877 | + if ($this->has_range) { |
|
| 878 | + wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version ); |
|
| 881 | + wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version); |
|
| 882 | 882 | |
| 883 | - if ( $this->has_imageselector ) { |
|
| 884 | - wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' ); |
|
| 883 | + if ($this->has_imageselector) { |
|
| 884 | + wp_enqueue_style('woothemes-sensei-settings-imageselectors'); |
|
| 885 | 885 | } |
| 886 | 886 | } // End enqueue_field_styles() |
| 887 | 887 | } // End Class |
@@ -891,4 +891,4 @@ discard block |
||
| 891 | 891 | * @ignore only for backward compatibility |
| 892 | 892 | * @since 1.9.0 |
| 893 | 893 | */ |
| 894 | -class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{} |
|
| 894 | +class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {} |
|