changeset 5 | 5e2f62d02dcd |
parent 0 | d970ebf37754 |
child 7 | cf61fcea0001 |
4:346c88efed21 | 5:5e2f62d02dcd |
---|---|
24 if ( ! function_exists( 'ot_register_theme_options_page' ) ) { |
24 if ( ! function_exists( 'ot_register_theme_options_page' ) ) { |
25 |
25 |
26 function ot_register_theme_options_page() { |
26 function ot_register_theme_options_page() { |
27 |
27 |
28 /* get the settings array */ |
28 /* get the settings array */ |
29 $get_settings = get_option( 'option_tree_settings' ); |
29 $get_settings = get_option( ot_settings_id() ); |
30 |
30 |
31 /* sections array */ |
31 /* sections array */ |
32 $sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array(); |
32 $sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array(); |
33 |
33 |
34 /* settings array */ |
34 /* settings array */ |
40 /* build the Theme Options */ |
40 /* build the Theme Options */ |
41 if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) { |
41 if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) { |
42 |
42 |
43 ot_register_settings( array( |
43 ot_register_settings( array( |
44 array( |
44 array( |
45 'id' => 'option_tree', |
45 'id' => ot_options_id(), |
46 'pages' => array( |
46 'pages' => array( |
47 array( |
47 array( |
48 'id' => 'ot_theme_options', |
48 'id' => 'ot_theme_options', |
49 'parent_slug' => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ), |
49 'parent_slug' => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ), |
50 'page_title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
50 'page_title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
54 'icon_url' => apply_filters( 'ot_theme_options_icon_url', null ), |
54 'icon_url' => apply_filters( 'ot_theme_options_icon_url', null ), |
55 'position' => apply_filters( 'ot_theme_options_position', null ), |
55 'position' => apply_filters( 'ot_theme_options_position', null ), |
56 'updated_message' => apply_filters( 'ot_theme_options_updated_message', __( 'Theme Options updated.', 'option-tree' ) ), |
56 'updated_message' => apply_filters( 'ot_theme_options_updated_message', __( 'Theme Options updated.', 'option-tree' ) ), |
57 'reset_message' => apply_filters( 'ot_theme_options_reset_message', __( 'Theme Options reset.', 'option-tree' ) ), |
57 'reset_message' => apply_filters( 'ot_theme_options_reset_message', __( 'Theme Options reset.', 'option-tree' ) ), |
58 'button_text' => apply_filters( 'ot_theme_options_button_text', __( 'Save Changes', 'option-tree' ) ), |
58 'button_text' => apply_filters( 'ot_theme_options_button_text', __( 'Save Changes', 'option-tree' ) ), |
59 'screen_icon' => 'themes', |
59 'contextual_help' => apply_filters( 'ot_theme_options_contextual_help', $contextual_help ), |
60 'contextual_help' => $contextual_help, |
60 'sections' => apply_filters( 'ot_theme_options_sections', $sections ), |
61 'sections' => $sections, |
61 'settings' => apply_filters( 'ot_theme_options_settings', $settings ) |
62 'settings' => $settings |
|
63 ) |
62 ) |
64 ) |
63 ) |
65 ) |
64 ) |
66 ) |
65 ) |
67 ); |
66 ); |
68 |
67 |
69 // Filters the options.php to add the minimum user capabilities. |
68 // Filters the options.php to add the minimum user capabilities. |
70 add_filter( 'option_page_capability_option_tree', create_function( '$caps', "return '$caps';" ), 999 ); |
69 add_filter( 'option_page_capability_' . ot_options_id(), create_function( '$caps', "return '$caps';" ), 999 ); |
71 |
70 |
72 } |
71 } |
73 |
72 |
74 } |
73 } |
75 |
74 |
86 * @since 2.1 |
85 * @since 2.1 |
87 */ |
86 */ |
88 if ( ! function_exists( 'ot_register_settings_page' ) ) { |
87 if ( ! function_exists( 'ot_register_settings_page' ) ) { |
89 |
88 |
90 function ot_register_settings_page() { |
89 function ot_register_settings_page() { |
91 |
90 global $ot_has_custom_theme_options; |
91 |
|
92 // Display UI Builder admin notice |
|
93 if ( OT_SHOW_OPTIONS_UI == true && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ot-settings' && ( $ot_has_custom_theme_options == true || has_action( 'admin_init', 'custom_theme_options' ) || has_action( 'init', 'custom_theme_options' ) ) ) { |
|
94 |
|
95 function ot_has_custom_theme_options() { |
|
96 |
|
97 echo '<div class="error"><p>' . __( 'The Theme Options UI Builder is being overridden by a custom file in your theme. Any changes you make via the UI Builder will not be saved.', 'option-tree' ) . '</p></div>'; |
|
98 |
|
99 } |
|
100 |
|
101 add_action( 'admin_notices', 'ot_has_custom_theme_options' ); |
|
102 |
|
103 } |
|
104 |
|
92 // Create the filterable pages array |
105 // Create the filterable pages array |
93 $ot_register_pages_array = array( |
106 $ot_register_pages_array = array( |
94 array( |
107 array( |
95 'id' => 'ot', |
108 'id' => 'ot', |
96 'page_title' => __( 'OptionTree', 'option-tree' ), |
109 'page_title' => __( 'OptionTree', 'option-tree' ), |
97 'menu_title' => __( 'OptionTree', 'option-tree' ), |
110 'menu_title' => __( 'OptionTree', 'option-tree' ), |
98 'capability' => 'edit_theme_options', |
111 'capability' => 'edit_theme_options', |
99 'menu_slug' => 'ot-settings', |
112 'menu_slug' => 'ot-settings', |
100 'icon_url' => OT_URL . '/assets/images/ot-logo-mini.png', |
113 'icon_url' => null, |
101 'position' => 61, |
114 'position' => 61, |
102 'hidden_page' => true |
115 'hidden_page' => true |
103 ), |
116 ), |
104 array( |
117 array( |
105 'id' => 'settings', |
118 'id' => 'settings', |
112 'position' => null, |
125 'position' => null, |
113 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
126 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
114 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
127 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
115 'button_text' => __( 'Save Settings', 'option-tree' ), |
128 'button_text' => __( 'Save Settings', 'option-tree' ), |
116 'show_buttons' => false, |
129 'show_buttons' => false, |
117 'screen_icon' => 'themes', |
|
118 'sections' => array( |
130 'sections' => array( |
119 array( |
131 array( |
120 'id' => 'create_setting', |
132 'id' => 'create_setting', |
121 'title' => __( 'Theme Options UI', 'option-tree' ) |
133 'title' => __( 'Theme Options UI', 'option-tree' ) |
122 ), |
134 ), |
207 'position' => null, |
219 'position' => null, |
208 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
220 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
209 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
221 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
210 'button_text' => __( 'Save Settings', 'option-tree' ), |
222 'button_text' => __( 'Save Settings', 'option-tree' ), |
211 'show_buttons' => false, |
223 'show_buttons' => false, |
212 'screen_icon' => 'themes', |
|
213 'sections' => array( |
224 'sections' => array( |
214 array( |
225 array( |
215 'id' => 'creating_options', |
226 'id' => 'creating_options', |
216 'title' => __( 'Creating Options', 'option-tree' ) |
227 'title' => __( 'Creating Options', 'option-tree' ) |
217 ), |
228 ), |
369 $ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array ); |
380 $ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array ); |
370 |
381 |
371 // Register the pages. |
382 // Register the pages. |
372 ot_register_settings( array( |
383 ot_register_settings( array( |
373 array( |
384 array( |
374 'id' => 'option_tree_settings', |
385 'id' => ot_settings_id(), |
375 'pages' => $ot_register_pages_array |
386 'pages' => $ot_register_pages_array |
376 ) |
387 ) |
377 ) |
388 ) |
378 ); |
389 ); |
379 |
390 |
398 |
409 |
399 /* only execute after the theme options are saved */ |
410 /* only execute after the theme options are saved */ |
400 if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) == $page && $updated ) { |
411 if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) == $page && $updated ) { |
401 |
412 |
402 /* grab a copy of the theme options */ |
413 /* grab a copy of the theme options */ |
403 $options = get_option( 'option_tree' ); |
414 $options = get_option( ot_options_id() ); |
404 |
415 |
405 /* execute the action hook and pass the theme options to it */ |
416 /* execute the action hook and pass the theme options to it */ |
406 do_action( 'ot_after_theme_options_save', $options ); |
417 do_action( 'ot_after_theme_options_save', $options ); |
407 |
418 |
408 } |
419 } |
464 |
475 |
465 $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id ); |
476 $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id ); |
466 |
477 |
467 $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id ); |
478 $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id ); |
468 |
479 |
480 // Loop over array and check for values |
|
481 foreach( (array) $input as $key => $value ) { |
|
482 if ( ! empty( $value ) ) { |
|
483 $has_value = true; |
|
484 } |
|
485 } |
|
486 |
|
487 // No value; set to empty |
|
488 if ( ! isset( $has_value ) ) { |
|
489 $input = ''; |
|
490 } |
|
491 |
|
492 } else if ( 'border' == $type ) { |
|
493 |
|
494 // Loop over array and set errors or unset key from array. |
|
495 foreach( $input as $key => $value ) { |
|
496 |
|
497 // Validate width |
|
498 if ( $key == 'width' && ! empty( $value ) && ! is_numeric( $value ) ) { |
|
499 |
|
500 $input[$key] = '0'; |
|
501 |
|
502 add_settings_error( 'option-tree', 'invalid_border_width', sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>width</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
503 |
|
504 } |
|
505 |
|
506 // Validate color |
|
507 if ( $key == 'color' && ! empty( $value ) ) { |
|
508 |
|
509 $input[$key] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
|
510 |
|
511 } |
|
512 |
|
513 // Unset keys with empty values. |
|
514 if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
515 unset( $input[$key] ); |
|
516 } |
|
517 |
|
518 } |
|
519 |
|
520 if ( empty( $input ) ) { |
|
521 $input = ''; |
|
522 } |
|
523 |
|
524 } else if ( 'box-shadow' == $type ) { |
|
525 |
|
526 // Validate inset |
|
527 $input['inset'] = isset( $input['inset'] ) ? 'inset' : ''; |
|
528 |
|
529 // Validate offset-x |
|
530 $input['offset-x'] = ot_validate_setting( $input['offset-x'], 'text', $field_id ); |
|
531 |
|
532 // Validate offset-y |
|
533 $input['offset-y'] = ot_validate_setting( $input['offset-y'], 'text', $field_id ); |
|
534 |
|
535 // Validate blur-radius |
|
536 $input['blur-radius'] = ot_validate_setting( $input['blur-radius'], 'text', $field_id ); |
|
537 |
|
538 // Validate spread-radius |
|
539 $input['spread-radius'] = ot_validate_setting( $input['spread-radius'], 'text', $field_id ); |
|
540 |
|
541 // Validate color |
|
542 $input['color'] = ot_validate_setting( $input['color'], 'colorpicker', $field_id ); |
|
543 |
|
544 // Unset keys with empty values. |
|
545 foreach( $input as $key => $value ) { |
|
546 if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
547 unset( $input[$key] ); |
|
548 } |
|
549 } |
|
550 |
|
551 // Set empty array to empty string. |
|
552 if ( empty( $input ) ) { |
|
553 $input = ''; |
|
554 } |
|
555 |
|
469 } else if ( 'colorpicker' == $type ) { |
556 } else if ( 'colorpicker' == $type ) { |
470 |
557 |
471 /* return empty & set error */ |
558 /* return empty & set error */ |
472 if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) ) { |
559 if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) && 0 === preg_match( '/^rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]{1,4})\s*\)/i', $input ) ) { |
473 |
560 |
474 $input = ''; |
561 $input = ''; |
475 |
562 |
476 add_settings_error( 'option-tree', 'invalid_hex', __( 'The Colorpicker only allows valid hexadecimal values.', 'option-tree' ), 'error' ); |
563 add_settings_error( 'option-tree', 'invalid_hex', sprintf( __( 'The %s Colorpicker only allows valid hexadecimal or rgba values.', 'option-tree' ), '<code>' . $field_id . '</code>' ), 'error' ); |
477 |
564 |
478 } |
565 } |
479 |
566 |
480 } else if ( in_array( $type, array( 'css', 'text', 'textarea', 'textarea-simple' ) ) ) { |
567 } else if ( 'colorpicker-opacity' == $type ) { |
568 |
|
569 // Not allowed |
|
570 if ( is_array( $input ) ) { |
|
571 $input = ''; |
|
572 } |
|
573 |
|
574 // Validate color |
|
575 $input = ot_validate_setting( $input, 'colorpicker', $field_id ); |
|
576 |
|
577 } else if ( in_array( $type, array( 'css', 'javascript', 'text', 'textarea', 'textarea-simple' ) ) ) { |
|
481 |
578 |
482 if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) { |
579 if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) { |
483 |
580 |
484 $input = wp_kses_post( $input ); |
581 $input = wp_kses_post( $input ); |
485 |
582 |
486 } |
583 } |
487 |
584 |
585 } else if ( 'dimension' == $type ) { |
|
586 |
|
587 // Loop over array and set error keys or unset key from array. |
|
588 foreach( $input as $key => $value ) { |
|
589 if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
|
590 $errors[] = $key; |
|
591 } |
|
592 if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
593 unset( $input[$key] ); |
|
594 } |
|
595 } |
|
596 |
|
597 /* return 0 & set error */ |
|
598 if ( isset( $errors ) ) { |
|
599 |
|
600 foreach( $errors as $error ) { |
|
601 |
|
602 $input[$error] = '0'; |
|
603 |
|
604 add_settings_error( 'option-tree', 'invalid_dimension_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
605 |
|
606 } |
|
607 |
|
608 } |
|
609 |
|
610 if ( empty( $input ) ) { |
|
611 $input = ''; |
|
612 } |
|
613 |
|
614 } else if ( 'google-fonts' == $type ) { |
|
615 |
|
616 unset($input['%key%']); |
|
617 |
|
618 // Loop over array and check for values |
|
619 if ( is_array( $input ) && ! empty( $input ) ) { |
|
620 $input = array_values( $input ); |
|
621 } |
|
622 |
|
623 // No value; set to empty |
|
624 if ( empty( $input ) ) { |
|
625 $input = ''; |
|
626 } |
|
627 |
|
628 } else if ( 'link-color' == $type ) { |
|
629 |
|
630 // Loop over array and check for values |
|
631 if ( is_array( $input ) && ! empty( $input ) ) { |
|
632 foreach( $input as $key => $value ) { |
|
633 if ( ! empty( $value ) ) { |
|
634 $input[$key] = ot_validate_setting( $input[$key], 'colorpicker', $field_id . '-' . $key ); |
|
635 $has_value = true; |
|
636 } |
|
637 } |
|
638 } |
|
639 |
|
640 // No value; set to empty |
|
641 if ( ! isset( $has_value ) ) { |
|
642 $input = ''; |
|
643 } |
|
644 |
|
488 } else if ( 'measurement' == $type ) { |
645 } else if ( 'measurement' == $type ) { |
489 |
646 |
490 $input[0] = sanitize_text_field( $input[0] ); |
647 $input[0] = sanitize_text_field( $input[0] ); |
491 |
648 |
649 // No value; set to empty |
|
650 if ( empty( $input[0] ) && strlen( $input[0] ) == 0 && empty( $input[1] ) ) { |
|
651 $input = ''; |
|
652 } |
|
653 |
|
654 } else if ( 'spacing' == $type ) { |
|
655 |
|
656 // Loop over array and set error keys or unset key from array. |
|
657 foreach( $input as $key => $value ) { |
|
658 if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
|
659 $errors[] = $key; |
|
660 } |
|
661 if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
662 unset( $input[$key] ); |
|
663 } |
|
664 } |
|
665 |
|
666 /* return 0 & set error */ |
|
667 if ( isset( $errors ) ) { |
|
668 |
|
669 foreach( $errors as $error ) { |
|
670 |
|
671 $input[$error] = '0'; |
|
672 |
|
673 add_settings_error( 'option-tree', 'invalid_spacing_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
674 |
|
675 } |
|
676 |
|
677 } |
|
678 |
|
679 if ( empty( $input ) ) { |
|
680 $input = ''; |
|
681 } |
|
682 |
|
492 } else if ( 'typography' == $type && isset( $input['font-color'] ) ) { |
683 } else if ( 'typography' == $type && isset( $input['font-color'] ) ) { |
493 |
684 |
494 $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id ); |
685 $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id ); |
495 |
686 |
687 // Loop over array and check for values |
|
688 foreach( $input as $key => $value ) { |
|
689 if ( ! empty( $value ) ) { |
|
690 $has_value = true; |
|
691 } |
|
692 } |
|
693 |
|
694 // No value; set to empty |
|
695 if ( ! isset( $has_value ) ) { |
|
696 $input = ''; |
|
697 } |
|
698 |
|
496 } else if ( 'upload' == $type ) { |
699 } else if ( 'upload' == $type ) { |
497 |
700 |
498 $input = sanitize_text_field( $input ); |
701 if( filter_var( $input, FILTER_VALIDATE_INT ) === FALSE ) { |
499 |
702 $input = esc_url_raw( $input ); |
703 } |
|
704 |
|
705 } else if ( 'gallery' == $type ) { |
|
706 |
|
707 $input = trim( $input ); |
|
708 |
|
709 } else if ( 'social-links' == $type ) { |
|
710 |
|
711 // Loop over array and check for values, plus sanitize the text field |
|
712 foreach( (array) $input as $key => $value ) { |
|
713 if ( ! empty( $value ) && is_array( $value ) ) { |
|
714 foreach( (array) $value as $item_key => $item_value ) { |
|
715 if ( ! empty( $item_value ) ) { |
|
716 $has_value = true; |
|
717 $input[$key][$item_key] = sanitize_text_field( $item_value ); |
|
718 } |
|
719 } |
|
720 } |
|
721 } |
|
722 |
|
723 // No value; set to empty |
|
724 if ( ! isset( $has_value ) ) { |
|
725 $input = ''; |
|
726 } |
|
727 |
|
500 } |
728 } |
501 |
729 |
502 $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id ); |
730 $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id ); |
503 |
731 |
504 return $input; |
732 return $input; |
505 |
733 |
506 } |
734 } |
507 |
735 |
508 } |
736 } |
509 |
737 |
510 /** |
738 /** |
511 * Setup the default admin styles |
739 * Setup the default admin styles |
512 * |
740 * |
513 * @return void |
741 * @return void |
514 * |
742 * |
516 * @since 2.0 |
744 * @since 2.0 |
517 */ |
745 */ |
518 if ( ! function_exists( 'ot_admin_styles' ) ) { |
746 if ( ! function_exists( 'ot_admin_styles' ) ) { |
519 |
747 |
520 function ot_admin_styles() { |
748 function ot_admin_styles() { |
521 |
749 global $wp_styles, $post; |
750 |
|
751 /* execute styles before actions */ |
|
752 do_action( 'ot_admin_styles_before' ); |
|
753 |
|
754 /* load WP colorpicker */ |
|
755 wp_enqueue_style( 'wp-color-picker' ); |
|
756 |
|
757 /* load admin styles */ |
|
522 wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); |
758 wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); |
523 |
759 |
760 /* load the RTL stylesheet */ |
|
761 $wp_styles->add_data( 'ot-admin-css','rtl', true ); |
|
762 |
|
763 /* Remove styles added by the Easy Digital Downloads plugin */ |
|
764 if ( isset( $post->post_type ) && $post->post_type == 'post' ) |
|
765 wp_dequeue_style( 'jquery-ui-css' ); |
|
766 |
|
767 /** |
|
768 * Filter the screen IDs used to dequeue `jquery-ui-css`. |
|
769 * |
|
770 * @since 2.5.0 |
|
771 * |
|
772 * @param array $screen_ids An array of screen IDs. |
|
773 */ |
|
774 $screen_ids = apply_filters( 'ot_dequeue_jquery_ui_css_screen_ids', array( |
|
775 'toplevel_page_ot-settings', |
|
776 'optiontree_page_ot-documentation', |
|
777 'appearance_page_ot-theme-options' |
|
778 ) ); |
|
779 |
|
780 /* Remove styles added by the WP Review plugin and any custom pages added through filtering */ |
|
781 if ( in_array( get_current_screen()->id, $screen_ids ) ) { |
|
782 wp_dequeue_style( 'plugin_name-admin-ui-css' ); |
|
783 wp_dequeue_style( 'jquery-ui-css' ); |
|
784 } |
|
785 |
|
786 /* execute styles after actions */ |
|
787 do_action( 'ot_admin_styles_after' ); |
|
788 |
|
524 } |
789 } |
525 |
790 |
526 } |
791 } |
527 |
792 |
528 /** |
793 /** |
538 * @since 2.0 |
803 * @since 2.0 |
539 */ |
804 */ |
540 if ( ! function_exists( 'ot_admin_scripts' ) ) { |
805 if ( ! function_exists( 'ot_admin_scripts' ) ) { |
541 |
806 |
542 function ot_admin_scripts() { |
807 function ot_admin_scripts() { |
543 |
808 |
809 /* execute scripts before actions */ |
|
810 do_action( 'ot_admin_scripts_before' ); |
|
811 |
|
544 if ( function_exists( 'wp_enqueue_media' ) ) { |
812 if ( function_exists( 'wp_enqueue_media' ) ) { |
545 /* WP 3.5 Media Uploader */ |
813 /* WP 3.5 Media Uploader */ |
546 wp_enqueue_media(); |
814 wp_enqueue_media(); |
547 } else { |
815 } else { |
548 /* Legacy Thickbox */ |
816 /* Legacy Thickbox */ |
549 add_thickbox(); |
817 add_thickbox(); |
550 } |
818 } |
551 |
819 |
552 /* load the colorpicker */ |
|
553 wp_enqueue_script( 'ot-colorpicker-js', OT_URL . 'assets/js/ot-colorpicker.js', array( 'jquery' ), OT_VERSION ); |
|
554 |
|
555 /* load jQuery-ui slider */ |
820 /* load jQuery-ui slider */ |
556 wp_enqueue_script( 'jquery-ui-slider' ); |
821 wp_enqueue_script( 'jquery-ui-slider' ); |
557 |
822 |
823 /* load jQuery-ui datepicker */ |
|
824 wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
825 |
|
826 /* load WP colorpicker */ |
|
827 wp_enqueue_script( 'wp-color-picker' ); |
|
828 |
|
829 /* load Ace Editor for CSS Editing */ |
|
830 wp_enqueue_script( 'ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js', null, '1.1.3' ); |
|
831 |
|
832 /* load jQuery UI timepicker addon */ |
|
833 wp_enqueue_script( 'jquery-ui-timepicker', OT_URL . 'assets/js/vendor/jquery/jquery-ui-timepicker.js', array( 'jquery', 'jquery-ui-slider', 'jquery-ui-datepicker' ), '1.4.3' ); |
|
834 |
|
835 /* load the post formats */ |
|
836 if ( OT_META_BOXES == true && OT_POST_FORMATS == true ) { |
|
837 wp_enqueue_script( 'ot-postformats', OT_URL . 'assets/js/ot-postformats.js', array( 'jquery' ), '1.0.1' ); |
|
838 } |
|
839 |
|
558 /* load all the required scripts */ |
840 /* load all the required scripts */ |
559 wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'media-upload', 'thickbox' ), OT_VERSION ); |
841 wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'jquery-ui-slider', 'wp-color-picker', 'ace-editor', 'jquery-ui-datepicker', 'jquery-ui-timepicker' ), OT_VERSION ); |
560 |
842 |
561 /* create localized JS array */ |
843 /* create localized JS array */ |
562 $localized_array = array( |
844 $localized_array = array( |
563 'ajax' => admin_url( 'admin-ajax.php' ), |
845 'ajax' => admin_url( 'admin-ajax.php' ), |
564 'upload_text' => __( 'Send to OptionTree', 'option-tree' ), |
846 'upload_text' => apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) ), |
565 'remove_media_text' => __( 'Remove Media', 'option-tree' ), |
847 'remove_media_text' => __( 'Remove Media', 'option-tree' ), |
566 'reset_agree' => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), |
848 'reset_agree' => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), |
567 'remove_no' => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), |
849 'remove_no' => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), |
568 'remove_agree' => __( 'Are you sure you want to remove this?', 'option-tree' ), |
850 'remove_agree' => __( 'Are you sure you want to remove this?', 'option-tree' ), |
569 'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ), |
851 'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ), |
570 'setting_limit' => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ) |
852 'setting_limit' => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ), |
853 'delete' => __( 'Delete Gallery', 'option-tree' ), |
|
854 'edit' => __( 'Edit Gallery', 'option-tree' ), |
|
855 'create' => __( 'Create Gallery', 'option-tree' ), |
|
856 'confirm' => __( 'Are you sure you want to delete this Gallery?', 'option-tree' ), |
|
857 'date_current' => __( 'Today', 'option-tree' ), |
|
858 'date_time_current' => __( 'Now', 'option-tree' ), |
|
859 'date_close' => __( 'Close', 'option-tree' ), |
|
860 'replace' => __( 'Featured Image', 'option-tree' ), |
|
861 'with' => __( 'Image', 'option-tree' ) |
|
571 ); |
862 ); |
572 |
863 |
573 /* localized script attached to 'option_tree' */ |
864 /* localized script attached to 'option_tree' */ |
574 wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); |
865 wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); |
575 |
866 |
576 } |
867 /* execute scripts after actions */ |
577 |
868 do_action( 'ot_admin_scripts_after' ); |
578 } |
869 |
579 |
870 } |
580 /** |
871 |
581 * Returns the ID of a custom post type by post_name. |
872 } |
873 |
|
874 /** |
|
875 * Returns the ID of a custom post type by post_title. |
|
582 * |
876 * |
583 * @uses get_results() |
877 * @uses get_results() |
584 * |
878 * |
585 * @return int |
879 * @return int |
586 * |
880 * |
588 * @since 2.0 |
882 * @since 2.0 |
589 */ |
883 */ |
590 if ( ! function_exists( 'ot_get_media_post_ID' ) ) { |
884 if ( ! function_exists( 'ot_get_media_post_ID' ) ) { |
591 |
885 |
592 function ot_get_media_post_ID() { |
886 function ot_get_media_post_ID() { |
593 global $wpdb; |
887 |
594 |
888 // Option ID |
595 return $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_name` = 'media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" ); |
889 $option_id = 'ot_media_post_ID'; |
890 |
|
891 // Get the media post ID |
|
892 $post_ID = get_option( $option_id, false ); |
|
893 |
|
894 // Add $post_ID to the DB |
|
895 if ( $post_ID === false || empty( $post_ID ) ) { |
|
896 global $wpdb; |
|
897 |
|
898 // Get the media post ID |
|
899 $post_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_title` = 'Media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" ); |
|
900 |
|
901 // Add to the DB |
|
902 if ( $post_ID !== null ) |
|
903 update_option( $option_id, $post_ID ); |
|
904 |
|
905 } |
|
906 |
|
907 return $post_ID; |
|
596 |
908 |
597 } |
909 } |
598 |
910 |
599 } |
911 } |
600 |
912 |
610 */ |
922 */ |
611 if ( ! function_exists( 'ot_create_media_post' ) ) { |
923 if ( ! function_exists( 'ot_create_media_post' ) ) { |
612 |
924 |
613 function ot_create_media_post() { |
925 function ot_create_media_post() { |
614 |
926 |
615 register_post_type( 'option-tree', array( |
927 $regsiter_post_type = 'register_' . 'post_type'; |
928 $regsiter_post_type( 'option-tree', array( |
|
616 'labels' => array( 'name' => __( 'Option Tree', 'option-tree' ) ), |
929 'labels' => array( 'name' => __( 'Option Tree', 'option-tree' ) ), |
617 'public' => false, |
930 'public' => false, |
618 'show_ui' => false, |
931 'show_ui' => false, |
619 'capability_type' => 'post', |
932 'capability_type' => 'post', |
620 'exclude_from_search' => true, |
933 'exclude_from_search' => true, |
632 if ( $post_id == 0 ) { |
945 if ( $post_id == 0 ) { |
633 |
946 |
634 /* create post object */ |
947 /* create post object */ |
635 $_p = array(); |
948 $_p = array(); |
636 $_p['post_title'] = 'Media'; |
949 $_p['post_title'] = 'Media'; |
950 $_p['post_name'] = 'media'; |
|
637 $_p['post_status'] = 'private'; |
951 $_p['post_status'] = 'private'; |
638 $_p['post_type'] = 'option-tree'; |
952 $_p['post_type'] = 'option-tree'; |
639 $_p['comment_status'] = 'closed'; |
953 $_p['comment_status'] = 'closed'; |
640 $_p['ping_status'] = 'closed'; |
954 $_p['ping_status'] = 'closed'; |
641 |
955 |
657 * @since 2.0 |
971 * @since 2.0 |
658 */ |
972 */ |
659 if ( ! function_exists( 'ot_default_settings' ) ) { |
973 if ( ! function_exists( 'ot_default_settings' ) ) { |
660 |
974 |
661 function ot_default_settings() { |
975 function ot_default_settings() { |
662 global $wpdb, $table_prefix; |
976 global $wpdb; |
663 |
977 |
664 if ( ! get_option( 'option_tree_settings' ) ) { |
978 if ( ! get_option( ot_settings_id() ) ) { |
665 |
979 |
666 $section_count = 0; |
980 $section_count = 0; |
667 $settings_count = 0; |
981 $settings_count = 0; |
668 $settings = array(); |
982 $settings = array(); |
669 |
983 $table_name = $wpdb->prefix . 'option_tree'; |
670 if ( mysql_num_rows( mysql_query( "SHOW TABLES LIKE '{$table_prefix}option_tree'" ) ) == 1 && $old_settings = $wpdb->get_results( "SELECT * FROM {$table_prefix}option_tree ORDER BY item_sort ASC" ) ) { |
984 |
985 if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) == $table_name && $old_settings = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY item_sort ASC" ) ) { |
|
671 |
986 |
672 foreach ( $old_settings as $setting ) { |
987 foreach ( $old_settings as $setting ) { |
673 |
988 |
674 /* heading is a section now */ |
989 /* heading is a section now */ |
675 if ( $setting->item_type == 'heading' ) { |
990 if ( $setting->item_type == 'heading' ) { |
695 $settings['settings'][$settings_count]['std'] = ''; |
1010 $settings['settings'][$settings_count]['std'] = ''; |
696 $settings['settings'][$settings_count]['class'] = ''; |
1011 $settings['settings'][$settings_count]['class'] = ''; |
697 |
1012 |
698 /* textarea rows */ |
1013 /* textarea rows */ |
699 $rows = ''; |
1014 $rows = ''; |
700 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) { |
1015 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
701 if ( (int) $setting->item_options > 0 ) { |
1016 if ( (int) $setting->item_options > 0 ) { |
702 $rows = (int) $setting->item_options; |
1017 $rows = (int) $setting->item_options; |
703 } else { |
1018 } else { |
704 $rows = 15; |
1019 $rows = 15; |
705 } |
1020 } |
769 ); |
1084 ); |
770 |
1085 |
771 } |
1086 } |
772 |
1087 |
773 /* update the settings array */ |
1088 /* update the settings array */ |
774 update_option( 'option_tree_settings', $settings ); |
1089 update_option( ot_settings_id(), $settings ); |
775 |
1090 |
776 /* get option tree array */ |
1091 /* get option tree array */ |
777 $options = get_option( 'option_tree' ); |
1092 $options = get_option( ot_options_id() ); |
778 |
1093 |
779 /* validate options */ |
1094 /* validate options */ |
780 if ( is_array( $options ) ) { |
1095 if ( is_array( $options ) ) { |
781 |
1096 |
782 foreach( $settings['settings'] as $setting ) { |
1097 foreach( $settings['settings'] as $setting ) { |
793 |
1108 |
794 /* execute the action hook and pass the theme options to it */ |
1109 /* execute the action hook and pass the theme options to it */ |
795 do_action( 'ot_before_theme_options_save', $options ); |
1110 do_action( 'ot_before_theme_options_save', $options ); |
796 |
1111 |
797 /* update the option tree array */ |
1112 /* update the option tree array */ |
798 update_option( 'option_tree', $options ); |
1113 update_option( ot_options_id(), $options ); |
799 |
1114 |
800 } |
1115 } |
801 |
1116 |
802 } |
1117 } |
803 |
1118 |
816 if ( ! function_exists( 'ot_save_css' ) ) { |
1131 if ( ! function_exists( 'ot_save_css' ) ) { |
817 |
1132 |
818 function ot_save_css( $options ) { |
1133 function ot_save_css( $options ) { |
819 |
1134 |
820 /* grab a copy of the settings */ |
1135 /* grab a copy of the settings */ |
821 $settings = get_option( 'option_tree_settings' ); |
1136 $settings = get_option( ot_settings_id() ); |
822 |
1137 |
823 /* has settings */ |
1138 /* has settings */ |
824 if ( isset( $settings['settings'] ) ) { |
1139 if ( isset( $settings['settings'] ) ) { |
825 |
1140 |
826 /* loop through sections and insert CSS when needed */ |
1141 /* loop through sections and insert CSS when needed */ |
951 $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" ); |
1266 $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" ); |
952 wp_delete_attachment( $attachmentid, true ); |
1267 wp_delete_attachment( $attachmentid, true ); |
953 } |
1268 } |
954 |
1269 |
955 /* update settings */ |
1270 /* update settings */ |
956 update_option( 'option_tree_settings', $settings ); |
1271 update_option( ot_settings_id(), $settings ); |
957 |
1272 |
958 /* set message */ |
1273 /* set message */ |
959 $message = 'success'; |
1274 $message = 'success'; |
960 |
1275 |
961 } |
1276 } |
962 |
1277 |
963 /* redirect */ |
1278 /* redirect */ |
964 wp_redirect( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
1279 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
965 exit; |
1280 exit; |
966 |
1281 |
967 } |
1282 } |
968 |
1283 |
969 /* check and verify import settings nonce */ |
1284 /* check and verify import settings nonce */ |
975 /* default message */ |
1290 /* default message */ |
976 $message = 'failed'; |
1291 $message = 'failed'; |
977 |
1292 |
978 /* is array: save & show success message */ |
1293 /* is array: save & show success message */ |
979 if ( is_array( $textarea ) ) { |
1294 if ( is_array( $textarea ) ) { |
980 update_option( 'option_tree_settings', $textarea ); |
1295 update_option( ot_settings_id(), $textarea ); |
981 $message = 'success'; |
1296 $message = 'success'; |
982 } |
1297 } |
983 |
1298 |
984 /* redirect */ |
1299 /* redirect */ |
985 wp_redirect( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
1300 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
986 exit; |
1301 exit; |
987 |
1302 |
988 } |
1303 } |
989 |
1304 |
990 /* check and verify import theme options data nonce */ |
1305 /* check and verify import theme options data nonce */ |
995 |
1310 |
996 /* textarea value */ |
1311 /* textarea value */ |
997 $options = isset( $_POST['import_data'] ) ? unserialize( ot_decode( $_POST['import_data'] ) ) : ''; |
1312 $options = isset( $_POST['import_data'] ) ? unserialize( ot_decode( $_POST['import_data'] ) ) : ''; |
998 |
1313 |
999 /* get settings array */ |
1314 /* get settings array */ |
1000 $settings = get_option( 'option_tree_settings' ); |
1315 $settings = get_option( ot_settings_id() ); |
1001 |
1316 |
1002 /* has options */ |
1317 /* has options */ |
1003 if ( is_array( $options ) ) { |
1318 if ( is_array( $options ) ) { |
1004 |
1319 |
1005 /* validate options */ |
1320 /* validate options */ |
1021 |
1336 |
1022 /* execute the action hook and pass the theme options to it */ |
1337 /* execute the action hook and pass the theme options to it */ |
1023 do_action( 'ot_before_theme_options_save', $options ); |
1338 do_action( 'ot_before_theme_options_save', $options ); |
1024 |
1339 |
1025 /* update the option tree array */ |
1340 /* update the option tree array */ |
1026 update_option( 'option_tree', $options ); |
1341 update_option( ot_options_id(), $options ); |
1027 |
1342 |
1028 $message = 'success'; |
1343 $message = 'success'; |
1029 |
1344 |
1030 } |
1345 } |
1031 |
1346 |
1032 /* redirect accordingly */ |
1347 /* redirect accordingly */ |
1033 wp_redirect( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
1348 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1034 exit; |
1349 exit; |
1035 |
1350 |
1036 } |
1351 } |
1037 |
1352 |
1038 /* check and verify import layouts nonce */ |
1353 /* check and verify import layouts nonce */ |
1043 |
1358 |
1044 /* textarea value */ |
1359 /* textarea value */ |
1045 $layouts = isset( $_POST['import_layouts'] ) ? unserialize( ot_decode( $_POST['import_layouts'] ) ) : ''; |
1360 $layouts = isset( $_POST['import_layouts'] ) ? unserialize( ot_decode( $_POST['import_layouts'] ) ) : ''; |
1046 |
1361 |
1047 /* get settings array */ |
1362 /* get settings array */ |
1048 $settings = get_option( 'option_tree_settings' ); |
1363 $settings = get_option( ot_settings_id() ); |
1049 |
1364 |
1050 /* has layouts */ |
1365 /* has layouts */ |
1051 if ( is_array( $layouts ) ) { |
1366 if ( is_array( $layouts ) ) { |
1052 |
1367 |
1053 /* validate options */ |
1368 /* validate options */ |
1084 $new_options = unserialize( ot_decode( $layouts[$layouts['active_layout']] ) ); |
1399 $new_options = unserialize( ot_decode( $layouts[$layouts['active_layout']] ) ); |
1085 |
1400 |
1086 /* execute the action hook and pass the theme options to it */ |
1401 /* execute the action hook and pass the theme options to it */ |
1087 do_action( 'ot_before_theme_options_save', $new_options ); |
1402 do_action( 'ot_before_theme_options_save', $new_options ); |
1088 |
1403 |
1089 update_option( 'option_tree', $new_options ); |
1404 update_option( ot_options_id(), $new_options ); |
1090 |
1405 |
1091 } |
1406 } |
1092 |
1407 |
1093 /* update the option tree layouts array */ |
1408 /* update the option tree layouts array */ |
1094 update_option( 'option_tree_layouts', $layouts ); |
1409 update_option( ot_layouts_id(), $layouts ); |
1095 |
1410 |
1096 $message = 'success'; |
1411 $message = 'success'; |
1097 |
1412 |
1098 } |
1413 } |
1099 |
1414 |
1100 /* redirect accordingly */ |
1415 /* redirect accordingly */ |
1101 wp_redirect( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
1416 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1102 exit; |
1417 exit; |
1103 |
1418 |
1104 } |
1419 } |
1105 |
1420 |
1106 return false; |
1421 return false; |
1188 $settings['settings'][$settings_count]['std'] = ''; |
1503 $settings['settings'][$settings_count]['std'] = ''; |
1189 $settings['settings'][$settings_count]['class'] = ''; |
1504 $settings['settings'][$settings_count]['class'] = ''; |
1190 |
1505 |
1191 /* textarea rows */ |
1506 /* textarea rows */ |
1192 $rows = ''; |
1507 $rows = ''; |
1193 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) { |
1508 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
1194 if ( (int) $value->item_options > 0 ) { |
1509 if ( (int) $value->item_options > 0 ) { |
1195 $rows = (int) $value->item_options; |
1510 $rows = (int) $value->item_options; |
1196 } else { |
1511 } else { |
1197 $rows = 15; |
1512 $rows = 15; |
1198 } |
1513 } |
1257 $content = ''; |
1572 $content = ''; |
1258 $build_settings = ''; |
1573 $build_settings = ''; |
1259 $contextual_help = ''; |
1574 $contextual_help = ''; |
1260 $sections = ''; |
1575 $sections = ''; |
1261 $settings = ''; |
1576 $settings = ''; |
1262 $option_tree_settings = get_option( 'option_tree_settings', array() ); |
1577 $option_tree_settings = get_option( ot_settings_id(), array() ); |
1578 |
|
1579 // Domain string helper |
|
1580 function ot_I18n_string( $string ) { |
|
1581 if ( ! empty( $string ) && isset( $_POST['domain'] ) && ! empty( $_POST['domain'] ) ) { |
|
1582 $domain = str_replace( ' ', '-', trim( $_POST['domain'] ) ); |
|
1583 return "__( '$string', '$domain' )"; |
|
1584 } |
|
1585 return "'$string'"; |
|
1586 } |
|
1263 |
1587 |
1264 header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
1588 header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
1265 header( "Pragma: no-cache "); |
1589 header( "Pragma: no-cache "); |
1266 header( "Content-Description: File Transfer" ); |
1590 header( "Content-Description: File Transfer" ); |
1267 header( 'Content-Disposition: attachment; filename="theme-options.php"'); |
1591 header( 'Content-Disposition: attachment; filename="theme-options.php"'); |
1271 /* build contextual help content */ |
1595 /* build contextual help content */ |
1272 if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { |
1596 if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { |
1273 $help = ''; |
1597 $help = ''; |
1274 foreach( $option_tree_settings['contextual_help']['content'] as $value ) { |
1598 foreach( $option_tree_settings['contextual_help']['content'] as $value ) { |
1275 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1599 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1276 $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : ''; |
1600 $_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1277 $_content = isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : ''; |
1601 $_content = ot_I18n_string( isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : '' ); |
1278 $help.= " |
1602 $help.= " |
1279 array( |
1603 array( |
1280 'id' => '$_id', |
1604 'id' => '$_id', |
1281 'title' => '$_title', |
1605 'title' => $_title, |
1282 'content' => '$_content' |
1606 'content' => $_content |
1283 ),"; |
1607 ),"; |
1284 } |
1608 } |
1285 $help = substr_replace( $help, '' , -1 ); |
1609 $help = substr_replace( $help, '' , -1 ); |
1286 $contextual_help = " |
1610 $contextual_help = " |
1287 'content' => array( $help |
1611 'content' => array( $help |
1289 } |
1613 } |
1290 |
1614 |
1291 /* build contextual help sidebar */ |
1615 /* build contextual help sidebar */ |
1292 if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { |
1616 if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { |
1293 $contextual_help.= " |
1617 $contextual_help.= " |
1294 'sidebar' => '" . html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) . "'"; |
1618 'sidebar' => " . ot_I18n_string( html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) ); |
1295 } |
1619 } |
1296 |
1620 |
1297 /* check that $contexual_help has a value and add to $build_settings */ |
1621 /* check that $contexual_help has a value and add to $build_settings */ |
1298 if ( '' != $contextual_help ) { |
1622 if ( '' != $contextual_help ) { |
1299 $build_settings.= " |
1623 $build_settings.= " |
1303 |
1627 |
1304 /* build sections */ |
1628 /* build sections */ |
1305 if ( isset( $option_tree_settings['sections'] ) ) { |
1629 if ( isset( $option_tree_settings['sections'] ) ) { |
1306 foreach( $option_tree_settings['sections'] as $value ) { |
1630 foreach( $option_tree_settings['sections'] as $value ) { |
1307 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1631 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1308 $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : ''; |
1632 $_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1309 $sections.= " |
1633 $sections.= " |
1310 array( |
1634 array( |
1311 'id' => '$_id', |
1635 'id' => '$_id', |
1312 'title' => '$_title' |
1636 'title' => $_title |
1313 ),"; |
1637 ),"; |
1314 } |
1638 } |
1315 $sections = substr_replace( $sections, '' , -1 ); |
1639 $sections = substr_replace( $sections, '' , -1 ); |
1316 } |
1640 } |
1317 |
1641 |
1324 |
1648 |
1325 /* build settings */ |
1649 /* build settings */ |
1326 if ( isset( $option_tree_settings['settings'] ) ) { |
1650 if ( isset( $option_tree_settings['settings'] ) ) { |
1327 foreach( $option_tree_settings['settings'] as $value ) { |
1651 foreach( $option_tree_settings['settings'] as $value ) { |
1328 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1652 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1329 $_label = isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : ''; |
1653 $_label = ot_I18n_string( isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '' ); |
1330 $_desc = isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : ''; |
1654 $_desc = ot_I18n_string( isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '' ); |
1331 $_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : ''; |
1655 $_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : ''; |
1332 $_type = isset( $value['type'] ) ? $value['type'] : ''; |
1656 $_type = isset( $value['type'] ) ? $value['type'] : ''; |
1333 $_section = isset( $value['section'] ) ? $value['section'] : ''; |
1657 $_section = isset( $value['section'] ) ? $value['section'] : ''; |
1334 $_rows = isset( $value['rows'] ) ? $value['rows'] : ''; |
1658 $_rows = isset( $value['rows'] ) ? $value['rows'] : ''; |
1335 $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; |
1659 $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; |
1336 $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; |
1660 $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; |
1337 $_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : ''; |
1661 $_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : ''; |
1338 $_class = isset( $value['class'] ) ? $value['class'] : ''; |
1662 $_class = isset( $value['class'] ) ? $value['class'] : ''; |
1663 $_condition = isset( $value['condition'] ) ? $value['condition'] : ''; |
|
1664 $_operator = isset( $value['operator'] ) ? $value['operator'] : ''; |
|
1339 |
1665 |
1340 $choices = ''; |
1666 $choices = ''; |
1341 if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { |
1667 if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { |
1342 foreach( $value['choices'] as $choice ) { |
1668 foreach( $value['choices'] as $choice ) { |
1343 $_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : ''; |
1669 $_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : ''; |
1344 $_choice_label = isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : ''; |
1670 $_choice_label = ot_I18n_string( isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '' ); |
1345 $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; |
1671 $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; |
1346 $choices.= " |
1672 $choices.= " |
1347 array( |
1673 array( |
1348 'value' => '$_choice_value', |
1674 'value' => '$_choice_value', |
1349 'label' => '$_choice_label', |
1675 'label' => $_choice_label, |
1350 'src' => '$_choice_src' |
1676 'src' => '$_choice_src' |
1351 ),"; |
1677 ),"; |
1352 } |
1678 } |
1353 $choices = substr_replace( $choices, '' , -1 ); |
1679 $choices = substr_replace( $choices, '' , -1 ); |
1354 $choices = ", |
1680 $choices = ", |
1355 'choices' => array( $choices |
1681 'choices' => array( $choices |
1356 ),"; |
1682 )"; |
1357 } |
1683 } |
1358 |
1684 |
1359 $std = "'$_std'"; |
1685 $std = "'$_std'"; |
1360 if ( is_array( $_std ) ) { |
1686 if ( is_array( $_std ) ) { |
1361 $std_array = array(); |
1687 $std_array = array(); |
1369 |
1695 |
1370 $setting_settings = ''; |
1696 $setting_settings = ''; |
1371 if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { |
1697 if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { |
1372 foreach( $value['settings'] as $setting ) { |
1698 foreach( $value['settings'] as $setting ) { |
1373 $_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; |
1699 $_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; |
1374 $_setting_label = isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : ''; |
1700 $_setting_label = ot_I18n_string( isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '' ); |
1375 $_setting_desc = isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : ''; |
1701 $_setting_desc = ot_I18n_string( isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '' ); |
1376 $_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; |
1702 $_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; |
1377 $_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; |
1703 $_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; |
1378 $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; |
1704 $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; |
1379 $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; |
1705 $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; |
1380 $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; |
1706 $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; |
1381 $_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : ''; |
1707 $_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : ''; |
1382 $_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; |
1708 $_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; |
1709 $_setting_condition = isset( $setting['condition'] ) ? $setting['condition'] : ''; |
|
1710 $_setting_operator = isset( $setting['operator'] ) ? $setting['operator'] : ''; |
|
1383 |
1711 |
1384 $setting_choices = ''; |
1712 $setting_choices = ''; |
1385 if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { |
1713 if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { |
1386 foreach( $setting['choices'] as $setting_choice ) { |
1714 foreach( $setting['choices'] as $setting_choice ) { |
1387 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; |
1715 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; |
1388 $_setting_choice_label = isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : ''; |
1716 $_setting_choice_label = ot_I18n_string( isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '' ); |
1389 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; |
1717 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; |
1390 $setting_choices.= " |
1718 $setting_choices.= " |
1391 array( |
1719 array( |
1392 'value' => '$_setting_choice_value', |
1720 'value' => '$_setting_choice_value', |
1393 'label' => '$_setting_choice_label', |
1721 'label' => $_setting_choice_label, |
1394 'src' => '$_setting_choice_src' |
1722 'src' => '$_setting_choice_src' |
1395 ),"; |
1723 ),"; |
1396 } |
1724 } |
1397 $setting_choices = substr_replace( $setting_choices, '' , -1 ); |
1725 $setting_choices = substr_replace( $setting_choices, '' , -1 ); |
1398 $setting_choices = ", |
1726 $setting_choices = ", |
1399 'choices' => array( $setting_choices |
1727 'choices' => array( $setting_choices |
1400 ),"; |
1728 )"; |
1401 } |
1729 } |
1402 |
1730 |
1403 $setting_std = "'$_setting_std'"; |
1731 $setting_std = "'$_setting_std'"; |
1404 if ( is_array( $_setting_std ) ) { |
1732 if ( is_array( $_setting_std ) ) { |
1405 $setting_std_array = array(); |
1733 $setting_std_array = array(); |
1412 } |
1740 } |
1413 |
1741 |
1414 $setting_settings.= " |
1742 $setting_settings.= " |
1415 array( |
1743 array( |
1416 'id' => '$_setting_id', |
1744 'id' => '$_setting_id', |
1417 'label' => '$_setting_label', |
1745 'label' => $_setting_label, |
1418 'desc' => '$_setting_desc', |
1746 'desc' => $_setting_desc, |
1419 'std' => $setting_std, |
1747 'std' => $setting_std, |
1420 'type' => '$_setting_type', |
1748 'type' => '$_setting_type', |
1421 'rows' => '$_setting_rows', |
1749 'rows' => '$_setting_rows', |
1422 'post_type' => '$_setting_post_type', |
1750 'post_type' => '$_setting_post_type', |
1423 'taxonomy' => '$_setting_taxonomy', |
1751 'taxonomy' => '$_setting_taxonomy', |
1424 'min_max_step'=> '$_setting_min_max_step', |
1752 'min_max_step'=> '$_setting_min_max_step', |
1425 'class' => '$_setting_class'$setting_choices |
1753 'class' => '$_setting_class', |
1754 'condition' => '$_setting_condition', |
|
1755 'operator' => '$_setting_operator'$setting_choices |
|
1426 ),"; |
1756 ),"; |
1427 } |
1757 } |
1428 $setting_settings = substr_replace( $setting_settings, '' , -1 ); |
1758 $setting_settings = substr_replace( $setting_settings, '' , -1 ); |
1429 $setting_settings = ", |
1759 $setting_settings = ", |
1430 'settings' => array( $setting_settings |
1760 'settings' => array( $setting_settings |
1432 } |
1762 } |
1433 |
1763 |
1434 $settings.= " |
1764 $settings.= " |
1435 array( |
1765 array( |
1436 'id' => '$_id', |
1766 'id' => '$_id', |
1437 'label' => '$_label', |
1767 'label' => $_label, |
1438 'desc' => '$_desc', |
1768 'desc' => $_desc, |
1439 'std' => $std, |
1769 'std' => $std, |
1440 'type' => '$_type', |
1770 'type' => '$_type', |
1441 'section' => '$_section', |
1771 'section' => '$_section', |
1442 'rows' => '$_rows', |
1772 'rows' => '$_rows', |
1443 'post_type' => '$_post_type', |
1773 'post_type' => '$_post_type', |
1444 'taxonomy' => '$_taxonomy', |
1774 'taxonomy' => '$_taxonomy', |
1445 'min_max_step'=> '$_min_max_step', |
1775 'min_max_step'=> '$_min_max_step', |
1446 'class' => '$_class'$choices$setting_settings |
1776 'class' => '$_class', |
1777 'condition' => '$_condition', |
|
1778 'operator' => '$_operator'$choices$setting_settings |
|
1447 ),"; |
1779 ),"; |
1448 } |
1780 } |
1449 $settings = substr_replace( $settings, '' , -1 ); |
1781 $settings = substr_replace( $settings, '' , -1 ); |
1450 } |
1782 } |
1451 |
1783 |
1458 |
1790 |
1459 $content.= "<?php |
1791 $content.= "<?php |
1460 /** |
1792 /** |
1461 * Initialize the custom theme options. |
1793 * Initialize the custom theme options. |
1462 */ |
1794 */ |
1463 add_action( 'admin_init', 'custom_theme_options' ); |
1795 add_action( 'init', 'custom_theme_options' ); |
1464 |
1796 |
1465 /** |
1797 /** |
1466 * Build the custom settings & update OptionTree. |
1798 * Build the custom settings & update OptionTree. |
1467 */ |
1799 */ |
1468 function custom_theme_options() { |
1800 function custom_theme_options() { |
1801 |
|
1802 /* OptionTree is not loaded yet, or this is not an admin request */ |
|
1803 if ( ! function_exists( 'ot_settings_id' ) || ! is_admin() ) |
|
1804 return false; |
|
1805 |
|
1469 /** |
1806 /** |
1470 * Get a copy of the saved settings array. |
1807 * Get a copy of the saved settings array. |
1471 */ |
1808 */ |
1472 \$saved_settings = get_option( 'option_tree_settings', array() ); |
1809 \$saved_settings = get_option( ot_settings_id(), array() ); |
1473 |
1810 |
1474 /** |
1811 /** |
1475 * Custom settings array that will eventually be |
1812 * Custom settings array that will eventually be |
1476 * passes to the OptionTree Settings API Class. |
1813 * passes to the OptionTree Settings API Class. |
1477 */ |
1814 */ |
1478 \$custom_settings = array( $build_settings |
1815 \$custom_settings = array( $build_settings |
1479 ); |
1816 ); |
1480 |
1817 |
1481 /* allow settings to be filtered before saving */ |
1818 /* allow settings to be filtered before saving */ |
1482 \$custom_settings = apply_filters( 'option_tree_settings_args', \$custom_settings ); |
1819 \$custom_settings = apply_filters( ot_settings_id() . '_args', \$custom_settings ); |
1483 |
1820 |
1484 /* settings are not the same update the DB */ |
1821 /* settings are not the same update the DB */ |
1485 if ( \$saved_settings !== \$custom_settings ) { |
1822 if ( \$saved_settings !== \$custom_settings ) { |
1486 update_option( 'option_tree_settings', \$custom_settings ); |
1823 update_option( ot_settings_id(), \$custom_settings ); |
1487 } |
1824 } |
1825 |
|
1826 /* Lets OptionTree know the UI Builder is being overridden */ |
|
1827 global \$ot_has_custom_theme_options; |
|
1828 \$ot_has_custom_theme_options = true; |
|
1488 |
1829 |
1489 }"; |
1830 }"; |
1490 |
1831 |
1491 echo $content; |
1832 echo $content; |
1492 die(); |
1833 die(); |
1508 |
1849 |
1509 /* check and verify import settings nonce */ |
1850 /* check and verify import settings nonce */ |
1510 if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) { |
1851 if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) { |
1511 |
1852 |
1512 /* settings value */ |
1853 /* settings value */ |
1513 $settings = isset( $_POST['option_tree_settings'] ) ? $_POST['option_tree_settings'] : ''; |
1854 $settings = isset( $_POST[ot_settings_id()] ) ? $_POST[ot_settings_id()] : ''; |
1514 |
1855 |
1515 /* validate sections */ |
1856 /* validate sections */ |
1516 if ( isset( $settings['sections'] ) ) { |
1857 if ( isset( $settings['sections'] ) ) { |
1517 |
1858 |
1518 /* fix numeric keys since drag & drop will change them */ |
1859 /* fix numeric keys since drag & drop will change them */ |
1632 if ( is_array( $settings ) ) { |
1973 if ( is_array( $settings ) ) { |
1633 |
1974 |
1634 /* WPML unregister ID's that have been removed */ |
1975 /* WPML unregister ID's that have been removed */ |
1635 if ( function_exists( 'icl_unregister_string' ) ) { |
1976 if ( function_exists( 'icl_unregister_string' ) ) { |
1636 |
1977 |
1637 $current = get_option( 'option_tree_settings' ); |
1978 $current = get_option( ot_settings_id() ); |
1638 $options = get_option( 'option_tree' ); |
1979 $options = get_option( ot_options_id() ); |
1639 |
1980 |
1640 if ( isset( $current['settings'] ) ) { |
1981 if ( isset( $current['settings'] ) ) { |
1641 |
1982 |
1642 /* Empty ID array */ |
1983 /* Empty ID array */ |
1643 $new_ids = array(); |
1984 $new_ids = array(); |
1657 foreach( $current['settings'] as $current_setting ) { |
1998 foreach( $current['settings'] as $current_setting ) { |
1658 |
1999 |
1659 if ( ! in_array( $current_setting['id'], $new_ids ) ) { |
2000 if ( ! in_array( $current_setting['id'], $new_ids ) ) { |
1660 |
2001 |
1661 if ( ! empty( $options[$current_setting['id']] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ) ) ) { |
2002 if ( ! empty( $options[$current_setting['id']] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ) ) ) { |
2003 |
|
2004 foreach( $options[$current_setting['id']] as $key => $value ) { |
|
2005 |
|
2006 foreach( $value as $ckey => $cvalue ) { |
|
2007 |
|
2008 ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
|
2009 |
|
2010 } |
|
2011 |
|
2012 } |
|
2013 |
|
2014 } else if ( ! empty( $options[$current_setting['id']] ) && $current_setting['type'] == 'social-icons' ) { |
|
1662 |
2015 |
1663 foreach( $options[$current_setting['id']] as $key => $value ) { |
2016 foreach( $options[$current_setting['id']] as $key => $value ) { |
1664 |
2017 |
1665 foreach( $value as $ckey => $cvalue ) { |
2018 foreach( $value as $ckey => $cvalue ) { |
1666 |
2019 |
1682 |
2035 |
1683 } |
2036 } |
1684 |
2037 |
1685 } |
2038 } |
1686 |
2039 |
1687 update_option( 'option_tree_settings', $settings ); |
2040 update_option( ot_settings_id(), $settings ); |
1688 $message = 'success'; |
2041 $message = 'success'; |
1689 |
2042 |
1690 } |
2043 } |
1691 |
2044 |
1692 /* redirect */ |
2045 /* redirect */ |
1693 wp_redirect( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
2046 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1694 exit; |
2047 exit; |
1695 |
2048 |
1696 } |
2049 } |
1697 |
2050 |
1698 return false; |
2051 return false; |
1831 |
2184 |
1832 /* check and verify modify layouts nonce */ |
2185 /* check and verify modify layouts nonce */ |
1833 if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) { |
2186 if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) { |
1834 |
2187 |
1835 /* previous layouts value */ |
2188 /* previous layouts value */ |
1836 $option_tree_layouts = get_option( 'option_tree_layouts' ); |
2189 $option_tree_layouts = get_option( ot_layouts_id() ); |
1837 |
2190 |
1838 /* new layouts value */ |
2191 /* new layouts value */ |
1839 $layouts = isset( $_POST['option_tree_layouts'] ) ? $_POST['option_tree_layouts'] : ''; |
2192 $layouts = isset( $_POST[ot_layouts_id()] ) ? $_POST[ot_layouts_id()] : ''; |
1840 |
2193 |
1841 /* rebuild layout array */ |
2194 /* rebuild layout array */ |
1842 $rebuild = array(); |
2195 $rebuild = array(); |
1843 |
2196 |
1844 /* validate layouts */ |
2197 /* validate layouts */ |
1850 } |
2203 } |
1851 |
2204 |
1852 /* add new and overwrite active layout */ |
2205 /* add new and overwrite active layout */ |
1853 if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) { |
2206 if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) { |
1854 $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); |
2207 $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); |
1855 $rebuild[$rebuild['active_layout']] = ot_encode( serialize( get_option( 'option_tree' ) ) ); |
2208 $rebuild[$rebuild['active_layout']] = ot_encode( serialize( get_option( ot_options_id() ) ) ); |
1856 } |
2209 } |
1857 |
2210 |
1858 $first_layout = ''; |
2211 $first_layout = ''; |
1859 |
2212 |
1860 /* loop through layouts */ |
2213 /* loop through layouts */ |
1891 if ( is_array( $rebuild_option_tree ) ) { |
2244 if ( is_array( $rebuild_option_tree ) ) { |
1892 |
2245 |
1893 /* execute the action hook and pass the theme options to it */ |
2246 /* execute the action hook and pass the theme options to it */ |
1894 do_action( 'ot_before_theme_options_save', $rebuild_option_tree ); |
2247 do_action( 'ot_before_theme_options_save', $rebuild_option_tree ); |
1895 |
2248 |
1896 update_option( 'option_tree', $rebuild_option_tree ); |
2249 update_option( ot_options_id(), $rebuild_option_tree ); |
1897 |
2250 |
1898 } |
2251 } |
1899 |
2252 |
1900 /* rebuild the layouts */ |
2253 /* rebuild the layouts */ |
1901 update_option( 'option_tree_layouts', $rebuild ); |
2254 update_option( ot_layouts_id(), $rebuild ); |
1902 |
2255 |
1903 /* change message */ |
2256 /* change message */ |
1904 $message = 'success'; |
2257 $message = 'success'; |
1905 |
2258 |
1906 } else if ( count( $rebuild ) <= 1 ) { |
2259 } else if ( count( $rebuild ) <= 1 ) { |
1907 |
2260 |
1908 /* delete layouts option */ |
2261 /* delete layouts option */ |
1909 delete_option( 'option_tree_layouts' ); |
2262 delete_option( ot_layouts_id() ); |
1910 |
2263 |
1911 /* change message */ |
2264 /* change message */ |
1912 $message = 'deleted'; |
2265 $message = 'deleted'; |
1913 |
2266 |
1914 } |
2267 } |
1915 |
2268 |
1916 /* redirect */ |
2269 /* redirect */ |
1917 if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) { |
2270 if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) { |
1918 $query_args = add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) ); |
2271 $query_args = esc_url_raw( add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) ) ); |
1919 } else { |
2272 } else { |
1920 $query_args = add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ); |
2273 $query_args = esc_url_raw( add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
1921 } |
2274 } |
1922 wp_redirect( $query_args ); |
2275 wp_redirect( $query_args ); |
1923 exit; |
2276 exit; |
1924 |
2277 |
1925 } |
2278 } |
1943 |
2296 |
1944 function ot_alert_message( $page = array() ) { |
2297 function ot_alert_message( $page = array() ) { |
1945 |
2298 |
1946 if ( empty( $page ) ) |
2299 if ( empty( $page ) ) |
1947 return false; |
2300 return false; |
2301 |
|
2302 $before = apply_filters( 'ot_before_page_messages', '', $page ); |
|
2303 |
|
2304 if ( $before ) { |
|
2305 return $before; |
|
2306 } |
|
1948 |
2307 |
1949 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; |
2308 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; |
1950 $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : ''; |
2309 $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : ''; |
1951 $updated = isset( $_REQUEST['settings-updated'] ) ? $_REQUEST['settings-updated'] : ''; |
2310 $updated = isset( $_REQUEST['settings-updated'] ) ? $_REQUEST['settings-updated'] : ''; |
1952 |
2311 |
2021 |
2380 |
2022 return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>'; |
2381 return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>'; |
2023 |
2382 |
2024 } |
2383 } |
2025 |
2384 |
2026 do_action( 'ot_custom_page_messages' ); |
2385 do_action( 'ot_custom_page_messages', $page ); |
2027 |
2386 |
2028 if ( $updated == 'true' ) { |
2387 if ( $updated == 'true' ) { |
2029 |
2388 |
2030 return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>'; |
2389 return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>'; |
2031 |
2390 |
2052 if ( ! function_exists( 'ot_option_types_array' ) ) { |
2411 if ( ! function_exists( 'ot_option_types_array' ) ) { |
2053 |
2412 |
2054 function ot_option_types_array() { |
2413 function ot_option_types_array() { |
2055 |
2414 |
2056 return apply_filters( 'ot_option_types_array', array( |
2415 return apply_filters( 'ot_option_types_array', array( |
2057 'background' => 'Background', |
2416 'background' => __('Background', 'option-tree'), |
2058 'category-checkbox' => 'Category Checkbox', |
2417 'border' => __('Border', 'option-tree'), |
2059 'category-select' => 'Category Select', |
2418 'box-shadow' => __('Box Shadow', 'option-tree'), |
2060 'checkbox' => 'Checkbox', |
2419 'category-checkbox' => __('Category Checkbox', 'option-tree'), |
2061 'colorpicker' => 'Colorpicker', |
2420 'category-select' => __('Category Select', 'option-tree'), |
2062 'css' => 'CSS', |
2421 'checkbox' => __('Checkbox', 'option-tree'), |
2063 'custom-post-type-checkbox' => 'Custom Post Type Checkbox', |
2422 'colorpicker' => __('Colorpicker', 'option-tree'), |
2064 'custom-post-type-select' => 'Custom Post Type Select', |
2423 'colorpicker-opacity' => __('Colorpicker Opacity', 'option-tree'), |
2065 'list-item' => 'List Item', |
2424 'css' => __('CSS', 'option-tree'), |
2066 'measurement' => 'Measurement', |
2425 'custom-post-type-checkbox' => __('Custom Post Type Checkbox', 'option-tree'), |
2067 'numeric-slider' => 'Numeric Slider', |
2426 'custom-post-type-select' => __('Custom Post Type Select', 'option-tree'), |
2068 'page-checkbox' => 'Page Checkbox', |
2427 'date-picker' => __('Date Picker', 'option-tree'), |
2069 'page-select' => 'Page Select', |
2428 'date-time-picker' => __('Date Time Picker', 'option-tree'), |
2070 'post-checkbox' => 'Post Checkbox', |
2429 'dimension' => __('Dimension', 'option-tree'), |
2071 'post-select' => 'Post Select', |
2430 'gallery' => __('Gallery', 'option-tree'), |
2072 'radio' => 'Radio', |
2431 'google-fonts' => __('Google Fonts', 'option-tree'), |
2073 'radio-image' => 'Radio Image', |
2432 'javascript' => __('JavaScript', 'option-tree'), |
2074 'select' => 'Select', |
2433 'link-color' => __('Link Color', 'option-tree'), |
2075 'sidebar-select' => 'Sidebar Select', |
2434 'list-item' => __('List Item', 'option-tree'), |
2076 'slider' => 'Slider', |
2435 'measurement' => __('Measurement', 'option-tree'), |
2077 'tag-checkbox' => 'Tag Checkbox', |
2436 'numeric-slider' => __('Numeric Slider', 'option-tree'), |
2078 'tag-select' => 'Tag Select', |
2437 'on-off' => __('On/Off', 'option-tree'), |
2079 'taxonomy-checkbox' => 'Taxonomy Checkbox', |
2438 'page-checkbox' => __('Page Checkbox', 'option-tree'), |
2080 'taxonomy-select' => 'Taxonomy Select', |
2439 'page-select' => __('Page Select', 'option-tree'), |
2081 'text' => 'Text', |
2440 'post-checkbox' => __('Post Checkbox', 'option-tree'), |
2082 'textarea' => 'Textarea', |
2441 'post-select' => __('Post Select', 'option-tree'), |
2083 'textarea-simple' => 'Textarea Simple', |
2442 'radio' => __('Radio', 'option-tree'), |
2084 'textblock' => 'Textblock', |
2443 'radio-image' => __('Radio Image', 'option-tree'), |
2085 'textblock-titled' => 'Textblock Titled', |
2444 'select' => __('Select', 'option-tree'), |
2086 'typography' => 'Typography', |
2445 'sidebar-select' => __('Sidebar Select', 'option-tree'), |
2087 'upload' => 'Upload' |
2446 'slider' => __('Slider', 'option-tree'), |
2447 'social-links' => __('Social Links', 'option-tree'), |
|
2448 'spacing' => __('Spacing', 'option-tree'), |
|
2449 'tab' => __('Tab', 'option-tree'), |
|
2450 'tag-checkbox' => __('Tag Checkbox', 'option-tree'), |
|
2451 'tag-select' => __('Tag Select', 'option-tree'), |
|
2452 'taxonomy-checkbox' => __('Taxonomy Checkbox', 'option-tree'), |
|
2453 'taxonomy-select' => __('Taxonomy Select', 'option-tree'), |
|
2454 'text' => __('Text', 'option-tree'), |
|
2455 'textarea' => __('Textarea', 'option-tree'), |
|
2456 'textarea-simple' => __('Textarea Simple', 'option-tree'), |
|
2457 'textblock' => __('Textblock', 'option-tree'), |
|
2458 'textblock-titled' => __('Textblock Titled', 'option-tree'), |
|
2459 'typography' => __('Typography', 'option-tree'), |
|
2460 'upload' => __('Upload', 'option-tree') |
|
2088 ) ); |
2461 ) ); |
2089 |
2462 |
2090 } |
2463 } |
2091 } |
2464 } |
2092 |
2465 |
2140 |
2513 |
2141 } |
2514 } |
2142 } |
2515 } |
2143 |
2516 |
2144 /** |
2517 /** |
2518 * Filters the typography font-family to add Google fonts dynamically. |
|
2519 * |
|
2520 * @param array $families An array of all recognized font families. |
|
2521 * @param string $field_id ID of the feild being filtered. |
|
2522 * @return array |
|
2523 * |
|
2524 * @access public |
|
2525 * @since 2.5.0 |
|
2526 */ |
|
2527 function ot_google_font_stack( $families, $field_id ) { |
|
2528 |
|
2529 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
2530 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
2531 |
|
2532 if ( ! empty( $ot_set_google_fonts ) ) { |
|
2533 foreach( $ot_set_google_fonts as $id => $sets ) { |
|
2534 foreach( $sets as $value ) { |
|
2535 $family = isset( $value['family'] ) ? $value['family'] : ''; |
|
2536 if ( $family && isset( $ot_google_fonts[$family] ) ) { |
|
2537 $spaces = explode(' ', $ot_google_fonts[$family]['family'] ); |
|
2538 $font_stack = count( $spaces ) > 1 ? '"' . $ot_google_fonts[$family]['family'] . '"': $ot_google_fonts[$family]['family']; |
|
2539 $families[$family] = apply_filters( 'ot_google_font_stack', $font_stack, $family, $field_id ); |
|
2540 } |
|
2541 } |
|
2542 } |
|
2543 } |
|
2544 |
|
2545 return $families; |
|
2546 } |
|
2547 add_filter( 'ot_recognized_font_families', 'ot_google_font_stack', 1, 2 ); |
|
2548 |
|
2549 /** |
|
2145 * Recognized font families |
2550 * Recognized font families |
2146 * |
2551 * |
2147 * Returns an array of all recognized font families. |
2552 * Returns an array of all recognized font families. |
2148 * Keys are intended to be stored in the database |
2553 * Keys are intended to be stored in the database |
2149 * while values are ready for display in html. |
2554 * while values are ready for display in html. |
2158 * @updated 2.0 |
2563 * @updated 2.0 |
2159 */ |
2564 */ |
2160 if ( ! function_exists( 'ot_recognized_font_families' ) ) { |
2565 if ( ! function_exists( 'ot_recognized_font_families' ) ) { |
2161 |
2566 |
2162 function ot_recognized_font_families( $field_id = '' ) { |
2567 function ot_recognized_font_families( $field_id = '' ) { |
2163 |
2568 |
2164 return apply_filters( 'ot_recognized_font_families', array( |
2569 $families = array( |
2165 'arial' => 'Arial', |
2570 'arial' => 'Arial', |
2166 'georgia' => 'Georgia', |
2571 'georgia' => 'Georgia', |
2167 'helvetica' => 'Helvetica', |
2572 'helvetica' => 'Helvetica', |
2168 'palatino' => 'Palatino', |
2573 'palatino' => 'Palatino', |
2169 'tahoma' => 'Tahoma', |
2574 'tahoma' => 'Tahoma', |
2170 'times' => '"Times New Roman", sans-serif', |
2575 'times' => '"Times New Roman", sans-serif', |
2171 'trebuchet' => 'Trebuchet', |
2576 'trebuchet' => 'Trebuchet', |
2172 'verdana' => 'Verdana' |
2577 'verdana' => 'Verdana' |
2173 ), $field_id ); |
2578 ); |
2579 |
|
2580 return apply_filters( 'ot_recognized_font_families', $families, $field_id ); |
|
2174 |
2581 |
2175 } |
2582 } |
2176 |
2583 |
2177 } |
2584 } |
2178 |
2585 |
2203 |
2610 |
2204 foreach( $range as $k => $v ) { |
2611 foreach( $range as $k => $v ) { |
2205 $range[$k] = $v . $unit; |
2612 $range[$k] = $v . $unit; |
2206 } |
2613 } |
2207 |
2614 |
2208 return $range; |
2615 return apply_filters( 'ot_recognized_font_sizes', $range, $field_id ); |
2209 } |
2616 } |
2210 |
2617 |
2211 } |
2618 } |
2212 |
2619 |
2213 /** |
2620 /** |
2333 |
2740 |
2334 foreach( $range as $k => $v ) { |
2741 foreach( $range as $k => $v ) { |
2335 $range[$k] = $v . $unit; |
2742 $range[$k] = $v . $unit; |
2336 } |
2743 } |
2337 |
2744 |
2338 return $range; |
2745 return apply_filters( 'ot_recognized_letter_spacing', $range, $field_id ); |
2339 } |
2746 } |
2340 |
2747 |
2341 } |
2748 } |
2342 |
2749 |
2343 /** |
2750 /** |
2358 function ot_recognized_line_heights( $field_id ) { |
2765 function ot_recognized_line_heights( $field_id ) { |
2359 |
2766 |
2360 $range = ot_range( |
2767 $range = ot_range( |
2361 apply_filters( 'ot_line_height_low_range', 0, $field_id ), |
2768 apply_filters( 'ot_line_height_low_range', 0, $field_id ), |
2362 apply_filters( 'ot_line_height_high_range', 150, $field_id ), |
2769 apply_filters( 'ot_line_height_high_range', 150, $field_id ), |
2363 apply_filters( 'ot_line_height_unit_type', 1, $field_id ) |
2770 apply_filters( 'ot_line_height_range_interval', 1, $field_id ) |
2364 ); |
2771 ); |
2365 |
2772 |
2366 $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id ); |
2773 $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id ); |
2367 |
2774 |
2368 foreach( $range as $k => $v ) { |
2775 foreach( $range as $k => $v ) { |
2369 $range[$k] = $v . $unit; |
2776 $range[$k] = $v . $unit; |
2370 } |
2777 } |
2371 |
2778 |
2372 return $range; |
2779 return apply_filters( 'ot_recognized_line_heights', $range, $field_id ); |
2373 } |
2780 } |
2374 |
2781 |
2375 } |
2782 } |
2376 |
2783 |
2377 /** |
2784 /** |
2521 "right top" => "Right Top", |
2928 "right top" => "Right Top", |
2522 "right center" => "Right Center", |
2929 "right center" => "Right Center", |
2523 "right bottom" => "Right Bottom" |
2930 "right bottom" => "Right Bottom" |
2524 ), $field_id ); |
2931 ), $field_id ); |
2525 |
2932 |
2933 } |
|
2934 |
|
2935 } |
|
2936 |
|
2937 /** |
|
2938 * Border Styles |
|
2939 * |
|
2940 * Returns an array of all available style types. |
|
2941 * |
|
2942 * @uses apply_filters() |
|
2943 * |
|
2944 * @return array |
|
2945 * |
|
2946 * @access public |
|
2947 * @since 2.5.0 |
|
2948 */ |
|
2949 if ( ! function_exists( 'ot_recognized_border_style_types' ) ) { |
|
2950 |
|
2951 function ot_recognized_border_style_types( $field_id = '' ) { |
|
2952 |
|
2953 return apply_filters( 'ot_recognized_border_style_types', array( |
|
2954 'hidden' => 'Hidden', |
|
2955 'dashed' => 'Dashed', |
|
2956 'solid' => 'Solid', |
|
2957 'double' => 'Double', |
|
2958 'groove' => 'Groove', |
|
2959 'ridge' => 'Ridge', |
|
2960 'inset' => 'Inset', |
|
2961 'outset' => 'Outset', |
|
2962 ), $field_id ); |
|
2963 |
|
2964 } |
|
2965 |
|
2966 } |
|
2967 |
|
2968 /** |
|
2969 * Border Units |
|
2970 * |
|
2971 * Returns an array of all available unit types. |
|
2972 * |
|
2973 * @uses apply_filters() |
|
2974 * |
|
2975 * @return array |
|
2976 * |
|
2977 * @access public |
|
2978 * @since 2.5.0 |
|
2979 */ |
|
2980 if ( ! function_exists( 'ot_recognized_border_unit_types' ) ) { |
|
2981 |
|
2982 function ot_recognized_border_unit_types( $field_id = '' ) { |
|
2983 |
|
2984 return apply_filters( 'ot_recognized_border_unit_types', array( |
|
2985 'px' => 'px', |
|
2986 '%' => '%', |
|
2987 'em' => 'em', |
|
2988 'pt' => 'pt' |
|
2989 ), $field_id ); |
|
2990 |
|
2991 } |
|
2992 |
|
2993 } |
|
2994 |
|
2995 /** |
|
2996 * Dimension Units |
|
2997 * |
|
2998 * Returns an array of all available unit types. |
|
2999 * |
|
3000 * @uses apply_filters() |
|
3001 * |
|
3002 * @return array |
|
3003 * |
|
3004 * @access public |
|
3005 * @since 2.5.0 |
|
3006 */ |
|
3007 if ( ! function_exists( 'ot_recognized_dimension_unit_types' ) ) { |
|
3008 |
|
3009 function ot_recognized_dimension_unit_types( $field_id = '' ) { |
|
3010 |
|
3011 return apply_filters( 'ot_recognized_dimension_unit_types', array( |
|
3012 'px' => 'px', |
|
3013 '%' => '%', |
|
3014 'em' => 'em', |
|
3015 'pt' => 'pt' |
|
3016 ), $field_id ); |
|
3017 |
|
3018 } |
|
3019 |
|
3020 } |
|
3021 |
|
3022 /** |
|
3023 * Spacing Units |
|
3024 * |
|
3025 * Returns an array of all available unit types. |
|
3026 * |
|
3027 * @uses apply_filters() |
|
3028 * |
|
3029 * @return array |
|
3030 * |
|
3031 * @access public |
|
3032 * @since 2.5.0 |
|
3033 */ |
|
3034 if ( ! function_exists( 'ot_recognized_spacing_unit_types' ) ) { |
|
3035 |
|
3036 function ot_recognized_spacing_unit_types( $field_id = '' ) { |
|
3037 |
|
3038 return apply_filters( 'ot_recognized_spacing_unit_types', array( |
|
3039 'px' => 'px', |
|
3040 '%' => '%', |
|
3041 'em' => 'em', |
|
3042 'pt' => 'pt' |
|
3043 ), $field_id ); |
|
3044 |
|
3045 } |
|
3046 |
|
3047 } |
|
3048 |
|
3049 /** |
|
3050 * Recognized Google font families |
|
3051 * |
|
3052 * @uses apply_filters() |
|
3053 * |
|
3054 * @return array |
|
3055 * |
|
3056 * @access public |
|
3057 * @since 2.5.0 |
|
3058 */ |
|
3059 if ( ! function_exists( 'ot_recognized_google_font_families' ) ) { |
|
3060 |
|
3061 function ot_recognized_google_font_families( $field_id ) { |
|
3062 |
|
3063 $families = array(); |
|
3064 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3065 |
|
3066 // Forces an array rebuild when we sitch themes |
|
3067 if ( empty( $ot_google_fonts ) ) { |
|
3068 $ot_google_fonts = ot_fetch_google_fonts( true, true ); |
|
3069 } |
|
3070 |
|
3071 foreach( (array) $ot_google_fonts as $key => $item ) { |
|
3072 |
|
3073 if ( isset( $item['family'] ) ) { |
|
3074 |
|
3075 $families[ $key ] = $item['family']; |
|
3076 |
|
3077 } |
|
3078 |
|
3079 } |
|
3080 |
|
3081 return apply_filters( 'ot_recognized_google_font_families', $families, $field_id ); |
|
3082 |
|
3083 } |
|
3084 |
|
3085 } |
|
3086 |
|
3087 /** |
|
3088 * Recognized Google font variants |
|
3089 * |
|
3090 * @uses apply_filters() |
|
3091 * |
|
3092 * @return array |
|
3093 * |
|
3094 * @access public |
|
3095 * @since 2.5.0 |
|
3096 */ |
|
3097 if ( ! function_exists( 'ot_recognized_google_font_variants' ) ) { |
|
3098 |
|
3099 function ot_recognized_google_font_variants( $field_id, $family ) { |
|
3100 |
|
3101 $variants = array(); |
|
3102 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3103 |
|
3104 if ( isset( $ot_google_fonts[ $family ]['variants'] ) ) { |
|
3105 |
|
3106 $variants = $ot_google_fonts[ $family ]['variants']; |
|
3107 |
|
3108 } |
|
3109 |
|
3110 return apply_filters( 'ot_recognized_google_font_variants', $variants, $field_id, $family ); |
|
3111 |
|
3112 } |
|
3113 |
|
3114 } |
|
3115 |
|
3116 /** |
|
3117 * Recognized Google font subsets |
|
3118 * |
|
3119 * @uses apply_filters() |
|
3120 * |
|
3121 * @return array |
|
3122 * |
|
3123 * @access public |
|
3124 * @since 2.5.0 |
|
3125 */ |
|
3126 if ( ! function_exists( 'ot_recognized_google_font_subsets' ) ) { |
|
3127 |
|
3128 function ot_recognized_google_font_subsets( $field_id, $family ) { |
|
3129 |
|
3130 $subsets = array(); |
|
3131 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3132 |
|
3133 if ( isset( $ot_google_fonts[ $family ]['subsets'] ) ) { |
|
3134 |
|
3135 $subsets = $ot_google_fonts[ $family ]['subsets']; |
|
3136 |
|
3137 } |
|
3138 |
|
3139 return apply_filters( 'ot_recognized_google_font_subsets', $subsets, $field_id, $family ); |
|
3140 |
|
2526 } |
3141 } |
2527 |
3142 |
2528 } |
3143 } |
2529 |
3144 |
2530 /** |
3145 /** |
2747 } |
3362 } |
2748 |
3363 |
2749 } |
3364 } |
2750 |
3365 |
2751 /** |
3366 /** |
3367 * Default Social Links Settings array. |
|
3368 * |
|
3369 * Returns an array of the default social links settings. |
|
3370 * You can filter this function to change the settings |
|
3371 * on a per option basis. |
|
3372 * |
|
3373 * @uses apply_filters() |
|
3374 * |
|
3375 * @return array |
|
3376 * |
|
3377 * @access public |
|
3378 * @since 2.4.0 |
|
3379 */ |
|
3380 if ( ! function_exists( 'ot_social_links_settings' ) ) { |
|
3381 |
|
3382 function ot_social_links_settings( $id ) { |
|
3383 |
|
3384 $settings = apply_filters( 'ot_social_links_settings', array( |
|
3385 array( |
|
3386 'id' => 'name', |
|
3387 'label' => __( 'Name', 'option-tree' ), |
|
3388 'desc' => __( 'Enter the name of the social website.', 'option-tree' ), |
|
3389 'std' => '', |
|
3390 'type' => 'text', |
|
3391 'class' => 'option-tree-setting-title' |
|
3392 ), |
|
3393 array( |
|
3394 'id' => 'title', |
|
3395 'label' => 'Title', |
|
3396 'desc' => __( 'Enter the text shown in the title attribute of the link.', 'option-tree' ), |
|
3397 'type' => 'text' |
|
3398 ), |
|
3399 array( |
|
3400 'id' => 'href', |
|
3401 'label' => 'Link', |
|
3402 'desc' => sprintf( __( 'Enter a link to the profile or page on the social website. Remember to add the %s part to the front of the link.', 'option-tree' ), '<code>http://</code>' ), |
|
3403 'type' => 'text', |
|
3404 ) |
|
3405 ), $id ); |
|
3406 |
|
3407 return $settings; |
|
3408 |
|
3409 } |
|
3410 |
|
3411 } |
|
3412 |
|
3413 /** |
|
2752 * Inserts CSS with field_id markers. |
3414 * Inserts CSS with field_id markers. |
2753 * |
3415 * |
2754 * Inserts CSS into a dynamic.css file, placing it between |
3416 * Inserts CSS into a dynamic.css file, placing it between |
2755 * BEGIN and END field_id markers. Replaces existing marked info, |
3417 * BEGIN and END field_id markers. Replaces existing marked info, |
2756 * but still retains surrounding data. |
3418 * but still retains surrounding data. |
2759 * @param array $options The current option_tree array. |
3421 * @param array $options The current option_tree array. |
2760 * @return bool True on write success, false on failure. |
3422 * @return bool True on write success, false on failure. |
2761 * |
3423 * |
2762 * @access public |
3424 * @access public |
2763 * @since 1.1.8 |
3425 * @since 1.1.8 |
2764 * @updated 2.0.12 |
3426 * @updated 2.5.3 |
2765 */ |
3427 */ |
2766 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) { |
3428 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) { |
2767 |
3429 |
2768 function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) { |
3430 function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) { |
2769 |
3431 |
2770 /* missing $field_id or $insertion exit early */ |
3432 /* missing $field_id or $insertion exit early */ |
2771 if ( '' == $field_id || '' == $insertion ) |
3433 if ( '' == $field_id || '' == $insertion ) |
2772 return; |
3434 return; |
2773 |
3435 |
2774 /* path to the dynamic.css file */ |
3436 /* path to the dynamic.css file */ |
2775 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
3437 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
2776 |
3438 if ( is_multisite() ) { |
3439 $multisite_filepath = get_stylesheet_directory() . '/dynamic-' . get_current_blog_id() . '.css'; |
|
3440 if ( file_exists( $multisite_filepath ) ) { |
|
3441 $filepath = $multisite_filepath; |
|
3442 } |
|
3443 } |
|
3444 |
|
2777 /* allow filter on path */ |
3445 /* allow filter on path */ |
2778 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
3446 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
2779 |
3447 |
2780 /* grab a copy of the paths array */ |
3448 /* grab a copy of the paths array */ |
2781 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
3449 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
2782 |
3450 if ( is_multisite() ) { |
3451 $ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
|
3452 } |
|
3453 |
|
2783 /* set the path for this field */ |
3454 /* set the path for this field */ |
2784 $ot_css_file_paths[$field_id] = $filepath; |
3455 $ot_css_file_paths[$field_id] = $filepath; |
2785 |
3456 |
2786 /* update the paths */ |
3457 /* update the paths */ |
2787 update_option( 'ot_css_file_paths', $ot_css_file_paths ); |
3458 if ( is_multisite() ) { |
2788 |
3459 update_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
3460 } else { |
|
3461 update_option( 'ot_css_file_paths', $ot_css_file_paths ); |
|
3462 } |
|
3463 |
|
2789 /* insert CSS into file */ |
3464 /* insert CSS into file */ |
2790 if ( file_exists( $filepath ) ) { |
3465 if ( file_exists( $filepath ) ) { |
2791 |
3466 |
2792 $insertion = ot_normalize_css( $insertion ); |
3467 $insertion = ot_normalize_css( $insertion ); |
2793 $regex = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/"; |
3468 $regex = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/"; |
2794 $marker = $field_id; |
3469 $marker = $field_id; |
2795 |
3470 |
2796 /* Match custom CSS */ |
3471 /* Match custom CSS */ |
2797 preg_match_all( $regex, $insertion, $matches ); |
3472 preg_match_all( $regex, $insertion, $matches ); |
2798 |
3473 |
2799 /* Loop through CSS */ |
3474 /* Loop through CSS */ |
2800 foreach( $matches[0] as $option ) { |
3475 foreach( $matches[0] as $option ) { |
2801 |
3476 |
2802 $value = ''; |
3477 $value = ''; |
2803 $option_id = str_replace( array( '{{', '}}' ), '', $option ); |
3478 $option_array = explode( '|', str_replace( array( '{{', '}}' ), '', $option ) ); |
2804 $option_array = explode( '|', $option_id ); |
3479 $option_id = isset( $option_array[0] ) ? $option_array[0] : ''; |
2805 |
3480 $option_key = isset( $option_array[1] ) ? $option_array[1] : ''; |
2806 /* get the array value */ |
3481 $option_type = ot_get_option_type_by_id( $option_id ); |
3482 $fallback = ''; |
|
3483 |
|
3484 // Get the meta array value |
|
2807 if ( $meta ) { |
3485 if ( $meta ) { |
2808 global $post; |
3486 global $post; |
2809 |
3487 |
2810 $value = get_post_meta( $post->ID, $option_array[0], true ); |
3488 $value = get_post_meta( $post->ID, $option_id, true ); |
2811 |
3489 |
3490 // Get the options array value |
|
2812 } else { |
3491 } else { |
2813 |
3492 |
2814 $options = get_option( 'option_tree' ); |
3493 $options = get_option( ot_options_id() ); |
2815 |
3494 |
2816 if ( isset( $options[$option_array[0]] ) ) { |
3495 if ( isset( $options[$option_id] ) ) { |
2817 |
3496 |
2818 $value = $options[$option_array[0]]; |
3497 $value = $options[$option_id]; |
2819 |
3498 |
2820 } |
3499 } |
2821 |
3500 |
2822 } |
3501 } |
2823 |
3502 |
3503 // This in an array of values |
|
2824 if ( is_array( $value ) ) { |
3504 if ( is_array( $value ) ) { |
2825 |
3505 |
2826 if ( ! isset( $option_array[1] ) ) { |
3506 if ( empty( $option_key ) ) { |
2827 |
3507 |
2828 /* Measurement */ |
3508 // Measurement |
2829 if ( isset( $value[0] ) && isset( $value[1] ) ) { |
3509 if ( $option_type == 'measurement' ) { |
2830 |
3510 $unit = ! empty( $value[1] ) ? $value[1] : 'px'; |
2831 /* set $value with measurement properties */ |
3511 |
2832 $value = $value[0].$value[1]; |
3512 // Set $value with measurement properties |
2833 |
3513 if ( isset( $value[0] ) && strlen( $value[0] ) > 0 ) |
2834 /* typography */ |
3514 $value = $value[0].$unit; |
2835 } else if ( ot_array_keys_exists( $value, array( 'font-color', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform' ) ) ) { |
3515 |
3516 // Border |
|
3517 } else if ( $option_type == 'border' ) { |
|
3518 $border = array(); |
|
3519 |
|
3520 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3521 |
|
3522 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
|
3523 $border[] = $value['width'].$unit; |
|
3524 |
|
3525 if ( ! empty( $value['style'] ) ) |
|
3526 $border[] = $value['style']; |
|
3527 |
|
3528 if ( ! empty( $value['color'] ) ) |
|
3529 $border[] = $value['color']; |
|
3530 |
|
3531 /* set $value with border properties or empty string */ |
|
3532 $value = ! empty( $border ) ? implode( ' ', $border ) : ''; |
|
3533 |
|
3534 // Box Shadow |
|
3535 } else if ( $option_type == 'box-shadow' ) { |
|
3536 |
|
3537 /* set $value with box-shadow properties or empty string */ |
|
3538 $value = ! empty( $value ) ? implode( ' ', $value ) : ''; |
|
3539 |
|
3540 // Dimension |
|
3541 } else if ( $option_type == 'dimension' ) { |
|
3542 $dimension = array(); |
|
3543 |
|
3544 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3545 |
|
3546 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
|
3547 $dimension[] = $value['width'].$unit; |
|
3548 |
|
3549 if ( isset( $value['height'] ) && strlen( $value['height'] ) > 0 ) |
|
3550 $dimension[] = $value['height'].$unit; |
|
3551 |
|
3552 // Set $value with dimension properties or empty string |
|
3553 $value = ! empty( $dimension ) ? implode( ' ', $dimension ) : ''; |
|
3554 |
|
3555 // Spacing |
|
3556 } else if ( $option_type == 'spacing' ) { |
|
3557 $spacing = array(); |
|
3558 |
|
3559 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3560 |
|
3561 if ( isset( $value['top'] ) && strlen( $value['top'] ) > 0 ) |
|
3562 $spacing[] = $value['top'].$unit; |
|
3563 |
|
3564 if ( isset( $value['right'] ) && strlen( $value['right'] ) > 0 ) |
|
3565 $spacing[] = $value['right'].$unit; |
|
3566 |
|
3567 if ( isset( $value['bottom'] ) && strlen( $value['bottom'] ) > 0 ) |
|
3568 $spacing[] = $value['bottom'].$unit; |
|
3569 |
|
3570 if ( isset( $value['left'] ) && strlen( $value['left'] ) > 0 ) |
|
3571 $spacing[] = $value['left'].$unit; |
|
3572 |
|
3573 // Set $value with spacing properties or empty string |
|
3574 $value = ! empty( $spacing ) ? implode( ' ', $spacing ) : ''; |
|
3575 |
|
3576 // Typography |
|
3577 } else if ( $option_type == 'typography' ) { |
|
2836 $font = array(); |
3578 $font = array(); |
2837 |
3579 |
2838 if ( ! empty( $value['font-color'] ) ) |
3580 if ( ! empty( $value['font-color'] ) ) |
2839 $font[] = "color: " . $value['font-color'] . ";"; |
3581 $font[] = "color: " . $value['font-color'] . ";"; |
2840 |
3582 |
2841 if ( ! empty( $value['font-family'] ) ) { |
3583 if ( ! empty( $value['font-family'] ) ) { |
2842 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) { |
3584 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) { |
2843 if ( $key == $value['font-family'] ) { |
3585 if ( $key == $value['font-family'] ) { |
2844 $font[] = "font-family: " . $v . ";"; |
3586 $font[] = "font-family: " . $v . ";"; |
2845 } |
3587 } |
2846 } |
3588 } |
2847 } |
3589 } |
2848 |
3590 |
2849 if ( ! empty( $value['font-size'] ) ) |
3591 if ( ! empty( $value['font-size'] ) ) |
2850 $font[] = "font-size: " . $value['font-size'] . ";"; |
3592 $font[] = "font-size: " . $value['font-size'] . ";"; |
2851 |
3593 |
2852 if ( ! empty( $value['font-style'] ) ) |
3594 if ( ! empty( $value['font-style'] ) ) |
2853 $font[] = "font-style: " . $value['font-style'] . ";"; |
3595 $font[] = "font-style: " . $value['font-style'] . ";"; |
2854 |
3596 |
2855 if ( ! empty( $value['font-variant'] ) ) |
3597 if ( ! empty( $value['font-variant'] ) ) |
2856 $font[] = "font-variant: " . $value['font-variant'] . ";"; |
3598 $font[] = "font-variant: " . $value['font-variant'] . ";"; |
2857 |
3599 |
2858 if ( ! empty( $value['font-weight'] ) ) |
3600 if ( ! empty( $value['font-weight'] ) ) |
2859 $font[] = "font-weight: " . $value['font-weight'] . ";"; |
3601 $font[] = "font-weight: " . $value['font-weight'] . ";"; |
2860 |
3602 |
2861 if ( ! empty( $value['letter-spacing'] ) ) |
3603 if ( ! empty( $value['letter-spacing'] ) ) |
2862 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";"; |
3604 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";"; |
2863 |
3605 |
2864 if ( ! empty( $value['line-height'] ) ) |
3606 if ( ! empty( $value['line-height'] ) ) |
2865 $font[] = "line-height: " . $value['line-height'] . ";"; |
3607 $font[] = "line-height: " . $value['line-height'] . ";"; |
2866 |
3608 |
2867 if ( ! empty( $value['text-decoration'] ) ) |
3609 if ( ! empty( $value['text-decoration'] ) ) |
2868 $font[] = "text-decoration: " . $value['text-decoration'] . ";"; |
3610 $font[] = "text-decoration: " . $value['text-decoration'] . ";"; |
2869 |
3611 |
2870 if ( ! empty( $value['text-transform'] ) ) |
3612 if ( ! empty( $value['text-transform'] ) ) |
2871 $font[] = "text-transform: " . $value['text-transform'] . ";"; |
3613 $font[] = "text-transform: " . $value['text-transform'] . ";"; |
2872 |
3614 |
2873 /* set $value with font properties or empty string */ |
3615 // Set $value with font properties or empty string |
2874 $value = ! empty( $font ) ? implode( "\n", $font ) : ''; |
3616 $value = ! empty( $font ) ? implode( "\n", $font ) : ''; |
2875 |
3617 |
2876 /* background */ |
3618 // Background |
2877 } else if ( ot_array_keys_exists( $value, array( 'background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position' ) ) ) { |
3619 } else if ( $option_type == 'background' ) { |
2878 $bg = array(); |
3620 $bg = array(); |
2879 |
3621 |
2880 if ( ! empty( $value['background-color'] ) ) |
3622 if ( ! empty( $value['background-color'] ) ) |
2881 $bg[] = $value['background-color']; |
3623 $bg[] = $value['background-color']; |
2882 |
3624 |
2883 if ( ! empty( $value['background-image'] ) ) |
3625 if ( ! empty( $value['background-image'] ) ) { |
3626 |
|
3627 // If an attachment ID is stored here fetch its URL and replace the value |
|
3628 if ( wp_attachment_is_image( $value['background-image'] ) ) { |
|
3629 |
|
3630 $attachment_data = wp_get_attachment_image_src( $value['background-image'], 'original' ); |
|
3631 |
|
3632 // Check for attachment data |
|
3633 if ( $attachment_data ) { |
|
3634 |
|
3635 $value['background-image'] = $attachment_data[0]; |
|
3636 |
|
3637 } |
|
3638 |
|
3639 } |
|
3640 |
|
2884 $bg[] = 'url("' . $value['background-image'] . '")'; |
3641 $bg[] = 'url("' . $value['background-image'] . '")'; |
2885 |
3642 |
3643 } |
|
3644 |
|
2886 if ( ! empty( $value['background-repeat'] ) ) |
3645 if ( ! empty( $value['background-repeat'] ) ) |
2887 $bg[] = $value['background-repeat']; |
3646 $bg[] = $value['background-repeat']; |
2888 |
3647 |
2889 if ( ! empty( $value['background-attachment'] ) ) |
3648 if ( ! empty( $value['background-attachment'] ) ) |
2890 $bg[] = $value['background-attachment']; |
3649 $bg[] = $value['background-attachment']; |
2891 |
3650 |
2892 if ( ! empty( $value['background-position'] ) ) |
3651 if ( ! empty( $value['background-position'] ) ) |
2893 $bg[] = $value['background-position']; |
3652 $bg[] = $value['background-position']; |
2894 |
3653 |
2895 /* set $value with background properties or empty string */ |
3654 if ( ! empty( $value['background-size'] ) ) |
3655 $size = $value['background-size']; |
|
3656 |
|
3657 // Set $value with background properties or empty string |
|
2896 $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : ''; |
3658 $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : ''; |
3659 |
|
3660 if ( isset( $size ) ) { |
|
3661 if ( ! empty( $bg ) ) { |
|
3662 $value.= apply_filters( 'ot_insert_css_with_markers_bg_size_white_space', "\n\x20\x20", $option_id ); |
|
3663 } |
|
3664 $value.= "background-size: $size;"; |
|
3665 } |
|
3666 |
|
2897 } |
3667 } |
2898 |
3668 |
2899 } else { |
3669 } else { |
2900 |
3670 |
2901 $value = $value[$option_array[1]]; |
3671 $value = $value[$option_key]; |
2902 |
3672 |
2903 } |
3673 } |
2904 |
3674 |
2905 } |
3675 } |
2906 |
3676 |
3677 // If an attachment ID is stored here fetch its URL and replace the value |
|
3678 if ( $option_type == 'upload' && wp_attachment_is_image( $value ) ) { |
|
3679 |
|
3680 $attachment_data = wp_get_attachment_image_src( $value, 'original' ); |
|
3681 |
|
3682 // Check for attachment data |
|
3683 if ( $attachment_data ) { |
|
3684 |
|
3685 $value = $attachment_data[0]; |
|
3686 |
|
3687 } |
|
3688 |
|
3689 } |
|
3690 |
|
3691 // Attempt to fallback when `$value` is empty |
|
3692 if ( empty( $value ) ) { |
|
3693 |
|
3694 // We're trying to access a single array key |
|
3695 if ( ! empty( $option_key ) ) { |
|
3696 |
|
3697 // Link Color `inherit` |
|
3698 if ( $option_type == 'link-color' ) { |
|
3699 $fallback = 'inherit'; |
|
3700 } |
|
3701 |
|
3702 } else { |
|
3703 |
|
3704 // Border |
|
3705 if ( $option_type == 'border' ) { |
|
3706 $fallback = 'inherit'; |
|
3707 } |
|
3708 |
|
3709 // Box Shadow |
|
3710 if ( $option_type == 'box-shadow' ) { |
|
3711 $fallback = 'none'; |
|
3712 } |
|
3713 |
|
3714 // Colorpicker |
|
3715 if ( $option_type == 'colorpicker' ) { |
|
3716 $fallback = 'inherit'; |
|
3717 } |
|
3718 |
|
3719 // Colorpicker Opacity |
|
3720 if ( $option_type == 'colorpicker-opacity' ) { |
|
3721 $fallback = 'inherit'; |
|
3722 } |
|
3723 |
|
3724 } |
|
3725 |
|
3726 /** |
|
3727 * Filter the `dynamic.css` fallback value. |
|
3728 * |
|
3729 * @since 2.5.3 |
|
3730 * |
|
3731 * @param string $fallback The default CSS fallback value. |
|
3732 * @param string $option_id The option ID. |
|
3733 * @param string $option_type The option type. |
|
3734 * @param string $option_key The option array key. |
|
3735 */ |
|
3736 $fallback = apply_filters( 'ot_insert_css_with_markers_fallback', $fallback, $option_id, $option_type, $option_key ); |
|
3737 |
|
3738 } |
|
3739 |
|
3740 // Let's fallback! |
|
3741 if ( ! empty( $fallback ) ) { |
|
3742 $value = $fallback; |
|
3743 } |
|
3744 |
|
2907 // Filter the CSS |
3745 // Filter the CSS |
2908 $value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id ); |
3746 $value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id ); |
2909 |
3747 |
2910 /* insert CSS, even if the value is empty */ |
3748 // Insert CSS, even if the value is empty |
2911 $insertion = stripslashes( str_replace( $option, $value, $insertion ) ); |
3749 $insertion = stripslashes( str_replace( $option, $value, $insertion ) ); |
2912 |
3750 |
2913 } |
3751 } |
2914 |
3752 |
2915 /* create array from the lines of code */ |
3753 // Can't write to the file so we error out |
3754 if ( ! is_writable( $filepath ) ) { |
|
3755 add_settings_error( 'option-tree', 'dynamic_css', sprintf( __( 'Unable to write to file %s.', 'option-tree' ), '<code>' . $filepath . '</code>' ), 'error' ); |
|
3756 return false; |
|
3757 } |
|
3758 |
|
3759 // Create array from the lines of code |
|
2916 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
3760 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
2917 |
3761 |
2918 /* can't write to the file return false */ |
3762 // Can't write to the file return false |
2919 if ( ! $f = ot_file_open( $filepath, 'w' ) ) |
3763 if ( ! $f = ot_file_open( $filepath, 'w' ) ) { |
2920 return false; |
3764 return false; |
2921 |
3765 } |
3766 |
|
2922 $searching = true; |
3767 $searching = true; |
2923 $foundit = false; |
3768 $foundit = false; |
2924 |
3769 |
2925 /* has array of lines */ |
3770 // Has array of lines |
2926 if ( ! empty( $markerdata ) ) { |
3771 if ( ! empty( $markerdata ) ) { |
2927 |
3772 |
2928 /* foreach line of code */ |
3773 // Foreach line of code |
2929 foreach( $markerdata as $n => $markerline ) { |
3774 foreach( $markerdata as $n => $markerline ) { |
2930 |
3775 |
2931 /* found begining of marker, set $searching to false */ |
3776 // Found begining of marker, set $searching to false |
2932 if ( $markerline == "/* BEGIN {$marker} */" ) |
3777 if ( $markerline == "/* BEGIN {$marker} */" ) |
2933 $searching = false; |
3778 $searching = false; |
2934 |
3779 |
2935 /* keep rewrite each line of CSS */ |
3780 // Keep searching each line of CSS |
2936 if ( $searching == true ) { |
3781 if ( $searching == true ) { |
2937 if ( $n + 1 < count( $markerdata ) ) |
3782 if ( $n + 1 < count( $markerdata ) ) |
2938 ot_file_write( $f, "{$markerline}\n" ); |
3783 ot_file_write( $f, "{$markerline}\n" ); |
2939 else |
3784 else |
2940 ot_file_write( $f, "{$markerline}" ); |
3785 ot_file_write( $f, "{$markerline}" ); |
2941 } |
3786 } |
2942 |
3787 |
2943 /* found end marker write code */ |
3788 // Found end marker write code |
2944 if ( $markerline == "/* END {$marker} */" ) { |
3789 if ( $markerline == "/* END {$marker} */" ) { |
2945 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
3790 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
2946 ot_file_write( $f, "{$insertion}\n" ); |
3791 ot_file_write( $f, "{$insertion}\n" ); |
2947 ot_file_write( $f, "/* END {$marker} */\n" ); |
3792 ot_file_write( $f, "/* END {$marker} */\n" ); |
2948 $searching = true; |
3793 $searching = true; |
2949 $foundit = true; |
3794 $foundit = true; |
2950 } |
3795 } |
2951 |
3796 |
2952 } |
3797 } |
2953 |
3798 |
2954 } |
3799 } |
2955 |
3800 |
2956 /* nothing inserted, write code. DO IT, DO IT! */ |
3801 // Nothing inserted, write code. DO IT, DO IT! |
2957 if ( ! $foundit ) { |
3802 if ( ! $foundit ) { |
2958 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
3803 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
2959 ot_file_write( $f, "{$insertion}\n" ); |
3804 ot_file_write( $f, "{$insertion}\n" ); |
2960 ot_file_write( $f, "/* END {$marker} */\n" ); |
3805 ot_file_write( $f, "/* END {$marker} */\n" ); |
2961 } |
3806 } |
2962 |
3807 |
2963 /* close file */ |
3808 // Close file |
2964 ot_file_close( $f ); |
3809 ot_file_close( $f ); |
2965 return true; |
3810 return true; |
2966 } |
3811 } |
2967 |
3812 |
2968 return false; |
3813 return false; |
2969 |
3814 |
2970 } |
3815 } |
2971 |
3816 |
2972 } |
3817 } |
3120 |
3965 |
3121 function ot_loop_through_choices( $name, $choices = array() ) { |
3966 function ot_loop_through_choices( $name, $choices = array() ) { |
3122 |
3967 |
3123 $content = ''; |
3968 $content = ''; |
3124 |
3969 |
3125 foreach( $choices as $key => $choice ) |
3970 foreach( (array) $choices as $key => $choice ) |
3126 $content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>'; |
3971 $content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>'; |
3127 |
3972 |
3128 return $content; |
3973 return $content; |
3129 } |
3974 } |
3130 |
3975 |
3175 |
4020 |
3176 return ' |
4021 return ' |
3177 <div class="option-tree-setting is-section"> |
4022 <div class="option-tree-setting is-section"> |
3178 <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div> |
4023 <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div> |
3179 <div class="button-section"> |
4024 <div class="button-section"> |
3180 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'edit', 'option-tree' ) . '"> |
4025 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'edit', 'option-tree' ) . '"> |
3181 <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> |
4026 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3182 </a> |
4027 </a> |
3183 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4028 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3184 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4029 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3185 </a> |
4030 </a> |
3186 </div> |
4031 </div> |
3187 <div class="option-tree-setting-body"> |
4032 <div class="option-tree-setting-body"> |
3188 <div class="format-settings"> |
4033 <div class="format-settings"> |
3189 <div class="format-setting type-text"> |
4034 <div class="format-setting type-text"> |
3227 function ot_settings_view( $name, $key, $setting = array() ) { |
4072 function ot_settings_view( $name, $key, $setting = array() ) { |
3228 |
4073 |
3229 $child = ( strpos( $name, '][settings]') !== false ) ? true : false; |
4074 $child = ( strpos( $name, '][settings]') !== false ) ? true : false; |
3230 $type = isset( $setting['type'] ) ? $setting['type'] : ''; |
4075 $type = isset( $setting['type'] ) ? $setting['type'] : ''; |
3231 $std = isset( $setting['std'] ) ? $setting['std'] : ''; |
4076 $std = isset( $setting['std'] ) ? $setting['std'] : ''; |
4077 $operator = isset( $setting['operator'] ) ? esc_attr( $setting['operator'] ) : 'and'; |
|
3232 |
4078 |
3233 // Serialize the standard value just incase |
4079 // Serialize the standard value just incase |
3234 if ( is_array( $std ) ) { |
4080 if ( is_array( $std ) ) { |
3235 $std = maybe_serialize( $std ); |
4081 $std = maybe_serialize( $std ); |
3236 } |
4082 } |
3237 |
4083 |
3238 if ( in_array( $type, array( 'textarea', 'textarea-simple', 'css' ) ) ) { |
4084 if ( in_array( $type, array( 'css', 'javascript', 'textarea', 'textarea-simple' ) ) ) { |
3239 $std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>'; |
4085 $std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>'; |
3240 } else { |
4086 } else { |
3241 $std_form_element = '<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . esc_attr( $std ) . '" class="widefat option-tree-ui-input" autocomplete="off" />'; |
4087 $std_form_element = '<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . esc_attr( $std ) . '" class="widefat option-tree-ui-input" autocomplete="off" />'; |
3242 } |
4088 } |
3243 |
4089 |
3244 return ' |
4090 return ' |
3245 <div class="option-tree-setting"> |
4091 <div class="option-tree-setting"> |
3246 <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div> |
4092 <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div> |
3247 <div class="button-section"> |
4093 <div class="button-section"> |
3248 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4094 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
3249 <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> |
4095 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3250 </a> |
4096 </a> |
3251 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4097 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3252 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4098 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3253 </a> |
4099 </a> |
3254 </div> |
4100 </div> |
3255 <div class="option-tree-setting-body"> |
4101 <div class="option-tree-setting-body"> |
3256 <div class="format-settings"> |
4102 <div class="format-settings"> |
3257 <div class="format-setting type-text wide-desc"> |
4103 <div class="format-setting type-text wide-desc"> |
3293 <div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div> |
4139 <div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div> |
3294 <div class="format-setting-inner"> |
4140 <div class="format-setting-inner"> |
3295 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4141 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
3296 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . ' |
4142 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . ' |
3297 </ul> |
4143 </ul> |
3298 <a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a> |
4144 <a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a> |
3299 </div> |
4145 </div> |
3300 </div> |
4146 </div> |
3301 </div> |
4147 </div> |
3302 <div class="format-settings"> |
4148 <div class="format-settings"> |
3303 <div class="format-setting type-textblock wide-desc"> |
4149 <div class="format-setting type-textblock wide-desc"> |
3304 <div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div> |
4150 <div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div> |
3305 <div class="format-setting-inner"> |
4151 <div class="format-setting-inner"> |
3306 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4152 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
3307 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . ' |
4153 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . ' |
3308 </ul> |
4154 </ul> |
3309 <a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a> |
4155 <a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a> |
3310 </div> |
4156 </div> |
3311 </div> |
4157 </div> |
3312 </div> |
4158 </div> |
3313 <div class="format-settings"> |
4159 <div class="format-settings"> |
3314 <div class="format-setting type-text wide-desc"> |
4160 <div class="format-setting type-text wide-desc"> |
3356 <div class="format-setting-inner"> |
4202 <div class="format-setting-inner"> |
3357 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4203 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
3358 </div> |
4204 </div> |
3359 </div> |
4205 </div> |
3360 </div> |
4206 </div> |
4207 <div class="format-settings"> |
|
4208 <div class="format-setting type-text wide-desc"> |
|
4209 <div class="description">' . sprintf( __( '<strong>Condition</strong>: Add a comma separated list (no spaces) of conditions in which the field will be visible, leave this setting empty to always show the field. In these examples, <code>value</code> is a placeholder for your condition, which can be in the form of %s.', 'option-tree' ), '<code>field_id:is(value)</code>, <code>field_id:not(value)</code>, <code>field_id:contains(value)</code>, <code>field_id:less_than(value)</code>, <code>field_id:less_than_or_equal_to(value)</code>, <code>field_id:greater_than(value)</code>, or <code>field_id:greater_than_or_equal_to(value)</code>' ) . '</div> |
|
4210 <div class="format-setting-inner"> |
|
4211 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][condition]" value="' . ( isset( $setting['condition'] ) ? esc_attr( $setting['condition'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4212 </div> |
|
4213 </div> |
|
4214 </div> |
|
4215 <div class="format-settings"> |
|
4216 <div class="format-setting type-select wide-desc"> |
|
4217 <div class="description">' . __( '<strong>Operator</strong>: Choose the logical operator to compute the result of the conditions.', 'option-tree' ) . '</div> |
|
4218 <div class="format-setting-inner"> |
|
4219 <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][operator]" value="' . $operator . '" class="option-tree-ui-select"> |
|
4220 <option value="and" ' . selected( $operator, 'and', false ) . '>' . __( 'and', 'option-tree' ) . '</option> |
|
4221 <option value="or" ' . selected( $operator, 'or', false ) . '>' . __( 'or', 'option-tree' ) . '</option> |
|
4222 </select> |
|
4223 </div> |
|
4224 </div> |
|
4225 </div> |
|
3361 </div> |
4226 </div> |
3362 </div> |
4227 </div> |
3363 ' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' ); |
4228 ' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' ); |
3364 |
4229 |
3365 } |
4230 } |
3387 |
4252 |
3388 return ' |
4253 return ' |
3389 <div class="option-tree-setting"> |
4254 <div class="option-tree-setting"> |
3390 <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div> |
4255 <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div> |
3391 <div class="button-section"> |
4256 <div class="button-section"> |
3392 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4257 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
3393 <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> |
4258 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3394 </a> |
4259 </a> |
3395 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4260 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3396 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4261 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3397 </a> |
4262 </a> |
3398 </div> |
4263 </div> |
3399 <div class="option-tree-setting-body"> |
4264 <div class="option-tree-setting-body"> |
3400 <div class="format-settings"> |
4265 <div class="format-settings"> |
3401 <div class="format-setting-label"> |
4266 <div class="format-setting-label"> |
3453 |
4318 |
3454 return ' |
4319 return ' |
3455 <div class="option-tree-setting"> |
4320 <div class="option-tree-setting"> |
3456 <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div> |
4321 <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div> |
3457 <div class="button-section"> |
4322 <div class="button-section"> |
3458 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4323 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
3459 <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> |
4324 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3460 </a> |
4325 </a> |
3461 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4326 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3462 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4327 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3463 </a> |
4328 </a> |
3464 </div> |
4329 </div> |
3465 <div class="option-tree-setting-body"> |
4330 <div class="option-tree-setting-body"> |
3466 <div class="format-settings"> |
4331 <div class="format-settings"> |
3467 <div class="format-setting type-text no-desc"> |
4332 <div class="format-setting type-text no-desc"> |
3504 * @return void |
4369 * @return void |
3505 * |
4370 * |
3506 * @access public |
4371 * @access public |
3507 * @since 2.0 |
4372 * @since 2.0 |
3508 */ |
4373 */ |
3509 if ( ! function_exists( 'ot_layouts_view' ) ) { |
4374 if ( ! function_exists( 'ot_layout_view' ) ) { |
3510 |
4375 |
3511 function ot_layout_view( $key, $data = '', $active_layout = '' ) { |
4376 function ot_layout_view( $key, $data = '', $active_layout = '' ) { |
3512 |
4377 |
3513 return ' |
4378 return ' |
3514 <div class="option-tree-setting"> |
4379 <div class="option-tree-setting"> |
3515 <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div> |
4380 <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div> |
3516 <div class="button-section"> |
4381 <div class="button-section"> |
3517 <a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '"> |
4382 <a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '"> |
3518 <span class="icon check">' . __( 'Activate', 'option-tree' ) . '</span> |
4383 <span class="icon ot-icon-square-o"></span>' . __( 'Activate', 'option-tree' ) . ' |
3519 </a> |
4384 </a> |
3520 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="'. __( 'Delete', 'option-tree' ) . '"> |
4385 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="'. __( 'Delete', 'option-tree' ) . '"> |
3521 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4386 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3522 </a> |
4387 </a> |
3523 </div> |
4388 </div> |
3524 <input type="hidden" name="option_tree_layouts[' . esc_attr( $key ) . ']" value="' . $data . '" /> |
4389 <input type="hidden" name="' . ot_layouts_id() . '[' . esc_attr( $key ) . ']" value="' . $data . '" /> |
3525 </div>'; |
4390 </div>'; |
3526 |
4391 |
3527 } |
4392 } |
3528 |
4393 |
3529 } |
4394 } |
3581 |
4446 |
3582 echo ' |
4447 echo ' |
3583 <div class="option-tree-setting"> |
4448 <div class="option-tree-setting"> |
3584 <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div> |
4449 <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div> |
3585 <div class="button-section"> |
4450 <div class="button-section"> |
3586 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4451 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
3587 <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> |
4452 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3588 </a> |
4453 </a> |
3589 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4454 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3590 <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span> |
4455 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3591 </a> |
4456 </a> |
3592 </div> |
4457 </div> |
3593 <div class="option-tree-setting-body">'; |
4458 <div class="option-tree-setting-body">'; |
3594 |
4459 |
3595 foreach( $settings as $field ) { |
4460 foreach( $settings as $field ) { |
3598 $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
4463 $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
3599 |
4464 |
3600 /* set default to standard value */ |
4465 /* set default to standard value */ |
3601 if ( isset( $field['std'] ) ) { |
4466 if ( isset( $field['std'] ) ) { |
3602 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
4467 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
4468 } |
|
4469 |
|
4470 // filter the title label and description |
|
4471 if ( $field['id'] == 'title' ) { |
|
4472 |
|
4473 // filter the label |
|
4474 $field['label'] = apply_filters( 'ot_list_item_title_label', $field['label'], $name ); |
|
4475 |
|
4476 // filter the description |
|
4477 $field['desc'] = apply_filters( 'ot_list_item_title_desc', $field['desc'], $name ); |
|
4478 |
|
3603 } |
4479 } |
3604 |
4480 |
3605 /* make life easier */ |
4481 /* make life easier */ |
3606 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
4482 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
3607 |
4483 |
3616 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
4492 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
3617 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
4493 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
3618 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
4494 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
3619 'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
4495 'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
3620 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4496 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4497 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
|
4498 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
|
3621 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4499 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
3622 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
4500 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
3623 'post_id' => $post_id, |
4501 'post_id' => $post_id, |
3624 'get_option' => $get_option |
4502 'get_option' => $get_option |
3625 ); |
4503 ); |
4504 |
|
4505 $conditions = ''; |
|
4506 |
|
4507 /* setup the conditions */ |
|
4508 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
|
4509 |
|
4510 /* doing magic on the conditions so they work in a list item */ |
|
4511 $conditionals = explode( ',', $field['condition'] ); |
|
4512 foreach( $conditionals as $condition ) { |
|
4513 $parts = explode( ':', $condition ); |
|
4514 if ( isset( $parts[0] ) ) { |
|
4515 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
|
4516 } |
|
4517 } |
|
4518 |
|
4519 $conditions = ' data-condition="' . $field['condition'] . '"'; |
|
4520 $conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
|
4521 |
|
4522 } |
|
4523 |
|
4524 // Build the setting CSS class |
|
4525 if ( ! empty( $_args['field_class'] ) ) { |
|
4526 |
|
4527 $classes = explode( ' ', $_args['field_class'] ); |
|
4528 |
|
4529 foreach( $classes as $_key => $value ) { |
|
4530 |
|
4531 $classes[$_key] = $value . '-wrap'; |
|
4532 |
|
4533 } |
|
4534 |
|
4535 $class = 'format-settings ' . implode( ' ', $classes ); |
|
4536 |
|
4537 } else { |
|
4538 |
|
4539 $class = 'format-settings'; |
|
4540 |
|
4541 } |
|
3626 |
4542 |
3627 /* option label */ |
4543 /* option label */ |
3628 echo '<div class="format-settings">'; |
4544 echo '<div id="setting_' . $_args['field_id'] . '" class="' . $class . '"' . $conditions . '>'; |
3629 |
4545 |
3630 /* don't show title with textblocks */ |
4546 /* don't show title with textblocks */ |
3631 if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
4547 if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
3632 echo '<div class="format-setting-label">'; |
4548 echo '<div class="format-setting-label">'; |
3633 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
4549 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
3634 echo '</div>'; |
4550 echo '</div>'; |
3635 } |
4551 } |
3636 |
4552 |
3637 /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
4553 /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
3638 if ( $_args['type'] == 'textarea' ) |
4554 if ( apply_filters( 'ot_override_forced_textarea_simple', false, $field['id'] ) == false && $_args['type'] == 'textarea' ) |
3639 $_args['type'] = 'textarea-simple'; |
4555 $_args['type'] = 'textarea-simple'; |
3640 |
4556 |
3641 /* option body, list-item is not allowed inside another list-item */ |
4557 /* option body, list-item is not allowed inside another list-item */ |
3642 if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) { |
4558 if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) { |
3643 echo ot_display_by_type( $_args ); |
4559 echo ot_display_by_type( $_args ); |
3644 } |
4560 } |
3645 |
4561 |
3646 echo '</div>'; |
4562 echo '</div>'; |
3647 |
4563 |
3648 } |
4564 } |
3649 |
4565 |
3650 echo |
4566 echo '</div>'; |
3651 '</div> |
4567 |
3652 </div>'; |
4568 echo '</div>'; |
4569 |
|
4570 } |
|
4571 |
|
4572 } |
|
4573 |
|
4574 /** |
|
4575 * Helper function to display social links. |
|
4576 * |
|
4577 * This function is used in AJAX to add a new list items |
|
4578 * and when they have already been added and saved. |
|
4579 * |
|
4580 * @param string $name The form field name. |
|
4581 * @param int $key The array key for the current element. |
|
4582 * @param array An array of values for the current list item. |
|
4583 * |
|
4584 * @return void |
|
4585 * |
|
4586 * @access public |
|
4587 * @since 2.4.0 |
|
4588 */ |
|
4589 if ( ! function_exists( 'ot_social_links_view' ) ) { |
|
4590 |
|
4591 function ot_social_links_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
|
4592 |
|
4593 /* if no settings array load the filterable social links settings */ |
|
4594 if ( empty( $settings ) ) { |
|
4595 |
|
4596 $settings = ot_social_links_settings( $name ); |
|
4597 |
|
4598 } |
|
4599 |
|
4600 echo ' |
|
4601 <div class="option-tree-setting"> |
|
4602 <div class="open">' . ( isset( $list_item['name'] ) ? esc_attr( $list_item['name'] ) : '' ) . '</div> |
|
4603 <div class="button-section"> |
|
4604 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
|
4605 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
4606 </a> |
|
4607 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
|
4608 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
4609 </a> |
|
4610 </div> |
|
4611 <div class="option-tree-setting-body">'; |
|
4612 |
|
4613 foreach( $settings as $field ) { |
|
4614 |
|
4615 // Set field value |
|
4616 $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
|
4617 |
|
4618 /* set default to standard value */ |
|
4619 if ( isset( $field['std'] ) ) { |
|
4620 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
|
4621 } |
|
4622 |
|
4623 /* make life easier */ |
|
4624 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
|
4625 |
|
4626 /* build the arguments array */ |
|
4627 $_args = array( |
|
4628 'type' => $field['type'], |
|
4629 'field_id' => $name . '_' . $field['id'] . '_' . $key, |
|
4630 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
|
4631 'field_value' => $field_value, |
|
4632 'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
|
4633 'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
|
4634 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
|
4635 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
|
4636 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
|
4637 'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
|
4638 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
|
4639 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
|
4640 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
|
4641 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
|
4642 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
|
4643 'post_id' => $post_id, |
|
4644 'get_option' => $get_option |
|
4645 ); |
|
4646 |
|
4647 $conditions = ''; |
|
4648 |
|
4649 /* setup the conditions */ |
|
4650 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
|
4651 |
|
4652 /* doing magic on the conditions so they work in a list item */ |
|
4653 $conditionals = explode( ',', $field['condition'] ); |
|
4654 foreach( $conditionals as $condition ) { |
|
4655 $parts = explode( ':', $condition ); |
|
4656 if ( isset( $parts[0] ) ) { |
|
4657 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
|
4658 } |
|
4659 } |
|
4660 |
|
4661 $conditions = ' data-condition="' . $field['condition'] . '"'; |
|
4662 $conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
|
4663 |
|
4664 } |
|
4665 |
|
4666 /* option label */ |
|
4667 echo '<div id="setting_' . $_args['field_id'] . '" class="format-settings"' . $conditions . '>'; |
|
4668 |
|
4669 /* don't show title with textblocks */ |
|
4670 if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
|
4671 echo '<div class="format-setting-label">'; |
|
4672 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
|
4673 echo '</div>'; |
|
4674 } |
|
4675 |
|
4676 /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
|
4677 if ( $_args['type'] == 'textarea' ) |
|
4678 $_args['type'] = 'textarea-simple'; |
|
4679 |
|
4680 /* option body, list-item is not allowed inside another list-item */ |
|
4681 if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' && $_args['type'] !== 'social-links' ) { |
|
4682 echo ot_display_by_type( $_args ); |
|
4683 } |
|
4684 |
|
4685 echo '</div>'; |
|
4686 |
|
4687 } |
|
4688 |
|
4689 echo '</div>'; |
|
4690 |
|
4691 echo '</div>'; |
|
3653 |
4692 |
3654 } |
4693 } |
3655 |
4694 |
3656 } |
4695 } |
3657 |
4696 |
3671 |
4710 |
3672 /* form nonce */ |
4711 /* form nonce */ |
3673 wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' ); |
4712 wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' ); |
3674 |
4713 |
3675 /* get the saved layouts */ |
4714 /* get the saved layouts */ |
3676 $layouts = get_option( 'option_tree_layouts' ); |
4715 $layouts = get_option( ot_layouts_id() ); |
3677 |
4716 |
3678 /* set active layout */ |
4717 /* set active layout */ |
3679 $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : ''; |
4718 $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : ''; |
3680 |
4719 |
3681 if ( is_array( $layouts ) && count( $layouts ) > 1 ) { |
4720 if ( is_array( $layouts ) && count( $layouts ) > 1 ) { |
3684 |
4723 |
3685 echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />'; |
4724 echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />'; |
3686 |
4725 |
3687 echo '<div class="option-tree-active-layout">'; |
4726 echo '<div class="option-tree-active-layout">'; |
3688 |
4727 |
3689 echo '<select name="option_tree_layouts[active_layout]" class="option-tree-ui-select">'; |
4728 echo '<select name="' . ot_layouts_id() . '[active_layout]" class="option-tree-ui-select">'; |
3690 |
4729 |
3691 foreach( $layouts as $key => $data ) { |
4730 foreach( $layouts as $key => $data ) { |
3692 |
4731 |
3693 if ( $key == 'active_layout' ) |
4732 if ( $key == 'active_layout' ) |
3694 continue; |
4733 continue; |
3703 foreach( $layouts as $key => $data ) { |
4742 foreach( $layouts as $key => $data ) { |
3704 |
4743 |
3705 if ( $key == 'active_layout' ) |
4744 if ( $key == 'active_layout' ) |
3706 continue; |
4745 continue; |
3707 |
4746 |
3708 echo '<input type="hidden" name="option_tree_layouts[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />'; |
4747 echo '<input type="hidden" name="' . ot_layouts_id() . '[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />'; |
3709 |
4748 |
3710 } |
4749 } |
3711 |
4750 |
3712 } |
4751 } |
3713 |
4752 |
3714 /* new layout wrapper */ |
4753 /* new layout wrapper */ |
3715 echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">'; |
4754 echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">'; |
3716 |
4755 |
3717 /* add new layout */ |
4756 /* add new layout */ |
3718 echo '<input type="text" name="option_tree_layouts[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />'; |
4757 echo '<input type="text" name="' . ot_layouts_id() . '[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />'; |
3719 |
4758 |
3720 echo '<button type="submit" class="option-tree-ui-button blue save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>'; |
4759 echo '<button type="submit" class="option-tree-ui-button button button-primary save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>'; |
3721 |
4760 |
3722 echo '</div>'; |
4761 echo '</div>'; |
3723 |
4762 |
3724 echo '</form>'; |
4763 echo '</form>'; |
3725 |
4764 |
4103 return $value; |
5142 return $value; |
4104 |
5143 |
4105 } |
5144 } |
4106 |
5145 |
4107 /** |
5146 /** |
5147 * Helper function to set the Google fonts array. |
|
5148 * |
|
5149 * @param string $id The option ID. |
|
5150 * @param bool $value The option value |
|
5151 * @return void |
|
5152 * |
|
5153 * @access public |
|
5154 * @since 2.5.0 |
|
5155 */ |
|
5156 function ot_set_google_fonts( $id = '', $value = '' ) { |
|
5157 |
|
5158 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
5159 |
|
5160 if ( is_array( $value ) && ! empty( $value ) ) { |
|
5161 $ot_set_google_fonts[$id] = $value; |
|
5162 } else if ( isset( $ot_set_google_fonts[$id] ) ) { |
|
5163 unset( $ot_set_google_fonts[$id] ); |
|
5164 } |
|
5165 |
|
5166 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
|
5167 |
|
5168 } |
|
5169 |
|
5170 /** |
|
5171 * Helper function to remove unused options from the Google fonts array. |
|
5172 * |
|
5173 * @param array $options The array of saved options. |
|
5174 * @return array |
|
5175 * |
|
5176 * @access public |
|
5177 * @since 2.5.0 |
|
5178 */ |
|
5179 function ot_update_google_fonts_after_save( $options ) { |
|
5180 |
|
5181 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
5182 |
|
5183 foreach( $ot_set_google_fonts as $key => $set ) { |
|
5184 if ( ! isset( $options[$key] ) ) { |
|
5185 unset( $ot_set_google_fonts[$key] ); |
|
5186 } |
|
5187 } |
|
5188 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
|
5189 |
|
5190 } |
|
5191 add_action( 'ot_after_theme_options_save', 'ot_update_google_fonts_after_save', 1 ); |
|
5192 |
|
5193 /** |
|
5194 * Helper function to fetch the Google fonts array. |
|
5195 * |
|
5196 * @param bool $normalize Whether or not to return a normalized array. Default 'true'. |
|
5197 * @param bool $force_rebuild Whether or not to force the array to be rebuilt. Default 'false'. |
|
5198 * @return array |
|
5199 * |
|
5200 * @access public |
|
5201 * @since 2.5.0 |
|
5202 */ |
|
5203 function ot_fetch_google_fonts( $normalize = true, $force_rebuild = false ) { |
|
5204 |
|
5205 /* Google Fonts cache key */ |
|
5206 $ot_google_fonts_cache_key = apply_filters( 'ot_google_fonts_cache_key', 'ot_google_fonts_cache' ); |
|
5207 |
|
5208 /* get the fonts from cache */ |
|
5209 $ot_google_fonts = apply_filters( 'ot_google_fonts_cache', get_transient( $ot_google_fonts_cache_key ) ); |
|
5210 |
|
5211 if ( $force_rebuild || ! is_array( $ot_google_fonts ) || empty( $ot_google_fonts ) ) { |
|
5212 |
|
5213 $ot_google_fonts = array(); |
|
5214 |
|
5215 /* API url and key */ |
|
5216 $ot_google_fonts_api_url = apply_filters( 'ot_google_fonts_api_url', 'https://www.googleapis.com/webfonts/v1/webfonts' ); |
|
5217 $ot_google_fonts_api_key = apply_filters( 'ot_google_fonts_api_key', 'AIzaSyB8G-4UtQr9fhDYTiNrDP40Y5GYQQKrNWI' ); |
|
5218 |
|
5219 /* API arguments */ |
|
5220 $ot_google_fonts_fields = apply_filters( 'ot_google_fonts_fields', array( 'family', 'variants', 'subsets' ) ); |
|
5221 $ot_google_fonts_sort = apply_filters( 'ot_google_fonts_sort', 'alpha' ); |
|
5222 |
|
5223 /* Initiate API request */ |
|
5224 $ot_google_fonts_query_args = array( |
|
5225 'key' => $ot_google_fonts_api_key, |
|
5226 'fields' => 'items(' . implode( ',', $ot_google_fonts_fields ) . ')', |
|
5227 'sort' => $ot_google_fonts_sort |
|
5228 ); |
|
5229 |
|
5230 /* Build and make the request */ |
|
5231 $ot_google_fonts_query = esc_url_raw( add_query_arg( $ot_google_fonts_query_args, $ot_google_fonts_api_url ) ); |
|
5232 $ot_google_fonts_response = wp_safe_remote_get( $ot_google_fonts_query, array( 'sslverify' => false, 'timeout' => 15 ) ); |
|
5233 |
|
5234 /* continue if we got a valid response */ |
|
5235 if ( 200 == wp_remote_retrieve_response_code( $ot_google_fonts_response ) ) { |
|
5236 |
|
5237 if ( $response_body = wp_remote_retrieve_body( $ot_google_fonts_response ) ) { |
|
5238 |
|
5239 /* JSON decode the response body and cache the result */ |
|
5240 $ot_google_fonts_data = json_decode( trim( $response_body ), true ); |
|
5241 |
|
5242 if ( is_array( $ot_google_fonts_data ) && isset( $ot_google_fonts_data['items'] ) ) { |
|
5243 |
|
5244 $ot_google_fonts = $ot_google_fonts_data['items']; |
|
5245 |
|
5246 // Normalize the array key |
|
5247 $ot_google_fonts_tmp = array(); |
|
5248 foreach( $ot_google_fonts as $key => $value ) { |
|
5249 $id = remove_accents( $value['family'] ); |
|
5250 $id = strtolower( $id ); |
|
5251 $id = preg_replace( '/[^a-z0-9_\-]/', '', $id ); |
|
5252 $ot_google_fonts_tmp[$id] = $value; |
|
5253 } |
|
5254 |
|
5255 $ot_google_fonts = $ot_google_fonts_tmp; |
|
5256 set_theme_mod( 'ot_google_fonts', $ot_google_fonts ); |
|
5257 set_transient( $ot_google_fonts_cache_key, $ot_google_fonts, WEEK_IN_SECONDS ); |
|
5258 |
|
5259 } |
|
5260 |
|
5261 } |
|
5262 |
|
5263 } |
|
5264 |
|
5265 } |
|
5266 |
|
5267 return $normalize ? ot_normalize_google_fonts( $ot_google_fonts ) : $ot_google_fonts; |
|
5268 |
|
5269 } |
|
5270 |
|
5271 /** |
|
5272 * Helper function to normalize the Google fonts array. |
|
5273 * |
|
5274 * @param array $google_fonts An array of fonts to nrmalize. |
|
5275 * @return array |
|
5276 * |
|
5277 * @access public |
|
5278 * @since 2.5.0 |
|
5279 */ |
|
5280 function ot_normalize_google_fonts( $google_fonts ) { |
|
5281 |
|
5282 $ot_normalized_google_fonts = array(); |
|
5283 |
|
5284 if ( is_array( $google_fonts ) && ! empty( $google_fonts ) ) { |
|
5285 |
|
5286 foreach( $google_fonts as $google_font ) { |
|
5287 |
|
5288 if( isset( $google_font['family'] ) ) { |
|
5289 |
|
5290 $id = str_replace( ' ', '+', $google_font['family'] ); |
|
5291 |
|
5292 $ot_normalized_google_fonts[ $id ] = array( |
|
5293 'family' => $google_font['family'] |
|
5294 ); |
|
5295 |
|
5296 if( isset( $google_font['variants'] ) ) { |
|
5297 |
|
5298 $ot_normalized_google_fonts[ $id ]['variants'] = $google_font['variants']; |
|
5299 |
|
5300 } |
|
5301 |
|
5302 if( isset( $google_font['subsets'] ) ) { |
|
5303 |
|
5304 $ot_normalized_google_fonts[ $id ]['subsets'] = $google_font['subsets']; |
|
5305 |
|
5306 } |
|
5307 |
|
5308 } |
|
5309 |
|
5310 } |
|
5311 |
|
5312 } |
|
5313 |
|
5314 return $ot_normalized_google_fonts; |
|
5315 |
|
5316 } |
|
5317 |
|
5318 /** |
|
4108 * Helper function to register a WPML string |
5319 * Helper function to register a WPML string |
4109 * |
5320 * |
4110 * @access public |
5321 * @access public |
4111 * @since 2.1 |
5322 * @since 2.1 |
4112 */ |
5323 */ |
4133 icl_unregister_string( 'Theme Options', $id ); |
5344 icl_unregister_string( 'Theme Options', $id ); |
4134 |
5345 |
4135 } |
5346 } |
4136 |
5347 |
4137 } |
5348 } |
5349 |
|
5350 /** |
|
5351 * Maybe migrate Settings |
|
5352 * |
|
5353 * @return void |
|
5354 * |
|
5355 * @access public |
|
5356 * @since 2.3.3 |
|
5357 */ |
|
5358 if ( ! function_exists( 'ot_maybe_migrate_settings' ) ) { |
|
5359 |
|
5360 function ot_maybe_migrate_settings() { |
|
5361 |
|
5362 // Filter the ID to migrate from |
|
5363 $settings_id = apply_filters( 'ot_migrate_settings_id', '' ); |
|
5364 |
|
5365 // Attempt to migrate Settings |
|
5366 if ( ! empty( $settings_id ) && get_option( ot_settings_id() ) === false && ot_settings_id() !== $settings_id ) { |
|
5367 |
|
5368 // Old settings |
|
5369 $settings = get_option( $settings_id ); |
|
5370 |
|
5371 // Check for array keys |
|
5372 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
|
5373 |
|
5374 update_option( ot_settings_id(), $settings ); |
|
5375 |
|
5376 } |
|
5377 |
|
5378 } |
|
5379 |
|
5380 } |
|
5381 |
|
5382 } |
|
5383 |
|
5384 /** |
|
5385 * Maybe migrate Option |
|
5386 * |
|
5387 * @return void |
|
5388 * |
|
5389 * @access public |
|
5390 * @since 2.3.3 |
|
5391 */ |
|
5392 if ( ! function_exists( 'ot_maybe_migrate_options' ) ) { |
|
5393 |
|
5394 function ot_maybe_migrate_options() { |
|
5395 |
|
5396 // Filter the ID to migrate from |
|
5397 $options_id = apply_filters( 'ot_migrate_options_id', '' ); |
|
5398 |
|
5399 // Attempt to migrate Theme Options |
|
5400 if ( ! empty( $options_id ) && get_option( ot_options_id() ) === false && ot_options_id() !== $options_id ) { |
|
5401 |
|
5402 // Old options |
|
5403 $options = get_option( $options_id ); |
|
5404 |
|
5405 // Migrate to new ID |
|
5406 update_option( ot_options_id(), $options ); |
|
5407 |
|
5408 } |
|
5409 |
|
5410 } |
|
5411 |
|
5412 } |
|
5413 |
|
5414 /** |
|
5415 * Maybe migrate Layouts |
|
5416 * |
|
5417 * @return void |
|
5418 * |
|
5419 * @access public |
|
5420 * @since 2.3.3 |
|
5421 */ |
|
5422 if ( ! function_exists( 'ot_maybe_migrate_layouts' ) ) { |
|
5423 |
|
5424 function ot_maybe_migrate_layouts() { |
|
5425 |
|
5426 // Filter the ID to migrate from |
|
5427 $layouts_id = apply_filters( 'ot_migrate_layouts_id', '' ); |
|
5428 |
|
5429 // Attempt to migrate Layouts |
|
5430 if ( ! empty( $layouts_id ) && get_option( ot_layouts_id() ) === false && ot_layouts_id() !== $layouts_id ) { |
|
5431 |
|
5432 // Old options |
|
5433 $layouts = get_option( $layouts_id ); |
|
5434 |
|
5435 // Migrate to new ID |
|
5436 update_option( ot_layouts_id(), $layouts ); |
|
5437 |
|
5438 } |
|
5439 |
|
5440 } |
|
5441 |
|
5442 } |
|
5443 |
|
5444 /** |
|
5445 * Returns an array with the post format gallery meta box. |
|
5446 * |
|
5447 * @param mixed $pages Excepts a comma separated string or array of |
|
5448 * post_types and is what tells the metabox where to |
|
5449 * display. Default 'post'. |
|
5450 * @return array |
|
5451 * |
|
5452 * @access public |
|
5453 * @since 2.4.0 |
|
5454 */ |
|
5455 function ot_meta_box_post_format_gallery( $pages = 'post' ) { |
|
5456 |
|
5457 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'gallery', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5458 return false; |
|
5459 |
|
5460 if ( is_string( $pages ) ) |
|
5461 $pages = explode( ',', $pages ); |
|
5462 |
|
5463 return apply_filters( 'ot_meta_box_post_format_gallery', array( |
|
5464 'id' => 'ot-post-format-gallery', |
|
5465 'title' => __( 'Gallery', 'option-tree' ), |
|
5466 'desc' => '', |
|
5467 'pages' => $pages, |
|
5468 'context' => 'side', |
|
5469 'priority' => 'low', |
|
5470 'fields' => array( |
|
5471 array( |
|
5472 'id' => '_format_gallery', |
|
5473 'label' => '', |
|
5474 'desc' => '', |
|
5475 'std' => '', |
|
5476 'type' => 'gallery', |
|
5477 'class' => 'ot-gallery-shortcode' |
|
5478 ) |
|
5479 ) |
|
5480 ), $pages ); |
|
5481 |
|
5482 } |
|
5483 |
|
5484 /** |
|
5485 * Returns an array with the post format link metabox. |
|
5486 * |
|
5487 * @param mixed $pages Excepts a comma separated string or array of |
|
5488 * post_types and is what tells the metabox where to |
|
5489 * display. Default 'post'. |
|
5490 * @return array |
|
5491 * |
|
5492 * @access public |
|
5493 * @since 2.4.0 |
|
5494 */ |
|
5495 function ot_meta_box_post_format_link( $pages = 'post' ) { |
|
5496 |
|
5497 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'link', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5498 return false; |
|
5499 |
|
5500 if ( is_string( $pages ) ) |
|
5501 $pages = explode( ',', $pages ); |
|
5502 |
|
5503 return apply_filters( 'ot_meta_box_post_format_link', array( |
|
5504 'id' => 'ot-post-format-link', |
|
5505 'title' => __( 'Link', 'option-tree' ), |
|
5506 'desc' => '', |
|
5507 'pages' => $pages, |
|
5508 'context' => 'side', |
|
5509 'priority' => 'low', |
|
5510 'fields' => array( |
|
5511 array( |
|
5512 'id' => '_format_link_url', |
|
5513 'label' => '', |
|
5514 'desc' => __( 'Link URL', 'option-tree' ), |
|
5515 'std' => '', |
|
5516 'type' => 'text' |
|
5517 ), |
|
5518 array( |
|
5519 'id' => '_format_link_title', |
|
5520 'label' => '', |
|
5521 'desc' => __( 'Link Title', 'option-tree' ), |
|
5522 'std' => '', |
|
5523 'type' => 'text' |
|
5524 ) |
|
5525 ) |
|
5526 ), $pages ); |
|
5527 |
|
5528 } |
|
5529 |
|
5530 /** |
|
5531 * Returns an array with the post format quote metabox. |
|
5532 * |
|
5533 * @param mixed $pages Excepts a comma separated string or array of |
|
5534 * post_types and is what tells the metabox where to |
|
5535 * display. Default 'post'. |
|
5536 * @return array |
|
5537 * |
|
5538 * @access public |
|
5539 * @since 2.4.0 |
|
5540 */ |
|
5541 function ot_meta_box_post_format_quote( $pages = 'post' ) { |
|
5542 |
|
5543 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'quote', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5544 return false; |
|
5545 |
|
5546 if ( is_string( $pages ) ) |
|
5547 $pages = explode( ',', $pages ); |
|
5548 |
|
5549 return apply_filters( 'ot_meta_box_post_format_quote', array( |
|
5550 'id' => 'ot-post-format-quote', |
|
5551 'title' => __( 'Quote', 'option-tree' ), |
|
5552 'desc' => '', |
|
5553 'pages' => $pages, |
|
5554 'context' => 'side', |
|
5555 'priority' => 'low', |
|
5556 'fields' => array( |
|
5557 array( |
|
5558 'id' => '_format_quote_source_name', |
|
5559 'label' => '', |
|
5560 'desc' => __( 'Source Name (ex. author, singer, actor)', 'option-tree' ), |
|
5561 'std' => '', |
|
5562 'type' => 'text' |
|
5563 ), |
|
5564 array( |
|
5565 'id' => '_format_quote_source_url', |
|
5566 'label' => '', |
|
5567 'desc' => __( 'Source URL', 'option-tree' ), |
|
5568 'std' => '', |
|
5569 'type' => 'text' |
|
5570 ), |
|
5571 array( |
|
5572 'id' => '_format_quote_source_title', |
|
5573 'label' => '', |
|
5574 'desc' => __( 'Source Title (ex. book, song, movie)', 'option-tree' ), |
|
5575 'std' => '', |
|
5576 'type' => 'text' |
|
5577 ), |
|
5578 array( |
|
5579 'id' => '_format_quote_source_date', |
|
5580 'label' => '', |
|
5581 'desc' => __( 'Source Date', 'option-tree' ), |
|
5582 'std' => '', |
|
5583 'type' => 'text' |
|
5584 ) |
|
5585 ) |
|
5586 ), $pages ); |
|
5587 |
|
5588 } |
|
5589 |
|
5590 /** |
|
5591 * Returns an array with the post format video metabox. |
|
5592 * |
|
5593 * @param mixed $pages Excepts a comma separated string or array of |
|
5594 * post_types and is what tells the metabox where to |
|
5595 * display. Default 'post'. |
|
5596 * @return array |
|
5597 * |
|
5598 * @access public |
|
5599 * @since 2.4.0 |
|
5600 */ |
|
5601 function ot_meta_box_post_format_video( $pages = 'post' ) { |
|
5602 |
|
5603 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'video', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5604 return false; |
|
5605 |
|
5606 if ( is_string( $pages ) ) |
|
5607 $pages = explode( ',', $pages ); |
|
5608 |
|
5609 return apply_filters( 'ot_meta_box_post_format_video', array( |
|
5610 'id' => 'ot-post-format-video', |
|
5611 'title' => __( 'Video', 'option-tree' ), |
|
5612 'desc' => '', |
|
5613 'pages' => $pages, |
|
5614 'context' => 'side', |
|
5615 'priority' => 'low', |
|
5616 'fields' => array( |
|
5617 array( |
|
5618 'id' => '_format_video_embed', |
|
5619 'label' => '', |
|
5620 'desc' => sprintf( __( 'Embed video from services like Youtube, Vimeo, or Hulu. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[video]</code>' ), |
|
5621 'std' => '', |
|
5622 'type' => 'textarea' |
|
5623 ) |
|
5624 ) |
|
5625 ), $pages ); |
|
5626 |
|
5627 } |
|
5628 |
|
5629 /** |
|
5630 * Returns an array with the post format audio metabox. |
|
5631 * |
|
5632 * @param mixed $pages Excepts a comma separated string or array of |
|
5633 * post_types and is what tells the metabox where to |
|
5634 * display. Default 'post'. |
|
5635 * @return array |
|
5636 * |
|
5637 * @access public |
|
5638 * @since 2.4.0 |
|
5639 */ |
|
5640 function ot_meta_box_post_format_audio( $pages = 'post' ) { |
|
5641 |
|
5642 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'audio', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5643 return false; |
|
5644 |
|
5645 if ( is_string( $pages ) ) |
|
5646 $pages = explode( ',', $pages ); |
|
5647 |
|
5648 return apply_filters( 'ot_meta_box_post_format_audio', array( |
|
5649 'id' => 'ot-post-format-audio', |
|
5650 'title' => __( 'Audio', 'option-tree' ), |
|
5651 'desc' => '', |
|
5652 'pages' => $pages, |
|
5653 'context' => 'side', |
|
5654 'priority' => 'low', |
|
5655 'fields' => array( |
|
5656 array( |
|
5657 'id' => '_format_audio_embed', |
|
5658 'label' => '', |
|
5659 'desc' => sprintf( __( 'Embed audio from services like SoundCloud and Rdio. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[audio]</code>' ), |
|
5660 'std' => '', |
|
5661 'type' => 'textarea' |
|
5662 ) |
|
5663 ) |
|
5664 ), $pages ); |
|
5665 |
|
5666 } |
|
5667 |
|
5668 /** |
|
5669 * Returns the option type by ID. |
|
5670 * |
|
5671 * @param string $option_id The option ID |
|
5672 * @return string $settings_id The settings array ID |
|
5673 * @return string The option type. |
|
5674 * |
|
5675 * @access public |
|
5676 * @since 2.4.2 |
|
5677 */ |
|
5678 if ( ! function_exists( 'ot_get_option_type_by_id' ) ) { |
|
5679 |
|
5680 function ot_get_option_type_by_id( $option_id, $settings_id = '' ) { |
|
5681 |
|
5682 if ( empty( $settings_id ) ) { |
|
5683 |
|
5684 $settings_id = ot_settings_id(); |
|
5685 |
|
5686 } |
|
5687 |
|
5688 $settings = get_option( $settings_id, array() ); |
|
5689 |
|
5690 if ( isset( $settings['settings'] ) ) { |
|
5691 |
|
5692 foreach( $settings['settings'] as $value ) { |
|
5693 |
|
5694 if ( $option_id == $value['id'] && isset( $value['type'] ) ) { |
|
5695 |
|
5696 return $value['type']; |
|
5697 |
|
5698 } |
|
5699 |
|
5700 } |
|
5701 |
|
5702 } |
|
5703 |
|
5704 return false; |
|
5705 |
|
5706 } |
|
5707 |
|
5708 } |
|
5709 |
|
5710 /** |
|
5711 * Build an array of potential Theme Options that could share terms |
|
5712 * |
|
5713 * @return array |
|
5714 * |
|
5715 * @access private |
|
5716 * @since 2.5.4 |
|
5717 */ |
|
5718 function _ot_settings_potential_shared_terms() { |
|
5719 |
|
5720 $options = array(); |
|
5721 $settings = get_option( ot_settings_id(), array() ); |
|
5722 $option_types = array( |
|
5723 'category-checkbox', |
|
5724 'category-select', |
|
5725 'tag-checkbox', |
|
5726 'tag-select', |
|
5727 'taxonomy-checkbox', |
|
5728 'taxonomy-select' |
|
5729 ); |
|
5730 |
|
5731 if ( isset( $settings['settings'] ) ) { |
|
5732 |
|
5733 foreach( $settings['settings'] as $value ) { |
|
5734 |
|
5735 if ( isset( $value['type'] ) ) { |
|
5736 |
|
5737 if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
|
5738 |
|
5739 $saved = ot_get_option( $value['id'] ); |
|
5740 |
|
5741 foreach( $value['settings'] as $item ) { |
|
5742 |
|
5743 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
|
5744 $sub_options = array(); |
|
5745 |
|
5746 foreach( $saved as $sub_key => $sub_value ) { |
|
5747 if ( isset( $sub_value[$item['id']] ) ) { |
|
5748 $sub_options[$sub_key] = $sub_value[$item['id']]; |
|
5749 } |
|
5750 } |
|
5751 |
|
5752 if ( ! empty( $sub_options ) ) { |
|
5753 $options[] = array( |
|
5754 'id' => $item['id'], |
|
5755 'taxonomy' => $value['taxonomy'], |
|
5756 'parent' => $value['id'], |
|
5757 'value' => $sub_options |
|
5758 ); |
|
5759 } |
|
5760 } |
|
5761 |
|
5762 } |
|
5763 |
|
5764 } |
|
5765 |
|
5766 if ( in_array( $value['type'], $option_types ) ) { |
|
5767 $saved = ot_get_option( $value['id'] ); |
|
5768 if ( ! empty( $saved ) ) { |
|
5769 $options[] = array( |
|
5770 'id' => $value['id'], |
|
5771 'taxonomy' => $value['taxonomy'], |
|
5772 'value' => $saved |
|
5773 ); |
|
5774 } |
|
5775 } |
|
5776 |
|
5777 } |
|
5778 |
|
5779 } |
|
5780 |
|
5781 } |
|
5782 |
|
5783 return $options; |
|
5784 |
|
5785 } |
|
5786 |
|
5787 /** |
|
5788 * Build an array of potential Meta Box options that could share terms |
|
5789 * |
|
5790 * @return array |
|
5791 * |
|
5792 * @access private |
|
5793 * @since 2.5.4 |
|
5794 */ |
|
5795 function _ot_meta_box_potential_shared_terms() { |
|
5796 global $ot_meta_boxes; |
|
5797 |
|
5798 $options = array(); |
|
5799 $settings = $ot_meta_boxes; |
|
5800 $option_types = array( |
|
5801 'category-checkbox', |
|
5802 'category-select', |
|
5803 'tag-checkbox', |
|
5804 'tag-select', |
|
5805 'taxonomy-checkbox', |
|
5806 'taxonomy-select' |
|
5807 ); |
|
5808 |
|
5809 foreach( $settings as $setting ) { |
|
5810 |
|
5811 if ( isset( $setting['fields'] ) ) { |
|
5812 |
|
5813 foreach( $setting['fields'] as $value ) { |
|
5814 |
|
5815 if ( isset( $value['type'] ) ) { |
|
5816 |
|
5817 if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
|
5818 |
|
5819 $children = array(); |
|
5820 |
|
5821 foreach( $value['settings'] as $item ) { |
|
5822 |
|
5823 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
|
5824 |
|
5825 $children[$value['id']][] = $item['id']; |
|
5826 |
|
5827 } |
|
5828 |
|
5829 } |
|
5830 |
|
5831 if ( ! empty( $children[$value['id']] ) ) { |
|
5832 $options[] = array( |
|
5833 'id' => $value['id'], |
|
5834 'children' => $children[$value['id']], |
|
5835 'taxonomy' => $value['taxonomy'], |
|
5836 ); |
|
5837 } |
|
5838 |
|
5839 } |
|
5840 |
|
5841 if ( in_array( $value['type'], $option_types ) ) { |
|
5842 |
|
5843 $options[] = array( |
|
5844 'id' => $value['id'], |
|
5845 'taxonomy' => $value['taxonomy'], |
|
5846 ); |
|
5847 |
|
5848 } |
|
5849 |
|
5850 } |
|
5851 |
|
5852 } |
|
5853 |
|
5854 } |
|
5855 |
|
5856 } |
|
5857 |
|
5858 return $options; |
|
5859 |
|
5860 } |
|
5861 |
|
5862 /** |
|
5863 * Update terms when a term gets split. |
|
5864 * |
|
5865 * @param int $term_id ID of the formerly shared term. |
|
5866 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
|
5867 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
|
5868 * @param string $taxonomy Taxonomy for the split term. |
|
5869 * @return void |
|
5870 * |
|
5871 * @access public |
|
5872 * @since 2.5.4 |
|
5873 */ |
|
5874 function ot_split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
|
5875 |
|
5876 // Process the Theme Options |
|
5877 $settings = _ot_settings_potential_shared_terms(); |
|
5878 $old_options = get_option( ot_options_id(), array() ); |
|
5879 $new_options = $old_options; |
|
5880 |
|
5881 // Process the saved settings |
|
5882 if ( ! empty( $settings ) && ! empty( $old_options ) ) { |
|
5883 |
|
5884 // Loop over the Theme Options |
|
5885 foreach( $settings as $option ) { |
|
5886 |
|
5887 if ( ! is_array( $option['taxonomy'] ) ) { |
|
5888 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
|
5889 } |
|
5890 |
|
5891 if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
|
5892 continue; |
|
5893 } |
|
5894 |
|
5895 // The option ID was found |
|
5896 if ( array_key_exists( $option['id'], $old_options ) || ( isset( $option['parent'] ) && array_key_exists( $option['parent'], $old_options ) ) ) { |
|
5897 |
|
5898 // This is a list item, we have to go deeper |
|
5899 if ( isset( $option['parent'] ) ) { |
|
5900 |
|
5901 // Loop over the array |
|
5902 foreach( $option['value'] as $key => $value ) { |
|
5903 |
|
5904 // The value is an array of IDs |
|
5905 if ( is_array( $value ) ) { |
|
5906 |
|
5907 // Loop over the sub array |
|
5908 foreach( $value as $sub_key => $sub_value ) { |
|
5909 |
|
5910 if ( $sub_value == $term_id ) { |
|
5911 |
|
5912 unset( $new_options[$option['parent']][$key][$option['id']][$sub_key] ); |
|
5913 $new_options[$option['parent']][$key][$option['id']][$new_term_id] = $new_term_id; |
|
5914 |
|
5915 } |
|
5916 |
|
5917 } |
|
5918 |
|
5919 } else if ( $value == $term_id ) { |
|
5920 |
|
5921 unset( $new_options[$option['parent']][$key][$option['id']] ); |
|
5922 $new_options[$option['parent']][$key][$option['id']] = $new_term_id; |
|
5923 |
|
5924 } |
|
5925 |
|
5926 } |
|
5927 |
|
5928 } else { |
|
5929 |
|
5930 // The value is an array of IDs |
|
5931 if ( is_array( $option['value'] ) ) { |
|
5932 |
|
5933 // Loop over the array |
|
5934 foreach( $option['value'] as $key => $value ) { |
|
5935 |
|
5936 // It's a single value, just replace it |
|
5937 if ( $value == $term_id ) { |
|
5938 |
|
5939 unset( $new_options[$option['id']][$key] ); |
|
5940 $new_options[$option['id']][$new_term_id] = $new_term_id; |
|
5941 |
|
5942 } |
|
5943 |
|
5944 } |
|
5945 |
|
5946 // It's a single value, just replace it |
|
5947 } else if ( $option['value'] == $term_id ) { |
|
5948 |
|
5949 $new_options[$option['id']] = $new_term_id; |
|
5950 |
|
5951 } |
|
5952 |
|
5953 } |
|
5954 |
|
5955 } |
|
5956 |
|
5957 } |
|
5958 |
|
5959 } |
|
5960 |
|
5961 // Options need to be updated |
|
5962 if ( $old_options !== $new_options ) { |
|
5963 update_option( ot_options_id(), $new_options ); |
|
5964 } |
|
5965 |
|
5966 // Process the Meta Boxes |
|
5967 $meta_settings = _ot_meta_box_potential_shared_terms(); |
|
5968 $option_types = array( |
|
5969 'category-checkbox', |
|
5970 'category-select', |
|
5971 'tag-checkbox', |
|
5972 'tag-select', |
|
5973 'taxonomy-checkbox', |
|
5974 'taxonomy-select' |
|
5975 ); |
|
5976 |
|
5977 if ( ! empty( $meta_settings ) ) { |
|
5978 $old_meta = array(); |
|
5979 |
|
5980 foreach( $meta_settings as $option ) { |
|
5981 |
|
5982 if ( ! is_array( $option['taxonomy'] ) ) { |
|
5983 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
|
5984 } |
|
5985 |
|
5986 if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
|
5987 continue; |
|
5988 } |
|
5989 |
|
5990 if ( isset( $option['children'] ) ) { |
|
5991 $post_ids = get_posts( array( |
|
5992 'fields' => 'ids', |
|
5993 'meta_key' => $option['id'], |
|
5994 ) ); |
|
5995 |
|
5996 if ( $post_ids ) { |
|
5997 |
|
5998 foreach( $post_ids as $post_id ) { |
|
5999 |
|
6000 // Get the meta |
|
6001 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
|
6002 $new_meta = $old_meta; |
|
6003 |
|
6004 // Has a saved value |
|
6005 if ( ! empty( $old_meta ) && is_array( $old_meta ) ) { |
|
6006 |
|
6007 // Loop over the array |
|
6008 foreach( $old_meta as $key => $value ) { |
|
6009 |
|
6010 foreach( $value as $sub_key => $sub_value ) { |
|
6011 |
|
6012 if ( in_array( $sub_key, $option['children'] ) ) { |
|
6013 |
|
6014 // The value is an array of IDs |
|
6015 if ( is_array( $sub_value ) ) { |
|
6016 |
|
6017 // Loop over the array |
|
6018 foreach( $sub_value as $sub_sub_key => $sub_sub_value ) { |
|
6019 |
|
6020 // It's a single value, just replace it |
|
6021 if ( $sub_sub_value == $term_id ) { |
|
6022 |
|
6023 unset( $new_meta[$key][$sub_key][$sub_sub_key] ); |
|
6024 $new_meta[$key][$sub_key][$new_term_id] = $new_term_id; |
|
6025 |
|
6026 } |
|
6027 |
|
6028 } |
|
6029 |
|
6030 // It's a single value, just replace it |
|
6031 } else if ( $sub_value == $term_id ) { |
|
6032 |
|
6033 $new_meta[$key][$sub_key] = $new_term_id; |
|
6034 |
|
6035 } |
|
6036 |
|
6037 } |
|
6038 |
|
6039 } |
|
6040 |
|
6041 } |
|
6042 |
|
6043 // Update |
|
6044 if ( $old_meta !== $new_meta ) { |
|
6045 |
|
6046 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
|
6047 |
|
6048 } |
|
6049 |
|
6050 } |
|
6051 |
|
6052 } |
|
6053 |
|
6054 } |
|
6055 |
|
6056 } else { |
|
6057 $post_ids = get_posts( array( |
|
6058 'fields' => 'ids', |
|
6059 'meta_query' => array( |
|
6060 'key' => $option['id'], |
|
6061 'value' => $term_id, |
|
6062 'compare' => 'IN' |
|
6063 ), |
|
6064 ) ); |
|
6065 |
|
6066 if ( $post_ids ) { |
|
6067 |
|
6068 foreach( $post_ids as $post_id ) { |
|
6069 |
|
6070 // Get the meta |
|
6071 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
|
6072 $new_meta = $old_meta; |
|
6073 |
|
6074 // Has a saved value |
|
6075 if ( ! empty( $old_meta ) ) { |
|
6076 |
|
6077 // The value is an array of IDs |
|
6078 if ( is_array( $old_meta ) ) { |
|
6079 |
|
6080 // Loop over the array |
|
6081 foreach( $old_meta as $key => $value ) { |
|
6082 |
|
6083 // It's a single value, just replace it |
|
6084 if ( $value == $term_id ) { |
|
6085 |
|
6086 unset( $new_meta[$key] ); |
|
6087 $new_meta[$new_term_id] = $new_term_id; |
|
6088 |
|
6089 } |
|
6090 |
|
6091 } |
|
6092 |
|
6093 // It's a single value, just replace it |
|
6094 } else if ( $old_meta == $term_id ) { |
|
6095 |
|
6096 $new_meta = $new_term_id; |
|
6097 |
|
6098 } |
|
6099 |
|
6100 // Update |
|
6101 if ( $old_meta !== $new_meta ) { |
|
6102 |
|
6103 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
|
6104 |
|
6105 } |
|
6106 |
|
6107 } |
|
6108 |
|
6109 } |
|
6110 |
|
6111 } |
|
6112 |
|
6113 } |
|
6114 |
|
6115 } |
|
6116 |
|
6117 } |
|
6118 |
|
6119 } |
|
6120 add_action( 'split_shared_term', 'ot_split_shared_term', 10, 4 ); |
|
4138 |
6121 |
4139 /* End of file ot-functions-admin.php */ |
6122 /* End of file ot-functions-admin.php */ |
4140 /* Location: ./includes/ot-functions-admin.php */ |
6123 /* Location: ./includes/ot-functions-admin.php */ |