|
1 <?php |
|
2 |
|
3 if ( ! class_exists('NHP_Options') ){ |
|
4 |
|
5 |
|
6 |
|
7 // windows-proof constants: replace backward by forward slashes - thanks to: https://github.com/peterbouwmeester |
|
8 |
|
9 $fslashed_dir = trailingslashit(str_replace('\\','/',dirname(__FILE__))); |
|
10 |
|
11 $fslashed_abs = trailingslashit(str_replace('\\','/',ABSPATH)); |
|
12 |
|
13 |
|
14 |
|
15 if(!defined('NHP_OPTIONS_DIR')){ |
|
16 |
|
17 define('NHP_OPTIONS_DIR', $fslashed_dir); |
|
18 |
|
19 } |
|
20 |
|
21 |
|
22 |
|
23 if(!defined('NHP_OPTIONS_URL')){ |
|
24 |
|
25 define('NHP_OPTIONS_URL', site_url(str_replace( $fslashed_abs, '', $fslashed_dir ))); |
|
26 |
|
27 } |
|
28 |
|
29 |
|
30 |
|
31 class NHP_Options{ |
|
32 |
|
33 |
|
34 |
|
35 protected $framework_url = 'http://leemason.github.com/NHP-Theme-Options-Framework/'; |
|
36 |
|
37 protected $framework_version = '1.0.6'; |
|
38 |
|
39 |
|
40 |
|
41 public $dir = NHP_OPTIONS_DIR; |
|
42 |
|
43 public $url = NHP_OPTIONS_URL; |
|
44 |
|
45 public $page = ''; |
|
46 |
|
47 public $args = array(); |
|
48 |
|
49 public $sections = array(); |
|
50 |
|
51 public $extra_tabs = array(); |
|
52 |
|
53 public $errors = array(); |
|
54 |
|
55 public $warnings = array(); |
|
56 |
|
57 public $options = array(); |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 /** |
|
66 |
|
67 * Class Constructor. Defines the args for the theme options class |
|
68 |
|
69 * |
|
70 |
|
71 * @since NHP_Options 1.0 |
|
72 |
|
73 * |
|
74 |
|
75 * @param $array $args Arguments. Class constructor arguments. |
|
76 |
|
77 */ |
|
78 |
|
79 function __construct($sections = array(), $args = array(), $extra_tabs = array()){ |
|
80 |
|
81 |
|
82 |
|
83 $defaults = array(); |
|
84 |
|
85 |
|
86 |
|
87 $defaults['opt_name'] = '';//must be defined by theme/plugin |
|
88 |
|
89 |
|
90 |
|
91 $defaults['google_api_key'] = '';//must be defined for use with google webfonts field type |
|
92 |
|
93 |
|
94 |
|
95 $defaults['menu_icon'] = NHP_OPTIONS_URL.'/img/menu_icon.png'; |
|
96 |
|
97 $defaults['menu_title'] = __('Options', 'nhp-opts'); |
|
98 |
|
99 $defaults['page_icon'] = 'icon-themes'; |
|
100 |
|
101 $defaults['page_title'] = __('Options', 'nhp-opts'); |
|
102 |
|
103 $defaults['page_slug'] = '_options'; |
|
104 |
|
105 $defaults['page_cap'] = 'manage_options'; |
|
106 |
|
107 $defaults['page_type'] = 'menu'; |
|
108 |
|
109 $defaults['page_parent'] = ''; |
|
110 |
|
111 $defaults['page_position'] = 100; |
|
112 |
|
113 $defaults['allow_sub_menu'] = true; |
|
114 |
|
115 |
|
116 |
|
117 $defaults['show_import_export'] = true; |
|
118 |
|
119 $defaults['dev_mode'] = true; |
|
120 |
|
121 $defaults['stylesheet_override'] = false; |
|
122 |
|
123 |
|
124 |
|
125 $defaults['footer_credit'] = __('<span id="footer-thankyou">Options Panel created using the <a href="'.$this->framework_url.'" target="_blank">NHP Theme Options Framework</a> Version '.$this->framework_version.'</span>', 'nhp-opts'); |
|
126 |
|
127 |
|
128 |
|
129 $defaults['help_tabs'] = array(); |
|
130 |
|
131 $defaults['help_sidebar'] = __('', 'nhp-opts'); |
|
132 |
|
133 |
|
134 |
|
135 //get args |
|
136 |
|
137 $this->args = wp_parse_args($args, $defaults); |
|
138 |
|
139 $this->args = apply_filters('nhp-opts-args-'.$this->args['opt_name'], $this->args); |
|
140 |
|
141 |
|
142 |
|
143 //get sections |
|
144 |
|
145 $this->sections = apply_filters('nhp-opts-sections-'.$this->args['opt_name'], $sections); |
|
146 |
|
147 |
|
148 |
|
149 //get extra tabs |
|
150 |
|
151 $this->extra_tabs = apply_filters('nhp-opts-extra-tabs-'.$this->args['opt_name'], $extra_tabs); |
|
152 |
|
153 |
|
154 |
|
155 //set option with defaults |
|
156 |
|
157 add_action('init', array(&$this, '_set_default_options')); |
|
158 |
|
159 |
|
160 |
|
161 //options page |
|
162 |
|
163 add_action('admin_menu', array(&$this, '_options_page')); |
|
164 |
|
165 |
|
166 |
|
167 //register setting |
|
168 |
|
169 add_action('admin_init', array(&$this, '_register_setting')); |
|
170 |
|
171 |
|
172 |
|
173 //add the js for the error handling before the form |
|
174 |
|
175 add_action('nhp-opts-page-before-form-'.$this->args['opt_name'], array(&$this, '_errors_js'), 1); |
|
176 |
|
177 |
|
178 |
|
179 //add the js for the warning handling before the form |
|
180 |
|
181 add_action('nhp-opts-page-before-form-'.$this->args['opt_name'], array(&$this, '_warnings_js'), 2); |
|
182 |
|
183 |
|
184 |
|
185 //hook into the wp feeds for downloading the exported settings |
|
186 |
|
187 add_action('do_feed_nhpopts-'.$this->args['opt_name'], array(&$this, '_download_options'), 1, 1); |
|
188 |
|
189 |
|
190 |
|
191 //get the options for use later on |
|
192 |
|
193 $this->options = get_option($this->args['opt_name']); |
|
194 |
|
195 |
|
196 |
|
197 }//function |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 /** |
|
204 |
|
205 * ->get(); This is used to return and option value from the options array |
|
206 |
|
207 * |
|
208 |
|
209 * @since NHP_Options 1.0.1 |
|
210 |
|
211 * |
|
212 |
|
213 * @param $array $args Arguments. Class constructor arguments. |
|
214 |
|
215 */ |
|
216 |
|
217 function get($opt_name, $default = null){ |
|
218 |
|
219 return (!empty($this->options[$opt_name])) ? $this->options[$opt_name] : $default; |
|
220 |
|
221 }//function |
|
222 |
|
223 |
|
224 |
|
225 /** |
|
226 |
|
227 * ->set(); This is used to set an arbitrary option in the options array |
|
228 |
|
229 * |
|
230 |
|
231 * @since NHP_Options 1.0.1 |
|
232 |
|
233 * |
|
234 |
|
235 * @param string $opt_name the name of the option being added |
|
236 |
|
237 * @param mixed $value the value of the option being added |
|
238 |
|
239 */ |
|
240 |
|
241 function set($opt_name = '', $value = '') { |
|
242 |
|
243 if($opt_name != ''){ |
|
244 |
|
245 $this->options[$opt_name] = $value; |
|
246 |
|
247 update_option($this->args['opt_name'], $this->options); |
|
248 |
|
249 }//if |
|
250 |
|
251 } |
|
252 |
|
253 |
|
254 |
|
255 /** |
|
256 |
|
257 * ->show(); This is used to echo and option value from the options array |
|
258 |
|
259 * |
|
260 |
|
261 * @since NHP_Options 1.0.1 |
|
262 |
|
263 * |
|
264 |
|
265 * @param $array $args Arguments. Class constructor arguments. |
|
266 |
|
267 */ |
|
268 |
|
269 function show($opt_name, $default = ''){ |
|
270 |
|
271 $option = $this->get($opt_name); |
|
272 |
|
273 if(!is_array($option) && $option != ''){ |
|
274 |
|
275 echo $option; |
|
276 |
|
277 }elseif($default != ''){ |
|
278 |
|
279 echo $default; |
|
280 |
|
281 } |
|
282 |
|
283 }//function |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 /** |
|
292 |
|
293 * Get default options into an array suitable for the settings API |
|
294 |
|
295 * |
|
296 |
|
297 * @since NHP_Options 1.0 |
|
298 |
|
299 * |
|
300 |
|
301 */ |
|
302 |
|
303 function _default_values(){ |
|
304 |
|
305 |
|
306 |
|
307 $defaults = array(); |
|
308 |
|
309 |
|
310 |
|
311 foreach($this->sections as $k => $section){ |
|
312 |
|
313 |
|
314 |
|
315 if(isset($section['fields'])){ |
|
316 |
|
317 |
|
318 |
|
319 foreach($section['fields'] as $fieldk => $field){ |
|
320 |
|
321 |
|
322 |
|
323 if(!isset($field['std'])){$field['std'] = '';} |
|
324 |
|
325 |
|
326 |
|
327 $defaults[$field['id']] = $field['std']; |
|
328 |
|
329 |
|
330 |
|
331 }//foreach |
|
332 |
|
333 |
|
334 |
|
335 }//if |
|
336 |
|
337 |
|
338 |
|
339 }//foreach |
|
340 |
|
341 |
|
342 |
|
343 //fix for notice on first page load |
|
344 |
|
345 $defaults['last_tab'] = 0; |
|
346 |
|
347 |
|
348 |
|
349 return $defaults; |
|
350 |
|
351 |
|
352 |
|
353 } |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 /** |
|
362 |
|
363 * Set default options on admin_init if option doesnt exist (theme activation hook caused problems, so admin_init it is) |
|
364 |
|
365 * |
|
366 |
|
367 * @since NHP_Options 1.0 |
|
368 |
|
369 * |
|
370 |
|
371 */ |
|
372 |
|
373 function _set_default_options(){ |
|
374 |
|
375 if(!get_option($this->args['opt_name'])){ |
|
376 |
|
377 add_option($this->args['opt_name'], $this->_default_values()); |
|
378 |
|
379 } |
|
380 |
|
381 $this->options = get_option($this->args['opt_name']); |
|
382 |
|
383 }//function |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 /** |
|
390 |
|
391 * Class Theme Options Page Function, creates main options page. |
|
392 |
|
393 * |
|
394 |
|
395 * @since NHP_Options 1.0 |
|
396 |
|
397 */ |
|
398 |
|
399 function _options_page(){ |
|
400 |
|
401 if($this->args['page_type'] == 'submenu'){ |
|
402 |
|
403 if(!isset($this->args['page_parent']) || empty($this->args['page_parent'])){ |
|
404 |
|
405 $this->args['page_parent'] = 'themes.php'; |
|
406 |
|
407 } |
|
408 |
|
409 $this->page = add_submenu_page( |
|
410 |
|
411 $this->args['page_parent'], |
|
412 |
|
413 $this->args['page_title'], |
|
414 |
|
415 $this->args['menu_title'], |
|
416 |
|
417 $this->args['page_cap'], |
|
418 |
|
419 $this->args['page_slug'], |
|
420 |
|
421 array(&$this, '_options_page_html') |
|
422 |
|
423 ); |
|
424 |
|
425 }else{ |
|
426 |
|
427 $this->page = add_menu_page( |
|
428 |
|
429 $this->args['page_title'], |
|
430 |
|
431 $this->args['menu_title'], |
|
432 |
|
433 $this->args['page_cap'], |
|
434 |
|
435 $this->args['page_slug'], |
|
436 |
|
437 array(&$this, '_options_page_html'), |
|
438 |
|
439 $this->args['menu_icon'], |
|
440 |
|
441 $this->args['page_position'] |
|
442 |
|
443 ); |
|
444 |
|
445 |
|
446 |
|
447 if(true === $this->args['allow_sub_menu']){ |
|
448 |
|
449 |
|
450 |
|
451 //this is needed to remove the top level menu item from showing in the submenu |
|
452 |
|
453 add_submenu_page($this->args['page_slug'],$this->args['page_title'],'',$this->args['page_cap'],$this->args['page_slug'],create_function( '$a', "return null;" )); |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 foreach($this->sections as $k => $section){ |
|
460 |
|
461 |
|
462 |
|
463 add_submenu_page( |
|
464 |
|
465 $this->args['page_slug'], |
|
466 |
|
467 $section['title'], |
|
468 |
|
469 $section['title'], |
|
470 |
|
471 $this->args['page_cap'], |
|
472 |
|
473 $this->args['page_slug'].'&tab='.$k, |
|
474 |
|
475 create_function( '$a', "return null;" ) |
|
476 |
|
477 ); |
|
478 |
|
479 |
|
480 |
|
481 } |
|
482 |
|
483 |
|
484 |
|
485 if(true === $this->args['show_import_export']){ |
|
486 |
|
487 |
|
488 |
|
489 add_submenu_page( |
|
490 |
|
491 $this->args['page_slug'], |
|
492 |
|
493 __('Import / Export', 'nhp-opts'), |
|
494 |
|
495 __('Import / Export', 'nhp-opts'), |
|
496 |
|
497 $this->args['page_cap'], |
|
498 |
|
499 $this->args['page_slug'].'&tab=import_export_default', |
|
500 |
|
501 create_function( '$a', "return null;" ) |
|
502 |
|
503 ); |
|
504 |
|
505 |
|
506 |
|
507 }//if |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 foreach($this->extra_tabs as $k => $tab){ |
|
514 |
|
515 |
|
516 |
|
517 add_submenu_page( |
|
518 |
|
519 $this->args['page_slug'], |
|
520 |
|
521 $tab['title'], |
|
522 |
|
523 $tab['title'], |
|
524 |
|
525 $this->args['page_cap'], |
|
526 |
|
527 $this->args['page_slug'].'&tab='.$k, |
|
528 |
|
529 create_function( '$a', "return null;" ) |
|
530 |
|
531 ); |
|
532 |
|
533 |
|
534 |
|
535 } |
|
536 |
|
537 |
|
538 |
|
539 if(true === $this->args['dev_mode']){ |
|
540 |
|
541 |
|
542 |
|
543 add_submenu_page( |
|
544 |
|
545 $this->args['page_slug'], |
|
546 |
|
547 __('Dev Mode Info', 'nhp-opts'), |
|
548 |
|
549 __('Dev Mode Info', 'nhp-opts'), |
|
550 |
|
551 $this->args['page_cap'], |
|
552 |
|
553 $this->args['page_slug'].'&tab=dev_mode_default', |
|
554 |
|
555 create_function( '$a', "return null;" ) |
|
556 |
|
557 ); |
|
558 |
|
559 |
|
560 |
|
561 }//if |
|
562 |
|
563 |
|
564 |
|
565 }//if |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 }//else |
|
572 |
|
573 |
|
574 |
|
575 add_action('admin_print_styles-'.$this->page, array(&$this, '_enqueue')); |
|
576 |
|
577 add_action('load-'.$this->page, array(&$this, '_load_page')); |
|
578 |
|
579 }//function |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 /** |
|
588 |
|
589 * enqueue styles/js for theme page |
|
590 |
|
591 * |
|
592 |
|
593 * @since NHP_Options 1.0 |
|
594 |
|
595 */ |
|
596 |
|
597 function _enqueue(){ |
|
598 |
|
599 |
|
600 |
|
601 wp_register_style( |
|
602 |
|
603 'nhp-opts-css', |
|
604 |
|
605 $this->url.'css/options.css', |
|
606 |
|
607 array('farbtastic'), |
|
608 |
|
609 time(), |
|
610 |
|
611 'all' |
|
612 |
|
613 ); |
|
614 |
|
615 |
|
616 |
|
617 wp_register_style( |
|
618 |
|
619 'nhp-opts-jquery-ui-css', |
|
620 |
|
621 apply_filters('nhp-opts-ui-theme', $this->url.'css/jquery-ui-aristo/aristo.css'), |
|
622 |
|
623 '', |
|
624 |
|
625 time(), |
|
626 |
|
627 'all' |
|
628 |
|
629 ); |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 if(false === $this->args['stylesheet_override']){ |
|
636 |
|
637 wp_enqueue_style('nhp-opts-css'); |
|
638 |
|
639 } |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 wp_enqueue_script( |
|
646 |
|
647 'nhp-opts-js', |
|
648 |
|
649 $this->url.'js/options.js', |
|
650 |
|
651 array('jquery'), |
|
652 |
|
653 time(), |
|
654 |
|
655 true |
|
656 |
|
657 ); |
|
658 |
|
659 wp_localize_script('nhp-opts-js', 'nhp_opts', array('reset_confirm' => __('Are you sure? Resetting will loose all custom values.', 'nhp-opts'), 'opt_name' => $this->args['opt_name'])); |
|
660 |
|
661 |
|
662 |
|
663 do_action('nhp-opts-enqueue-'.$this->args['opt_name']); |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 foreach($this->sections as $k => $section){ |
|
670 |
|
671 |
|
672 |
|
673 if(isset($section['fields'])){ |
|
674 |
|
675 |
|
676 |
|
677 foreach($section['fields'] as $fieldk => $field){ |
|
678 |
|
679 |
|
680 |
|
681 if(isset($field['type'])){ |
|
682 |
|
683 |
|
684 |
|
685 $field_class = 'NHP_Options_'.$field['type']; |
|
686 |
|
687 |
|
688 |
|
689 if(!class_exists($field_class)){ |
|
690 |
|
691 require_once($this->dir.'fields/'.$field['type'].'/field_'.$field['type'].'.php'); |
|
692 |
|
693 }//if |
|
694 |
|
695 |
|
696 |
|
697 if(class_exists($field_class) && method_exists($field_class, 'enqueue')){ |
|
698 |
|
699 $enqueue = new $field_class('','',$this); |
|
700 |
|
701 $enqueue->enqueue(); |
|
702 |
|
703 }//if |
|
704 |
|
705 |
|
706 |
|
707 }//if type |
|
708 |
|
709 |
|
710 |
|
711 }//foreach |
|
712 |
|
713 |
|
714 |
|
715 }//if fields |
|
716 |
|
717 |
|
718 |
|
719 }//foreach |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 }//function |
|
726 |
|
727 |
|
728 |
|
729 /** |
|
730 |
|
731 * Download the options file, or display it |
|
732 |
|
733 * |
|
734 |
|
735 * @since NHP_Options 1.0.1 |
|
736 |
|
737 */ |
|
738 |
|
739 function _download_options(){ |
|
740 |
|
741 //-'.$this->args['opt_name'] |
|
742 |
|
743 if(!isset($_GET['secret']) || $_GET['secret'] != md5(AUTH_KEY.SECURE_AUTH_KEY)){wp_die('Invalid Secret for options use');exit;} |
|
744 |
|
745 if(!isset($_GET['feed'])){wp_die('No Feed Defined');exit;} |
|
746 |
|
747 $backup_options = get_option(str_replace('nhpopts-','',$_GET['feed'])); |
|
748 |
|
749 $backup_options['nhp-opts-backup'] = '1'; |
|
750 |
|
751 $content = '###'.serialize($backup_options).'###'; |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 if(isset($_GET['action']) && $_GET['action'] == 'download_options'){ |
|
758 |
|
759 header('Content-Description: File Transfer'); |
|
760 |
|
761 header('Content-type: application/txt'); |
|
762 |
|
763 header('Content-Disposition: attachment; filename="'.str_replace('nhpopts-','',$_GET['feed']).'_options_'.date('d-m-Y').'.txt"'); |
|
764 |
|
765 header('Content-Transfer-Encoding: binary'); |
|
766 |
|
767 header('Expires: 0'); |
|
768 |
|
769 header('Cache-Control: must-revalidate'); |
|
770 |
|
771 header('Pragma: public'); |
|
772 |
|
773 echo $content; |
|
774 |
|
775 exit; |
|
776 |
|
777 }else{ |
|
778 |
|
779 echo $content; |
|
780 |
|
781 exit; |
|
782 |
|
783 } |
|
784 |
|
785 } |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 /** |
|
796 |
|
797 * show page help |
|
798 |
|
799 * |
|
800 |
|
801 * @since NHP_Options 1.0 |
|
802 |
|
803 */ |
|
804 |
|
805 function _load_page(){ |
|
806 |
|
807 |
|
808 |
|
809 //do admin head action for this page |
|
810 |
|
811 add_action('admin_head', array(&$this, 'admin_head')); |
|
812 |
|
813 |
|
814 |
|
815 //do admin footer text hook |
|
816 |
|
817 add_filter('admin_footer_text', array(&$this, 'admin_footer_text')); |
|
818 |
|
819 |
|
820 |
|
821 $screen = get_current_screen(); |
|
822 |
|
823 |
|
824 |
|
825 if(is_array($this->args['help_tabs'])){ |
|
826 |
|
827 foreach($this->args['help_tabs'] as $tab){ |
|
828 |
|
829 $screen->add_help_tab($tab); |
|
830 |
|
831 }//foreach |
|
832 |
|
833 }//if |
|
834 |
|
835 |
|
836 |
|
837 if($this->args['help_sidebar'] != ''){ |
|
838 |
|
839 $screen->set_help_sidebar($this->args['help_sidebar']); |
|
840 |
|
841 }//if |
|
842 |
|
843 |
|
844 |
|
845 do_action('nhp-opts-load-page-'.$this->args['opt_name'], $screen); |
|
846 |
|
847 |
|
848 |
|
849 }//function |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 /** |
|
856 |
|
857 * do action nhp-opts-admin-head for theme options page |
|
858 |
|
859 * |
|
860 |
|
861 * @since NHP_Options 1.0 |
|
862 |
|
863 */ |
|
864 |
|
865 function admin_head(){ |
|
866 |
|
867 |
|
868 |
|
869 do_action('nhp-opts-admin-head-'.$this->args['opt_name'], $this); |
|
870 |
|
871 |
|
872 |
|
873 }//function |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 function admin_footer_text($footer_text){ |
|
880 |
|
881 return $this->args['footer_credit']; |
|
882 |
|
883 }//function |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 /** |
|
894 |
|
895 * Register Option for use |
|
896 |
|
897 * |
|
898 |
|
899 * @since NHP_Options 1.0 |
|
900 |
|
901 */ |
|
902 |
|
903 function _register_setting(){ |
|
904 |
|
905 |
|
906 |
|
907 register_setting($this->args['opt_name'].'_group', $this->args['opt_name'], array(&$this,'_validate_options')); |
|
908 |
|
909 |
|
910 |
|
911 foreach($this->sections as $k => $section){ |
|
912 |
|
913 |
|
914 |
|
915 add_settings_section($k.'_section', $section['title'], array(&$this, '_section_desc'), $k.'_section_group'); |
|
916 |
|
917 |
|
918 |
|
919 if(isset($section['fields'])){ |
|
920 |
|
921 |
|
922 |
|
923 foreach($section['fields'] as $fieldk => $field){ |
|
924 |
|
925 |
|
926 |
|
927 if(isset($field['title'])){ |
|
928 |
|
929 |
|
930 |
|
931 $th = (isset($field['sub_desc']))?$field['title'].'<span class="description">'.$field['sub_desc'].'</span>':$field['title']; |
|
932 |
|
933 }else{ |
|
934 |
|
935 $th = ''; |
|
936 |
|
937 } |
|
938 |
|
939 |
|
940 |
|
941 add_settings_field($fieldk.'_field', $th, array(&$this,'_field_input'), $k.'_section_group', $k.'_section', $field); // checkbox |
|
942 |
|
943 |
|
944 |
|
945 }//foreach |
|
946 |
|
947 |
|
948 |
|
949 }//if(isset($section['fields'])){ |
|
950 |
|
951 |
|
952 |
|
953 }//foreach |
|
954 |
|
955 |
|
956 |
|
957 do_action('nhp-opts-register-settings-'.$this->args['opt_name']); |
|
958 |
|
959 |
|
960 |
|
961 }//function |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 /** |
|
970 |
|
971 * Validate the Options options before insertion |
|
972 |
|
973 * |
|
974 |
|
975 * @since NHP_Options 1.0 |
|
976 |
|
977 */ |
|
978 |
|
979 function _validate_options($plugin_options){ |
|
980 |
|
981 |
|
982 |
|
983 set_transient('nhp-opts-saved', '1', 1000 ); |
|
984 |
|
985 |
|
986 |
|
987 if(!empty($plugin_options['import'])){ |
|
988 |
|
989 |
|
990 |
|
991 if($plugin_options['import_code'] != ''){ |
|
992 |
|
993 $import = $plugin_options['import_code']; |
|
994 |
|
995 }elseif($plugin_options['import_link'] != ''){ |
|
996 |
|
997 $import = wp_remote_retrieve_body( wp_remote_get($plugin_options['import_link']) ); |
|
998 |
|
999 } |
|
1000 |
|
1001 |
|
1002 |
|
1003 $imported_options = unserialize(trim($import,'###')); |
|
1004 |
|
1005 if(is_array($imported_options) && isset($imported_options['nhp-opts-backup']) && $imported_options['nhp-opts-backup'] == '1'){ |
|
1006 |
|
1007 $imported_options['imported'] = 1; |
|
1008 |
|
1009 return $imported_options; |
|
1010 |
|
1011 } |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 } |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 if(!empty($plugin_options['defaults'])){ |
|
1024 |
|
1025 $plugin_options = $this->_default_values(); |
|
1026 |
|
1027 return $plugin_options; |
|
1028 |
|
1029 }//if set defaults |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 //validate fields (if needed) |
|
1036 |
|
1037 $plugin_options = $this->_validate_values($plugin_options, $this->options); |
|
1038 |
|
1039 |
|
1040 |
|
1041 if($this->errors){ |
|
1042 |
|
1043 set_transient('nhp-opts-errors-'.$this->args['opt_name'], $this->errors, 1000 ); |
|
1044 |
|
1045 }//if errors |
|
1046 |
|
1047 |
|
1048 |
|
1049 if($this->warnings){ |
|
1050 |
|
1051 set_transient('nhp-opts-warnings-'.$this->args['opt_name'], $this->warnings, 1000 ); |
|
1052 |
|
1053 }//if errors |
|
1054 |
|
1055 |
|
1056 |
|
1057 do_action('nhp-opts-options-validate-'.$this->args['opt_name'], $plugin_options, $this->options); |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 unset($plugin_options['defaults']); |
|
1064 |
|
1065 unset($plugin_options['import']); |
|
1066 |
|
1067 unset($plugin_options['import_code']); |
|
1068 |
|
1069 unset($plugin_options['import_link']); |
|
1070 |
|
1071 |
|
1072 |
|
1073 return $plugin_options; |
|
1074 |
|
1075 |
|
1076 |
|
1077 }//function |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 /** |
|
1088 |
|
1089 * Validate values from options form (used in settings api validate function) |
|
1090 |
|
1091 * calls the custom validation class for the field so authors can override with custom classes |
|
1092 |
|
1093 * |
|
1094 |
|
1095 * @since NHP_Options 1.0 |
|
1096 |
|
1097 */ |
|
1098 |
|
1099 function _validate_values($plugin_options, $options){ |
|
1100 |
|
1101 foreach($this->sections as $k => $section){ |
|
1102 |
|
1103 |
|
1104 |
|
1105 if(isset($section['fields'])){ |
|
1106 |
|
1107 |
|
1108 |
|
1109 foreach($section['fields'] as $fieldk => $field){ |
|
1110 |
|
1111 $field['section_id'] = $k; |
|
1112 |
|
1113 |
|
1114 |
|
1115 if(isset($field['type']) && $field['type'] == 'multi_text'){continue;}//we cant validate this yet |
|
1116 |
|
1117 |
|
1118 |
|
1119 if(!isset($plugin_options[$field['id']]) || $plugin_options[$field['id']] == ''){ |
|
1120 |
|
1121 continue; |
|
1122 |
|
1123 } |
|
1124 |
|
1125 |
|
1126 |
|
1127 //force validate of custom filed types |
|
1128 |
|
1129 |
|
1130 |
|
1131 if(isset($field['type']) && !isset($field['validate'])){ |
|
1132 |
|
1133 if($field['type'] == 'color' || $field['type'] == 'color_gradient'){ |
|
1134 |
|
1135 $field['validate'] = 'color'; |
|
1136 |
|
1137 }elseif($field['type'] == 'date'){ |
|
1138 |
|
1139 $field['validate'] = 'date'; |
|
1140 |
|
1141 } |
|
1142 |
|
1143 }//if |
|
1144 |
|
1145 |
|
1146 |
|
1147 if(isset($field['validate'])){ |
|
1148 |
|
1149 $validate = 'NHP_Validation_'.$field['validate']; |
|
1150 |
|
1151 |
|
1152 |
|
1153 if(!class_exists($validate)){ |
|
1154 |
|
1155 require_once($this->dir.'validation/'.$field['validate'].'/validation_'.$field['validate'].'.php'); |
|
1156 |
|
1157 }//if |
|
1158 |
|
1159 |
|
1160 |
|
1161 if(class_exists($validate)){ |
|
1162 |
|
1163 $validation = new $validate($field, $plugin_options[$field['id']], $options[$field['id']]); |
|
1164 |
|
1165 $plugin_options[$field['id']] = $validation->value; |
|
1166 |
|
1167 if(isset($validation->error)){ |
|
1168 |
|
1169 $this->errors[] = $validation->error; |
|
1170 |
|
1171 } |
|
1172 |
|
1173 if(isset($validation->warning)){ |
|
1174 |
|
1175 $this->warnings[] = $validation->warning; |
|
1176 |
|
1177 } |
|
1178 |
|
1179 continue; |
|
1180 |
|
1181 }//if |
|
1182 |
|
1183 }//if |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 if(isset($field['validate_callback']) && function_exists($field['validate_callback'])){ |
|
1190 |
|
1191 |
|
1192 |
|
1193 $callbackvalues = call_user_func($field['validate_callback'], $field, $plugin_options[$field['id']], $options[$field['id']]); |
|
1194 |
|
1195 $plugin_options[$field['id']] = $callbackvalues['value']; |
|
1196 |
|
1197 if(isset($callbackvalues['error'])){ |
|
1198 |
|
1199 $this->errors[] = $callbackvalues['error']; |
|
1200 |
|
1201 }//if |
|
1202 |
|
1203 if(isset($callbackvalues['warning'])){ |
|
1204 |
|
1205 $this->warnings[] = $callbackvalues['warning']; |
|
1206 |
|
1207 }//if |
|
1208 |
|
1209 |
|
1210 |
|
1211 }//if |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 }//foreach |
|
1218 |
|
1219 |
|
1220 |
|
1221 }//if(isset($section['fields'])){ |
|
1222 |
|
1223 |
|
1224 |
|
1225 }//foreach |
|
1226 |
|
1227 return $plugin_options; |
|
1228 |
|
1229 }//function |
|
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 /** |
|
1248 |
|
1249 * HTML OUTPUT. |
|
1250 |
|
1251 * |
|
1252 |
|
1253 * @since NHP_Options 1.0 |
|
1254 |
|
1255 */ |
|
1256 |
|
1257 function _options_page_html(){ |
|
1258 |
|
1259 |
|
1260 |
|
1261 echo '<div class="wrap">'; |
|
1262 |
|
1263 echo '<div id="'.$this->args['page_icon'].'" class="icon32"><br/></div>'; |
|
1264 |
|
1265 echo '<h2 id="nhp-opts-heading">'.get_admin_page_title().'</h2>'; |
|
1266 |
|
1267 echo (isset($this->args['intro_text']))?$this->args['intro_text']:''; |
|
1268 |
|
1269 |
|
1270 |
|
1271 do_action('nhp-opts-page-before-form-'.$this->args['opt_name']); |
|
1272 |
|
1273 |
|
1274 |
|
1275 echo '<form method="post" action="options.php" enctype="multipart/form-data" id="nhp-opts-form-wrapper">'; |
|
1276 |
|
1277 settings_fields($this->args['opt_name'].'_group'); |
|
1278 |
|
1279 |
|
1280 |
|
1281 $this->options['last_tab'] = (isset($_GET['tab']) && !get_transient('nhp-opts-saved'))?$_GET['tab']:$this->options['last_tab']; |
|
1282 |
|
1283 |
|
1284 |
|
1285 echo '<input type="hidden" id="last_tab" name="'.$this->args['opt_name'].'[last_tab]" value="'.$this->options['last_tab'].'" />'; |
|
1286 |
|
1287 |
|
1288 |
|
1289 echo '<div id="nhp-opts-header">'; |
|
1290 |
|
1291 submit_button('', 'primary', '', false); |
|
1292 |
|
1293 submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'].'[defaults]', false); |
|
1294 |
|
1295 echo '<div class="clear"></div><!--clearfix-->'; |
|
1296 |
|
1297 echo '</div>'; |
|
1298 |
|
1299 |
|
1300 |
|
1301 if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-saved') == '1'){ |
|
1302 |
|
1303 if(isset($this->options['imported']) && $this->options['imported'] == 1){ |
|
1304 |
|
1305 echo '<div id="nhp-opts-imported">'.apply_filters('nhp-opts-imported-text-'.$this->args['opt_name'], __('<strong>Settings Imported!</strong>', 'nhp-opts')).'</div>'; |
|
1306 |
|
1307 }else{ |
|
1308 |
|
1309 echo '<div id="nhp-opts-save">'.apply_filters('nhp-opts-saved-text-'.$this->args['opt_name'], __('<strong>Settings Saved!</strong>', 'nhp-opts')).'</div>'; |
|
1310 |
|
1311 } |
|
1312 |
|
1313 delete_transient('nhp-opts-saved'); |
|
1314 |
|
1315 } |
|
1316 |
|
1317 echo '<div id="nhp-opts-save-warn">'.apply_filters('nhp-opts-changed-text-'.$this->args['opt_name'], __('<strong>Settings have changed!, you should save them!</strong>', 'nhp-opts')).'</div>'; |
|
1318 |
|
1319 echo '<div id="nhp-opts-field-errors">'.__('<strong><span></span> error(s) were found!</strong>', 'nhp-opts').'</div>'; |
|
1320 |
|
1321 |
|
1322 |
|
1323 echo '<div id="nhp-opts-field-warnings">'.__('<strong><span></span> warning(s) were found!</strong>', 'nhp-opts').'</div>'; |
|
1324 |
|
1325 |
|
1326 |
|
1327 echo '<div class="clear"></div><!--clearfix-->'; |
|
1328 |
|
1329 |
|
1330 |
|
1331 echo '<div id="nhp-opts-sidebar">'; |
|
1332 |
|
1333 echo '<ul id="nhp-opts-group-menu">'; |
|
1334 |
|
1335 foreach($this->sections as $k => $section){ |
|
1336 |
|
1337 $icon = (!isset($section['icon']))?'<img src="'.$this->url.'img/glyphicons/glyphicons_019_cogwheel.png" /> ':'<img src="'.$section['icon'].'" /> '; |
|
1338 |
|
1339 echo '<li id="'.$k.'_section_group_li" class="nhp-opts-group-tab-link-li">'; |
|
1340 |
|
1341 echo '<a href="javascript:void(0);" id="'.$k.'_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="'.$k.'">'.$icon.'<span>'.$section['title'].'</span></a>'; |
|
1342 |
|
1343 echo '</li>'; |
|
1344 |
|
1345 } |
|
1346 |
|
1347 |
|
1348 |
|
1349 echo '<li class="divide"> </li>'; |
|
1350 |
|
1351 |
|
1352 |
|
1353 do_action('nhp-opts-after-section-menu-items-'.$this->args['opt_name'], $this); |
|
1354 |
|
1355 |
|
1356 |
|
1357 if(true === $this->args['show_import_export']){ |
|
1358 |
|
1359 echo '<li id="import_export_default_section_group_li" class="nhp-opts-group-tab-link-li">'; |
|
1360 |
|
1361 echo '<a href="javascript:void(0);" id="import_export_default_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="import_export_default"><img src="'.$this->url.'img/glyphicons/glyphicons_082_roundabout.png" /> <span>'.__('Import / Export', 'nhp-opts').'</span></a>'; |
|
1362 |
|
1363 echo '</li>'; |
|
1364 |
|
1365 echo '<li class="divide"> </li>'; |
|
1366 |
|
1367 }//if |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 foreach($this->extra_tabs as $k => $tab){ |
|
1380 |
|
1381 $icon = (!isset($tab['icon']))?'<img src="'.$this->url.'img/glyphicons/glyphicons_019_cogwheel.png" /> ':'<img src="'.$tab['icon'].'" /> '; |
|
1382 |
|
1383 echo '<li id="'.$k.'_section_group_li" class="nhp-opts-group-tab-link-li">'; |
|
1384 |
|
1385 echo '<a href="javascript:void(0);" id="'.$k.'_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="'.$k.'">'.$icon.'<span>'.$tab['title'].'</span></a>'; |
|
1386 |
|
1387 echo '</li>'; |
|
1388 |
|
1389 } |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 if(true === $this->args['dev_mode']){ |
|
1396 |
|
1397 echo '<li id="dev_mode_default_section_group_li" class="nhp-opts-group-tab-link-li">'; |
|
1398 |
|
1399 echo '<a href="javascript:void(0);" id="dev_mode_default_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="dev_mode_default"><img src="'.$this->url.'img/glyphicons/glyphicons_195_circle_info.png" /> <span>'.__('Dev Mode Info', 'nhp-opts').'</span></a>'; |
|
1400 |
|
1401 echo '</li>'; |
|
1402 |
|
1403 }//if |
|
1404 |
|
1405 |
|
1406 |
|
1407 echo '</ul>'; |
|
1408 |
|
1409 echo '</div>'; |
|
1410 |
|
1411 |
|
1412 |
|
1413 echo '<div id="nhp-opts-main">'; |
|
1414 |
|
1415 |
|
1416 |
|
1417 foreach($this->sections as $k => $section){ |
|
1418 |
|
1419 echo '<div id="'.$k.'_section_group'.'" class="nhp-opts-group-tab">'; |
|
1420 |
|
1421 do_settings_sections($k.'_section_group'); |
|
1422 |
|
1423 echo '</div>'; |
|
1424 |
|
1425 } |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 if(true === $this->args['show_import_export']){ |
|
1432 |
|
1433 echo '<div id="import_export_default_section_group'.'" class="nhp-opts-group-tab">'; |
|
1434 |
|
1435 echo '<h3>'.__('Import / Export Options', 'nhp-opts').'</h3>'; |
|
1436 |
|
1437 |
|
1438 |
|
1439 echo '<h4>'.__('Import Options', 'nhp-opts').'</h4>'; |
|
1440 |
|
1441 |
|
1442 |
|
1443 echo '<p><a href="javascript:void(0);" id="nhp-opts-import-code-button" class="button-secondary">Import from file</a> <a href="javascript:void(0);" id="nhp-opts-import-link-button" class="button-secondary">Import from URL</a></p>'; |
|
1444 |
|
1445 |
|
1446 |
|
1447 echo '<div id="nhp-opts-import-code-wrapper">'; |
|
1448 |
|
1449 |
|
1450 |
|
1451 echo '<div class="nhp-opts-section-desc">'; |
|
1452 |
|
1453 |
|
1454 |
|
1455 echo '<p class="description" id="import-code-description">'.apply_filters('nhp-opts-import-file-description',__('Input your backup file below and hit Import to restore your sites options from a backup.', 'nhp-opts')).'</p>'; |
|
1456 |
|
1457 |
|
1458 |
|
1459 echo '</div>'; |
|
1460 |
|
1461 |
|
1462 |
|
1463 echo '<textarea id="import-code-value" name="'.$this->args['opt_name'].'[import_code]" class="large-text" rows="8"></textarea>'; |
|
1464 |
|
1465 |
|
1466 |
|
1467 echo '</div>'; |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 echo '<div id="nhp-opts-import-link-wrapper">'; |
|
1474 |
|
1475 |
|
1476 |
|
1477 echo '<div class="nhp-opts-section-desc">'; |
|
1478 |
|
1479 |
|
1480 |
|
1481 echo '<p class="description" id="import-link-description">'.apply_filters('nhp-opts-import-link-description',__('Input the URL to another sites options set and hit Import to load the options from that site.', 'nhp-opts')).'</p>'; |
|
1482 |
|
1483 |
|
1484 |
|
1485 echo '</div>'; |
|
1486 |
|
1487 |
|
1488 |
|
1489 echo '<input type="text" id="import-link-value" name="'.$this->args['opt_name'].'[import_link]" class="large-text" value="" />'; |
|
1490 |
|
1491 |
|
1492 |
|
1493 echo '</div>'; |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 echo '<p id="nhp-opts-import-action"><input type="submit" id="nhp-opts-import" name="'.$this->args['opt_name'].'[import]" class="button-primary" value="'.__('Import', 'nhp-opts').'"> <span>'.apply_filters('nhp-opts-import-warning', __('WARNING! This will overwrite any existing options, please proceed with caution!', 'nhp-opts')).'</span></p>'; |
|
1502 |
|
1503 echo '<div id="import_divide"></div>'; |
|
1504 |
|
1505 |
|
1506 |
|
1507 echo '<h4>'.__('Export Options', 'nhp-opts').'</h4>'; |
|
1508 |
|
1509 echo '<div class="nhp-opts-section-desc">'; |
|
1510 |
|
1511 echo '<p class="description">'.apply_filters('nhp-opts-backup-description', __('Here you can copy/download your themes current option settings. Keep this safe as you can use it as a backup should anything go wrong. Or you can use it to restore your settings on this site (or any other site). You also have the handy option to copy the link to yours sites settings. Which you can then use to duplicate on another site', 'nhp-opts')).'</p>'; |
|
1512 |
|
1513 echo '</div>'; |
|
1514 |
|
1515 |
|
1516 |
|
1517 echo '<p><a href="javascript:void(0);" id="nhp-opts-export-code-copy" class="button-secondary">Copy</a> <a href="'.add_query_arg(array('feed' => 'nhpopts-'.$this->args['opt_name'], 'action' => 'download_options', 'secret' => md5(AUTH_KEY.SECURE_AUTH_KEY)), site_url()).'" id="nhp-opts-export-code-dl" class="button-primary">Download</a> <a href="javascript:void(0);" id="nhp-opts-export-link" class="button-secondary">Copy Link</a></p>'; |
|
1518 |
|
1519 $backup_options = $this->options; |
|
1520 |
|
1521 $backup_options['nhp-opts-backup'] = '1'; |
|
1522 |
|
1523 $encoded_options = '###'.serialize($backup_options).'###'; |
|
1524 |
|
1525 echo '<textarea class="large-text" id="nhp-opts-export-code" rows="8">';print_r($encoded_options);echo '</textarea>'; |
|
1526 |
|
1527 echo '<input type="text" class="large-text" id="nhp-opts-export-link-value" value="'.add_query_arg(array('feed' => 'nhpopts-'.$this->args['opt_name'], 'secret' => md5(AUTH_KEY.SECURE_AUTH_KEY)), site_url()).'" />'; |
|
1528 |
|
1529 |
|
1530 |
|
1531 echo '</div>'; |
|
1532 |
|
1533 } |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 foreach($this->extra_tabs as $k => $tab){ |
|
1542 |
|
1543 echo '<div id="'.$k.'_section_group'.'" class="nhp-opts-group-tab">'; |
|
1544 |
|
1545 echo '<h3>'.$tab['title'].'</h3>'; |
|
1546 |
|
1547 echo $tab['content']; |
|
1548 |
|
1549 echo '</div>'; |
|
1550 |
|
1551 } |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 if(true === $this->args['dev_mode']){ |
|
1560 |
|
1561 echo '<div id="dev_mode_default_section_group'.'" class="nhp-opts-group-tab">'; |
|
1562 |
|
1563 echo '<h3>'.__('Dev Mode Info', 'nhp-opts').'</h3>'; |
|
1564 |
|
1565 echo '<div class="nhp-opts-section-desc">'; |
|
1566 |
|
1567 echo '<textarea class="large-text" rows="24">'.print_r($this, true).'</textarea>'; |
|
1568 |
|
1569 echo '</div>'; |
|
1570 |
|
1571 echo '</div>'; |
|
1572 |
|
1573 } |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 do_action('nhp-opts-after-section-items-'.$this->args['opt_name'], $this); |
|
1580 |
|
1581 |
|
1582 |
|
1583 echo '<div class="clear"></div><!--clearfix-->'; |
|
1584 |
|
1585 echo '</div>'; |
|
1586 |
|
1587 echo '<div class="clear"></div><!--clearfix-->'; |
|
1588 |
|
1589 |
|
1590 |
|
1591 echo '<div id="nhp-opts-footer">'; |
|
1592 |
|
1593 |
|
1594 |
|
1595 if(isset($this->args['share_icons'])){ |
|
1596 |
|
1597 echo '<div id="nhp-opts-share">'; |
|
1598 |
|
1599 foreach($this->args['share_icons'] as $link){ |
|
1600 |
|
1601 echo '<a href="'.$link['link'].'" title="'.$link['title'].'" target="_blank"><img src="'.$link['img'].'"/></a>'; |
|
1602 |
|
1603 } |
|
1604 |
|
1605 echo '</div>'; |
|
1606 |
|
1607 } |
|
1608 |
|
1609 |
|
1610 |
|
1611 submit_button('', 'primary', '', false); |
|
1612 |
|
1613 submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'].'[defaults]', false); |
|
1614 |
|
1615 echo '<div class="clear"></div><!--clearfix-->'; |
|
1616 |
|
1617 echo '</div>'; |
|
1618 |
|
1619 |
|
1620 |
|
1621 echo '</form>'; |
|
1622 |
|
1623 |
|
1624 |
|
1625 do_action('nhp-opts-page-after-form-'.$this->args['opt_name']); |
|
1626 |
|
1627 |
|
1628 |
|
1629 echo '<div class="clear"></div><!--clearfix-->'; |
|
1630 |
|
1631 echo '</div><!--wrap-->'; |
|
1632 |
|
1633 |
|
1634 |
|
1635 }//function |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 /** |
|
1644 |
|
1645 * JS to display the errors on the page |
|
1646 |
|
1647 * |
|
1648 |
|
1649 * @since NHP_Options 1.0 |
|
1650 |
|
1651 */ |
|
1652 |
|
1653 function _errors_js(){ |
|
1654 |
|
1655 |
|
1656 |
|
1657 if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-errors-'.$this->args['opt_name'])){ |
|
1658 |
|
1659 $errors = get_transient('nhp-opts-errors-'.$this->args['opt_name']); |
|
1660 |
|
1661 $section_errors = array(); |
|
1662 |
|
1663 foreach($errors as $error){ |
|
1664 |
|
1665 $section_errors[$error['section_id']] = (isset($section_errors[$error['section_id']]))?$section_errors[$error['section_id']]:0; |
|
1666 |
|
1667 $section_errors[$error['section_id']]++; |
|
1668 |
|
1669 } |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 echo '<script type="text/javascript">'; |
|
1676 |
|
1677 echo 'jQuery(document).ready(function(){'; |
|
1678 |
|
1679 echo 'jQuery("#nhp-opts-field-errors span").html("'.count($errors).'");'; |
|
1680 |
|
1681 echo 'jQuery("#nhp-opts-field-errors").show();'; |
|
1682 |
|
1683 |
|
1684 |
|
1685 foreach($section_errors as $sectionkey => $section_error){ |
|
1686 |
|
1687 echo 'jQuery("#'.$sectionkey.'_section_group_li_a").append("<span class=\"nhp-opts-menu-error\">'.$section_error.'</span>");'; |
|
1688 |
|
1689 } |
|
1690 |
|
1691 |
|
1692 |
|
1693 foreach($errors as $error){ |
|
1694 |
|
1695 echo 'jQuery("#'.$error['id'].'").addClass("nhp-opts-field-error");'; |
|
1696 |
|
1697 echo 'jQuery("#'.$error['id'].'").closest("td").append("<span class=\"nhp-opts-th-error\">'.$error['msg'].'</span>");'; |
|
1698 |
|
1699 } |
|
1700 |
|
1701 echo '});'; |
|
1702 |
|
1703 echo '</script>'; |
|
1704 |
|
1705 delete_transient('nhp-opts-errors-'.$this->args['opt_name']); |
|
1706 |
|
1707 } |
|
1708 |
|
1709 |
|
1710 |
|
1711 }//function |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 /** |
|
1720 |
|
1721 * JS to display the warnings on the page |
|
1722 |
|
1723 * |
|
1724 |
|
1725 * @since NHP_Options 1.0.3 |
|
1726 |
|
1727 */ |
|
1728 |
|
1729 function _warnings_js(){ |
|
1730 |
|
1731 |
|
1732 |
|
1733 if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-warnings-'.$this->args['opt_name'])){ |
|
1734 |
|
1735 $warnings = get_transient('nhp-opts-warnings-'.$this->args['opt_name']); |
|
1736 |
|
1737 $section_warnings = array(); |
|
1738 |
|
1739 foreach($warnings as $warning){ |
|
1740 |
|
1741 $section_warnings[$warning['section_id']] = (isset($section_warnings[$warning['section_id']]))?$section_warnings[$warning['section_id']]:0; |
|
1742 |
|
1743 $section_warnings[$warning['section_id']]++; |
|
1744 |
|
1745 } |
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 echo '<script type="text/javascript">'; |
|
1752 |
|
1753 echo 'jQuery(document).ready(function(){'; |
|
1754 |
|
1755 echo 'jQuery("#nhp-opts-field-warnings span").html("'.count($warnings).'");'; |
|
1756 |
|
1757 echo 'jQuery("#nhp-opts-field-warnings").show();'; |
|
1758 |
|
1759 |
|
1760 |
|
1761 foreach($section_warnings as $sectionkey => $section_warning){ |
|
1762 |
|
1763 echo 'jQuery("#'.$sectionkey.'_section_group_li_a").append("<span class=\"nhp-opts-menu-warning\">'.$section_warning.'</span>");'; |
|
1764 |
|
1765 } |
|
1766 |
|
1767 |
|
1768 |
|
1769 foreach($warnings as $warning){ |
|
1770 |
|
1771 echo 'jQuery("#'.$warning['id'].'").addClass("nhp-opts-field-warning");'; |
|
1772 |
|
1773 echo 'jQuery("#'.$warning['id'].'").closest("td").append("<span class=\"nhp-opts-th-warning\">'.$warning['msg'].'</span>");'; |
|
1774 |
|
1775 } |
|
1776 |
|
1777 echo '});'; |
|
1778 |
|
1779 echo '</script>'; |
|
1780 |
|
1781 delete_transient('nhp-opts-warnings-'.$this->args['opt_name']); |
|
1782 |
|
1783 } |
|
1784 |
|
1785 |
|
1786 |
|
1787 }//function |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 /** |
|
1800 |
|
1801 * Section HTML OUTPUT. |
|
1802 |
|
1803 * |
|
1804 |
|
1805 * @since NHP_Options 1.0 |
|
1806 |
|
1807 */ |
|
1808 |
|
1809 function _section_desc($section){ |
|
1810 |
|
1811 |
|
1812 |
|
1813 $id = rtrim($section['id'], '_section'); |
|
1814 |
|
1815 |
|
1816 |
|
1817 if(isset($this->sections[$id]['desc']) && !empty($this->sections[$id]['desc'])) { |
|
1818 |
|
1819 echo '<div class="nhp-opts-section-desc">'.$this->sections[$id]['desc'].'</div>'; |
|
1820 |
|
1821 } |
|
1822 |
|
1823 |
|
1824 |
|
1825 }//function |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 /** |
|
1836 |
|
1837 * Field HTML OUTPUT. |
|
1838 |
|
1839 * |
|
1840 |
|
1841 * Gets option from options array, then calls the speicfic field type class - allows extending by other devs |
|
1842 |
|
1843 * |
|
1844 |
|
1845 * @since NHP_Options 1.0 |
|
1846 |
|
1847 */ |
|
1848 |
|
1849 function _field_input($field){ |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 if(isset($field['callback']) && function_exists($field['callback'])){ |
|
1856 |
|
1857 $value = (isset($this->options[$field['id']]))?$this->options[$field['id']]:''; |
|
1858 |
|
1859 do_action('nhp-opts-before-field-'.$this->args['opt_name'], $field, $value); |
|
1860 |
|
1861 call_user_func($field['callback'], $field, $value); |
|
1862 |
|
1863 do_action('nhp-opts-after-field-'.$this->args['opt_name'], $field, $value); |
|
1864 |
|
1865 return; |
|
1866 |
|
1867 } |
|
1868 |
|
1869 |
|
1870 |
|
1871 if(isset($field['type'])){ |
|
1872 |
|
1873 |
|
1874 |
|
1875 $field_class = 'NHP_Options_'.$field['type']; |
|
1876 |
|
1877 |
|
1878 |
|
1879 if(class_exists($field_class)){ |
|
1880 |
|
1881 require_once($this->dir.'fields/'.$field['type'].'/field_'.$field['type'].'.php'); |
|
1882 |
|
1883 }//if |
|
1884 |
|
1885 |
|
1886 |
|
1887 if(class_exists($field_class)){ |
|
1888 |
|
1889 $value = (isset($this->options[$field['id']]))?$this->options[$field['id']]:''; |
|
1890 |
|
1891 do_action('nhp-opts-before-field-'.$this->args['opt_name'], $field, $value); |
|
1892 |
|
1893 $render = ''; |
|
1894 |
|
1895 $render = new $field_class($field, $value, $this); |
|
1896 |
|
1897 $render->render(); |
|
1898 |
|
1899 do_action('nhp-opts-after-field-'.$this->args['opt_name'], $field, $value); |
|
1900 |
|
1901 }//if |
|
1902 |
|
1903 |
|
1904 |
|
1905 }//if $field['type'] |
|
1906 |
|
1907 |
|
1908 |
|
1909 }//function |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 }//class |
|
1916 |
|
1917 }//if |
|
1918 |
|
1919 ?> |