|
1 <?php if ( ! defined( 'OT_VERSION') ) exit( 'No direct script access allowed' ); |
|
2 /** |
|
3 * OptionTree Settings API |
|
4 * |
|
5 * This class loads all the methods and helpers specific to a Settings page. |
|
6 * |
|
7 * @package OptionTree |
|
8 * @author Derek Herman <derek@valendesigns.com> |
|
9 * @copyright Copyright (c) 2012, Derek Herman |
|
10 */ |
|
11 if ( ! class_exists( 'OT_Settings' ) ) { |
|
12 |
|
13 class OT_Settings { |
|
14 |
|
15 /* the options array */ |
|
16 private $options; |
|
17 |
|
18 /* hooks for targeting admin pages */ |
|
19 private $page_hook; |
|
20 |
|
21 /** |
|
22 * Constructor |
|
23 * |
|
24 * @param array An array of options |
|
25 * @return void |
|
26 * |
|
27 * @access public |
|
28 * @since 2.0 |
|
29 */ |
|
30 public function __construct( $args ) { |
|
31 |
|
32 $this->options = $args; |
|
33 |
|
34 /* return early if not viewing an admin page or no options */ |
|
35 if ( ! is_admin() || ! is_array( $this->options ) ) |
|
36 return false; |
|
37 |
|
38 /* load everything */ |
|
39 $this->hooks(); |
|
40 |
|
41 } |
|
42 |
|
43 /** |
|
44 * Execute the WordPress Hooks |
|
45 * |
|
46 * @return void |
|
47 * |
|
48 * @access public |
|
49 * @since 2.0 |
|
50 */ |
|
51 public function hooks() { |
|
52 |
|
53 /* add pages & menu items */ |
|
54 add_action( 'admin_menu', array( &$this, 'add_page' ) ); |
|
55 |
|
56 /* register sections */ |
|
57 add_action( 'admin_init', array( &$this, 'add_sections' ) ); |
|
58 |
|
59 /* register settings */ |
|
60 add_action( 'admin_init', array( &$this, 'add_settings' ) ); |
|
61 |
|
62 /* reset options */ |
|
63 add_action( 'admin_init', array( &$this, 'reset_options' ), 10 ); |
|
64 |
|
65 /* initialize settings */ |
|
66 add_action( 'admin_init', array( &$this, 'initialize_settings' ), 11 ); |
|
67 |
|
68 } |
|
69 |
|
70 /** |
|
71 * Loads each admin page |
|
72 * |
|
73 * @return void |
|
74 * |
|
75 * @access public |
|
76 * @since 2.0 |
|
77 */ |
|
78 public function add_page() { |
|
79 |
|
80 /* loop through options */ |
|
81 foreach( (array) $this->options as $option ) { |
|
82 |
|
83 /* loop through pages */ |
|
84 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
85 |
|
86 /* load page in WP top level menu */ |
|
87 if ( ! isset( $page['parent_slug'] ) || empty( $page['parent_slug'] ) ) { |
|
88 $page_hook = add_menu_page( |
|
89 $page['page_title'], |
|
90 $page['menu_title'], |
|
91 $page['capability'], |
|
92 $page['menu_slug'], |
|
93 array( &$this, 'display_page' ), |
|
94 $page['icon_url'], |
|
95 $page['position'] |
|
96 ); |
|
97 /* load page in WP sub menu */ |
|
98 } else { |
|
99 $page_hook = add_submenu_page( |
|
100 $page['parent_slug'], |
|
101 $page['page_title'], |
|
102 $page['menu_title'], |
|
103 $page['capability'], |
|
104 $page['menu_slug'], |
|
105 array( &$this, 'display_page' ) |
|
106 ); |
|
107 } |
|
108 |
|
109 /* only load if not a hidden page */ |
|
110 if ( ! isset( $page['hidden_page'] ) ) { |
|
111 |
|
112 /* associate $page_hook with page id */ |
|
113 $this->page_hook[$page['id']] = $page_hook; |
|
114 |
|
115 /* add scripts */ |
|
116 add_action( 'admin_print_scripts-' . $page_hook, array( &$this, 'scripts' ) ); |
|
117 |
|
118 /* add styles */ |
|
119 add_action( 'admin_print_styles-' . $page_hook, array( &$this, 'styles' ) ); |
|
120 |
|
121 /* add contextual help */ |
|
122 add_action( 'load-' . $page_hook, array( &$this, 'help' ) ); |
|
123 |
|
124 } |
|
125 |
|
126 } |
|
127 |
|
128 } |
|
129 |
|
130 return false; |
|
131 } |
|
132 |
|
133 /** |
|
134 * Loads the scripts |
|
135 * |
|
136 * @return void |
|
137 * |
|
138 * @access public |
|
139 * @since 2.0 |
|
140 */ |
|
141 public function scripts() { |
|
142 ot_admin_scripts(); |
|
143 } |
|
144 |
|
145 /** |
|
146 * Loads the styles |
|
147 * |
|
148 * @return void |
|
149 * |
|
150 * @access public |
|
151 * @since 2.0 |
|
152 */ |
|
153 public function styles() { |
|
154 ot_admin_styles(); |
|
155 } |
|
156 |
|
157 /** |
|
158 * Loads the contextual help for each page |
|
159 * |
|
160 * @return void |
|
161 * |
|
162 * @access public |
|
163 * @since 2.0 |
|
164 */ |
|
165 public function help() { |
|
166 $screen = get_current_screen(); |
|
167 |
|
168 /* loop through options */ |
|
169 foreach( (array) $this->options as $option ) { |
|
170 |
|
171 /* loop through pages */ |
|
172 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
173 |
|
174 /* verify page */ |
|
175 if ( ! isset( $page['hidden_page'] ) && $screen->id == $this->page_hook[$page['id']] ) { |
|
176 |
|
177 /* set up the help tabs */ |
|
178 if ( ! empty( $page['contextual_help']['content'] ) ) { |
|
179 foreach( $page['contextual_help']['content'] as $contextual_help ) { |
|
180 $screen->add_help_tab( |
|
181 array( |
|
182 'id' => esc_attr( $contextual_help['id'] ), |
|
183 'title' => esc_attr( $contextual_help['title'] ), |
|
184 'content' => htmlspecialchars_decode( $contextual_help['content'] ), |
|
185 ) |
|
186 ); |
|
187 } |
|
188 } |
|
189 |
|
190 /* set up the help sidebar */ |
|
191 if ( ! empty( $page['contextual_help']['sidebar'] ) ) { |
|
192 $screen->set_help_sidebar( htmlspecialchars_decode( $page['contextual_help']['sidebar'] ) ); |
|
193 } |
|
194 |
|
195 } |
|
196 |
|
197 } |
|
198 |
|
199 } |
|
200 |
|
201 return false; |
|
202 } |
|
203 |
|
204 /** |
|
205 * Loads the content for each page |
|
206 * |
|
207 * @return string |
|
208 * |
|
209 * @access public |
|
210 * @since 2.0 |
|
211 */ |
|
212 public function display_page() { |
|
213 $screen = get_current_screen(); |
|
214 |
|
215 /* loop through settings */ |
|
216 foreach( (array) $this->options as $option ) { |
|
217 |
|
218 /* loop through pages */ |
|
219 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
220 |
|
221 /* verify page */ |
|
222 if ( ! isset( $page['hidden_page'] ) && $screen->id == $this->page_hook[$page['id']] ) { |
|
223 |
|
224 $show_buttons = isset( $page['show_buttons'] ) && $page['show_buttons'] == false ? false : true; |
|
225 |
|
226 /* update active layout content */ |
|
227 if ( isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ) { |
|
228 |
|
229 $layouts = get_option( 'option_tree_layouts' ); |
|
230 |
|
231 /* has active layout */ |
|
232 if ( isset( $layouts['active_layout'] ) ) { |
|
233 $option_tree = get_option( $option['id'] ); |
|
234 $layouts[$layouts['active_layout']] = base64_encode( serialize( $option_tree ) ); |
|
235 update_option( 'option_tree_layouts', $layouts ); |
|
236 } |
|
237 |
|
238 } |
|
239 |
|
240 echo '<div class="wrap settings-wrap" id ="page-' . $page['id'] . '">'; |
|
241 |
|
242 screen_icon( ( isset( $page['screen_icon'] ) ? $page['screen_icon'] : 'options-general' ) ); |
|
243 echo '<h2>' . $page['page_title'] . '</h2>'; |
|
244 |
|
245 echo ot_alert_message( $page ); |
|
246 |
|
247 settings_errors( 'option-tree' ); |
|
248 |
|
249 /* Header */ |
|
250 echo '<div id="option-tree-header-wrap">'; |
|
251 |
|
252 echo '<ul id="option-tree-header">'; |
|
253 |
|
254 echo '<li id="option-tree-logo"><a href="http://wordpress.org/extend/plugins/option-tree/" target="_blank">OptionTree</a></li>'; |
|
255 |
|
256 echo '<li id="option-tree-version"><span>Version ' . OT_VERSION . '</span></li>'; |
|
257 |
|
258 echo '</ul>'; |
|
259 |
|
260 /* layouts form */ |
|
261 if ( $page['id'] == 'ot_theme_options' && OT_SHOW_NEW_LAYOUT == true ) |
|
262 ot_theme_options_layouts_form(); |
|
263 |
|
264 echo '</div>'; |
|
265 |
|
266 /* remove forms on the custom settings pages */ |
|
267 if ( $show_buttons ) { |
|
268 |
|
269 echo '<form action="options.php" method="post" id="option-tree-settings-api">'; |
|
270 |
|
271 settings_fields( $option['id'] ); |
|
272 |
|
273 } else { |
|
274 |
|
275 echo '<div id="option-tree-settings-api">'; |
|
276 |
|
277 } |
|
278 |
|
279 /* Sub Header */ |
|
280 echo '<div id="option-tree-sub-header">'; |
|
281 |
|
282 if ( $show_buttons ) |
|
283 echo '<button class="option-tree-ui-button grey right">' . $page['button_text'] . '</button>'; |
|
284 |
|
285 echo '</div>'; |
|
286 |
|
287 /* Navigation */ |
|
288 echo '<div class="ui-tabs">'; |
|
289 |
|
290 /* check for sections */ |
|
291 if ( isset( $page['sections'] ) && count( $page['sections'] ) > 0 ) { |
|
292 |
|
293 echo '<ul class="ui-tabs-nav">'; |
|
294 |
|
295 /* loop through page sections */ |
|
296 foreach( (array) $page['sections'] as $section ) { |
|
297 echo '<li id="tab_' . $section['id'] . '"><a href="#section_' . $section['id'] . '">' . $section['title'] . '</a></li>'; |
|
298 } |
|
299 |
|
300 echo '</ul>'; |
|
301 |
|
302 } |
|
303 |
|
304 /* sections */ |
|
305 echo '<div id="poststuff" class="metabox-holder">'; |
|
306 |
|
307 echo '<div id="post-body">'; |
|
308 |
|
309 echo '<div id="post-body-content">'; |
|
310 |
|
311 $this->do_settings_sections( $_GET['page'] ); |
|
312 |
|
313 echo '</div>'; |
|
314 |
|
315 echo '</div>'; |
|
316 |
|
317 echo '</div>'; |
|
318 |
|
319 echo '<div class="clear"></div>'; |
|
320 |
|
321 echo '</div>'; |
|
322 |
|
323 /* buttons */ |
|
324 if ( $show_buttons ) { |
|
325 |
|
326 echo '<div class="option-tree-ui-buttons">'; |
|
327 |
|
328 echo '<button class="option-tree-ui-button grey right">' . $page['button_text'] . '</button>'; |
|
329 |
|
330 echo '</div>'; |
|
331 |
|
332 } |
|
333 |
|
334 echo $show_buttons ? '</form>' : '</div>'; |
|
335 |
|
336 /* reset button */ |
|
337 if ( $show_buttons ) { |
|
338 |
|
339 echo '<form method="post" action="' . str_replace( '&settings-updated=true', '', $_SERVER["REQUEST_URI"] ) . '">'; |
|
340 |
|
341 /* form nonce */ |
|
342 wp_nonce_field( 'option_tree_reset_form', 'option_tree_reset_nonce' ); |
|
343 |
|
344 echo '<input type="hidden" name="action" value="reset" />'; |
|
345 |
|
346 echo '<button type="submit" class="option-tree-ui-button red light left reset-settings" title="' . __( 'Reset Options', 'option-tree' ) . '">' . __( 'Reset Options', 'option-tree' ) . '</button>'; |
|
347 |
|
348 echo '</form>'; |
|
349 |
|
350 } |
|
351 |
|
352 echo '</div>'; |
|
353 |
|
354 } |
|
355 |
|
356 } |
|
357 |
|
358 } |
|
359 |
|
360 return false; |
|
361 } |
|
362 |
|
363 /** |
|
364 * Adds sections to the page |
|
365 * |
|
366 * @return void |
|
367 * |
|
368 * @access public |
|
369 * @since 2.0 |
|
370 */ |
|
371 public function add_sections() { |
|
372 |
|
373 /* loop through options */ |
|
374 foreach( (array) $this->options as $option ) { |
|
375 |
|
376 /* loop through pages */ |
|
377 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
378 |
|
379 /* loop through page sections */ |
|
380 foreach( (array) $this->get_sections( $page ) as $section ) { |
|
381 |
|
382 /* add each section */ |
|
383 add_settings_section( |
|
384 $section['id'], |
|
385 $section['title'], |
|
386 array( &$this, 'display_section' ), |
|
387 $page['menu_slug'] |
|
388 ); |
|
389 |
|
390 } |
|
391 |
|
392 } |
|
393 |
|
394 } |
|
395 |
|
396 return false; |
|
397 } |
|
398 |
|
399 /** |
|
400 * Callback for add_settings_section() |
|
401 * |
|
402 * @return string |
|
403 * |
|
404 * @access public |
|
405 * @since 2.0 |
|
406 */ |
|
407 public function display_section() { |
|
408 /* currently pointless */ |
|
409 } |
|
410 |
|
411 /** |
|
412 * Add settings the the page |
|
413 * |
|
414 * @return void |
|
415 * |
|
416 * @access public |
|
417 * @since 2.0 |
|
418 */ |
|
419 public function add_settings() { |
|
420 |
|
421 /* loop through options */ |
|
422 foreach( (array) $this->options as $option ) { |
|
423 |
|
424 register_setting( $option['id'], $option['id'], array ( &$this, 'sanitize_callback' ) ); |
|
425 |
|
426 /* loop through pages */ |
|
427 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
428 |
|
429 /* loop through page settings */ |
|
430 foreach( (array) $this->get_settings( $page ) as $setting ) { |
|
431 |
|
432 /* skip if no setting ID */ |
|
433 if ( ! isset( $setting['id'] ) ) |
|
434 continue; |
|
435 |
|
436 /* add get_option param to the array */ |
|
437 $setting['get_option'] = $option['id']; |
|
438 |
|
439 /* add each setting */ |
|
440 add_settings_field( |
|
441 $setting['id'], |
|
442 $setting['label'], |
|
443 array( &$this, 'display_setting' ), |
|
444 $page['menu_slug'], |
|
445 $setting['section'], |
|
446 $setting |
|
447 ); |
|
448 |
|
449 } |
|
450 |
|
451 } |
|
452 |
|
453 } |
|
454 |
|
455 return false; |
|
456 } |
|
457 |
|
458 /** |
|
459 * Callback for add_settings_field() to build each setting by type |
|
460 * |
|
461 * @param array Setting object array |
|
462 * @return string |
|
463 * |
|
464 * @access public |
|
465 * @since 2.0 |
|
466 */ |
|
467 public function display_setting( $args = array() ) { |
|
468 extract( $args ); |
|
469 |
|
470 /* get current saved data */ |
|
471 $options = get_option( $get_option, false ); |
|
472 |
|
473 /* set default to standard value */ |
|
474 if ( ! isset( $options[$id] ) && isset( $std ) ) { |
|
475 $options[$id] = trim( $std ); |
|
476 } |
|
477 |
|
478 /* build the arguments array */ |
|
479 $_args = array( |
|
480 'type' => $type, |
|
481 'field_id' => $id, |
|
482 'field_name' => 'option_tree[' . $id . ']', |
|
483 'field_value' => isset( $options[$id] ) ? $options[$id] : '', |
|
484 'field_desc' => isset( $desc ) ? $desc : '', |
|
485 'field_std' => isset( $std ) ? $std : '', |
|
486 'field_rows' => isset( $rows ) && ! empty( $rows ) ? $rows : 15, |
|
487 'field_post_type' => isset( $post_type ) && ! empty( $post_type ) ? $post_type : 'post', |
|
488 'field_taxonomy' => isset( $taxonomy ) && ! empty( $taxonomy ) ? $taxonomy : 'category', |
|
489 'field_class' => isset( $class ) ? $class : '', |
|
490 'field_choices' => isset( $choices ) && ! empty( $choices ) ? $choices : array(), |
|
491 'field_settings' => isset( $settings ) && ! empty( $settings ) ? $settings : array(), |
|
492 'post_id' => ot_get_media_post_ID(), |
|
493 'get_option' => $get_option, |
|
494 ); |
|
495 |
|
496 /* get the option HTML */ |
|
497 echo ot_display_by_type( $_args ); |
|
498 } |
|
499 |
|
500 /** |
|
501 * Sets the option standards if nothing yet exists. |
|
502 * |
|
503 * @return void |
|
504 * |
|
505 * @access public |
|
506 * @since 2.0 |
|
507 */ |
|
508 public function initialize_settings() { |
|
509 |
|
510 /* loop through options */ |
|
511 foreach( (array) $this->options as $option ) { |
|
512 |
|
513 /* skip if option is already set */ |
|
514 if ( isset( $option['id'] ) && get_option( $option['id'], false ) ) { |
|
515 return false; |
|
516 } |
|
517 |
|
518 $defaults = array(); |
|
519 |
|
520 /* loop through pages */ |
|
521 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
522 |
|
523 /* loop through page settings */ |
|
524 foreach( (array) $this->get_settings( $page ) as $setting ) { |
|
525 |
|
526 if ( isset( $setting['std'] ) ) { |
|
527 |
|
528 $defaults[$setting['id']] = ot_validate_setting( $setting['std'], $setting['type'], $setting['id'] ); |
|
529 |
|
530 } |
|
531 |
|
532 } |
|
533 |
|
534 } |
|
535 |
|
536 update_option( $option['id'], $defaults ); |
|
537 |
|
538 } |
|
539 |
|
540 return false; |
|
541 } |
|
542 |
|
543 /** |
|
544 * Sanitize callback for register_setting() |
|
545 * |
|
546 * @return string |
|
547 * |
|
548 * @access public |
|
549 * @since 2.0 |
|
550 */ |
|
551 public function sanitize_callback( $input ) { |
|
552 |
|
553 /* loop through options */ |
|
554 foreach( (array) $this->options as $option ) { |
|
555 |
|
556 /* loop through pages */ |
|
557 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
558 |
|
559 /* loop through page settings */ |
|
560 foreach( (array) $this->get_settings( $page ) as $setting ) { |
|
561 |
|
562 /* verify setting has a type & value */ |
|
563 if ( isset( $setting['type'] ) && isset( $input[$setting['id']] ) ) { |
|
564 |
|
565 /* validate setting */ |
|
566 if ( is_array( $input[$setting['id']] ) && in_array( $setting['type'], array( 'list-item', 'slider' ) ) ) { |
|
567 |
|
568 /* required title setting */ |
|
569 $required_setting = array( |
|
570 array( |
|
571 'id' => 'title', |
|
572 'label' => __( 'Title', 'option-tree' ), |
|
573 'desc' => '', |
|
574 'std' => '', |
|
575 'type' => 'text', |
|
576 'rows' => '', |
|
577 'class' => 'option-tree-setting-title', |
|
578 'post_type' => '', |
|
579 'choices' => array() |
|
580 ) |
|
581 ); |
|
582 |
|
583 /* get the settings array */ |
|
584 $settings = isset( $_POST[$setting['id'] . '_settings_array'] ) ? unserialize( base64_decode( $_POST[$setting['id'] . '_settings_array'] ) ) : array(); |
|
585 |
|
586 /* settings are empty for some odd ass reason get the defaults */ |
|
587 if ( empty( $settings ) ) { |
|
588 $settings = 'slider' == $setting['type'] ? |
|
589 ot_slider_settings( $setting['id'] ) : |
|
590 ot_list_item_settings( $setting['id'] ); |
|
591 } |
|
592 |
|
593 /* merge the two settings array */ |
|
594 $settings = array_merge( $required_setting, $settings ); |
|
595 |
|
596 foreach( $input[$setting['id']] as $k => $setting_array ) { |
|
597 |
|
598 foreach( $settings as $sub_setting ) { |
|
599 |
|
600 /* verify sub setting has a type & value */ |
|
601 if ( isset( $sub_setting['type'] ) && isset( $input[$setting['id']][$k][$sub_setting['id']] ) ) { |
|
602 |
|
603 $input[$setting['id']][$k][$sub_setting['id']] = ot_validate_setting( $input[$setting['id']][$k][$sub_setting['id']], $sub_setting['type'], $sub_setting['id'] ); |
|
604 |
|
605 } |
|
606 |
|
607 } |
|
608 |
|
609 } |
|
610 |
|
611 } else { |
|
612 |
|
613 $input[$setting['id']] = ot_validate_setting( $input[$setting['id']], $setting['type'], $setting['id'] ); |
|
614 |
|
615 } |
|
616 |
|
617 } |
|
618 |
|
619 } |
|
620 |
|
621 } |
|
622 |
|
623 } |
|
624 |
|
625 return $input; |
|
626 } |
|
627 |
|
628 /** |
|
629 * Helper function to get the pages array for an option |
|
630 * |
|
631 * @param array Option array |
|
632 * @return mixed |
|
633 * |
|
634 * @access public |
|
635 * @since 2.0 |
|
636 */ |
|
637 public function get_pages( $option = array() ) { |
|
638 |
|
639 if ( empty( $option ) ) |
|
640 return false; |
|
641 |
|
642 /* check for pages */ |
|
643 if ( isset( $option['pages'] ) && ! empty( $option['pages'] ) ) { |
|
644 |
|
645 /* return pages array */ |
|
646 return $option['pages']; |
|
647 |
|
648 } |
|
649 |
|
650 return false; |
|
651 } |
|
652 |
|
653 /** |
|
654 * Helper function to get the sections array for a page |
|
655 * |
|
656 * @param array Page array |
|
657 * @return mixed |
|
658 * |
|
659 * @access public |
|
660 * @since 2.0 |
|
661 */ |
|
662 public function get_sections( $page = array() ) { |
|
663 |
|
664 if ( empty( $page ) ) |
|
665 return false; |
|
666 |
|
667 /* check for sections */ |
|
668 if ( isset( $page['sections'] ) && ! empty( $page['sections'] ) ) { |
|
669 |
|
670 /* return sections array */ |
|
671 return $page['sections']; |
|
672 |
|
673 } |
|
674 |
|
675 return false; |
|
676 } |
|
677 |
|
678 /** |
|
679 * Helper function to get the settings array for a page |
|
680 * |
|
681 * @param array Page array |
|
682 * @return mixed |
|
683 * |
|
684 * @access public |
|
685 * @since 2.0 |
|
686 */ |
|
687 public function get_settings( $page = array() ) { |
|
688 |
|
689 if ( empty( $page ) ) |
|
690 return false; |
|
691 |
|
692 /* check for settings */ |
|
693 if ( isset( $page['settings'] ) && ! empty( $page['settings'] ) ) { |
|
694 |
|
695 /* return settings array */ |
|
696 return $page['settings']; |
|
697 |
|
698 } |
|
699 |
|
700 return false; |
|
701 } |
|
702 |
|
703 /** |
|
704 * Prints out all settings sections added to a particular settings page |
|
705 * |
|
706 * @global $wp_settings_sections Storage array of all settings sections added to admin pages |
|
707 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections |
|
708 * |
|
709 * @param string The slug name of the page whos settings sections you want to output |
|
710 * @return string |
|
711 * |
|
712 * @access public |
|
713 * @since 2.0 |
|
714 */ |
|
715 public function do_settings_sections( $page ) { |
|
716 global $wp_settings_sections, $wp_settings_fields; |
|
717 |
|
718 if ( ! isset( $wp_settings_sections ) || ! isset( $wp_settings_sections[$page] ) ) { |
|
719 return false; |
|
720 } |
|
721 |
|
722 foreach ( (array) $wp_settings_sections[$page] as $section ) { |
|
723 |
|
724 if ( ! isset( $section['id'] ) ) |
|
725 continue; |
|
726 |
|
727 echo '<div id="section_' . $section['id'] . '" class="postbox ui-tabs-panel">'; |
|
728 |
|
729 call_user_func( $section['callback'], $section ); |
|
730 |
|
731 if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[$page] ) || ! isset( $wp_settings_fields[$page][$section['id']] ) ) |
|
732 continue; |
|
733 |
|
734 echo '<div class="inside">'; |
|
735 |
|
736 $this->do_settings_fields( $page, $section['id'] ); |
|
737 |
|
738 echo '</div>'; |
|
739 |
|
740 echo '</div>'; |
|
741 |
|
742 } |
|
743 |
|
744 } |
|
745 |
|
746 /** |
|
747 * Print out the settings fields for a particular settings section |
|
748 * |
|
749 * @global $wp_settings_fields Storage array of settings fields and their pages/sections |
|
750 * |
|
751 * @param string $page Slug title of the admin page who's settings fields you want to show. |
|
752 * @param string $section Slug title of the settings section who's fields you want to show. |
|
753 * @return string |
|
754 * |
|
755 * @access public |
|
756 * @since 2.0 |
|
757 */ |
|
758 public function do_settings_fields( $page, $section ) { |
|
759 global $wp_settings_fields; |
|
760 |
|
761 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) |
|
762 return; |
|
763 |
|
764 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { |
|
765 |
|
766 echo '<div id="setting_' . $field['id'] . '" class="format-settings">'; |
|
767 |
|
768 echo '<div class="format-setting-wrap">'; |
|
769 |
|
770 if ( $field['args']['type'] != 'textblock' ) { |
|
771 |
|
772 echo '<div class="format-setting-label">'; |
|
773 |
|
774 echo '<h3 class="label">' . $field['title'] . '</h3>'; |
|
775 |
|
776 echo '</div>'; |
|
777 |
|
778 } |
|
779 |
|
780 call_user_func( $field['callback'], $field['args'] ); |
|
781 |
|
782 echo '</div>'; |
|
783 |
|
784 echo '</div>'; |
|
785 |
|
786 } |
|
787 |
|
788 } |
|
789 |
|
790 /** |
|
791 * Resets page options before the screen is displayed |
|
792 * |
|
793 * @return void |
|
794 * |
|
795 * @access public |
|
796 * @since 2.0 |
|
797 */ |
|
798 public function reset_options() { |
|
799 |
|
800 /* check for reset action */ |
|
801 if ( isset( $_POST['option_tree_reset_nonce'] ) && wp_verify_nonce( $_POST['option_tree_reset_nonce'], 'option_tree_reset_form' ) ) { |
|
802 |
|
803 /* loop through options */ |
|
804 foreach( (array) $this->options as $option ) { |
|
805 |
|
806 /* loop through pages */ |
|
807 foreach( (array) $this->get_pages( $option ) as $page ) { |
|
808 |
|
809 /* verify page */ |
|
810 if ( isset( $_GET['page'] ) && $_GET['page'] == $page['menu_slug'] ) { |
|
811 |
|
812 /* reset options */ |
|
813 delete_option( $option['id'] ); |
|
814 |
|
815 } |
|
816 |
|
817 } |
|
818 |
|
819 } |
|
820 |
|
821 } |
|
822 |
|
823 return false; |
|
824 } |
|
825 |
|
826 } |
|
827 |
|
828 } |
|
829 |
|
830 /** |
|
831 * This method instantiates the settings class & builds the UI. |
|
832 * |
|
833 * @uses OT_Settings() |
|
834 * |
|
835 * @param array Array of arguments to create settings |
|
836 * @return void |
|
837 * |
|
838 * @access public |
|
839 * @since 2.0 |
|
840 */ |
|
841 if ( ! function_exists( 'ot_register_settings' ) ) { |
|
842 |
|
843 function ot_register_settings( $args ) { |
|
844 if ( ! $args ) |
|
845 return; |
|
846 |
|
847 $ot_settings =& new OT_Settings( $args ); |
|
848 } |
|
849 |
|
850 } |
|
851 |
|
852 /* End of file ot-settings-api.php */ |
|
853 /* Location: ./includes/ot-settings-api.php */ |