| @@ -57,20 +57,20 @@ | ||
| 57 | 57 | * @since 1.0.0 |
| 58 | 58 | * @access public |
| 59 | 59 | */ |
| 60 | 60 | public function content_template() { |
| 61 | + $control_uid = $this->get_control_uid(); | |
| 61 | 62 | ?> |
| 62 | - <div class="elementor-control-field {{ data.content_classes }}"> | |
| 63 | + <div class="elementor-control-field"> | |
| 63 | 64 | <# if ( data.label ) {#> |
| 64 | - <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> | |
| 65 | + <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label> | |
| 65 | 66 | <# } #> |
| 66 | 67 | <div class="elementor-control-input-wrapper elementor-control-unit-5"> |
| 67 | - <select id="<?php $this->print_control_uid(); ?>" data-setting="{{ data.name }}"> | |
| 68 | + <select id="<?php echo $control_uid; ?>" data-setting="{{ data.name }}"> | |
| 68 | 69 | <# |
| 69 | 70 | var printOptions = function( options ) { |
| 70 | 71 | _.each( options, function( option_title, option_value ) { #> |
| 71 | - <?php // If the option title is array of title & icon. ?> | |
| 72 | - <option value="{{ option_value }}">{{{ option_title?.title || option_title }}}</option> | |
| 72 | + <option value="{{ option_value }}">{{{ option_title }}}</option> | |
| 73 | 73 | <# } ); |
| 74 | 74 | }; |
| 75 | 75 | |
| 76 | 76 | if ( data.groups ) { |
| @@ -94,6 +94,49 @@ | ||
| 94 | 94 | <# if ( data.description ) { #> |
| 95 | 95 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 96 | 96 | <# } #> |
| 97 | 97 | <?php |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * @param string $value | |
| 102 | + * @param array $config | |
| 103 | + * | |
| 104 | + * @return string | |
| 105 | + */ | |
| 106 | + public function before_save( $value, array $config ) { | |
| 107 | + return $this->validate_value( $value, $config ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Validate the value is listed in the control options config. | |
| 112 | + * | |
| 113 | + * Avoid change settings like `html_tag` & `title_size` to a `script` tag. | |
| 114 | + * | |
| 115 | + * @param string $value | |
| 116 | + * @param array $config | |
| 117 | + * | |
| 118 | + * @return mixed|string | |
| 119 | + */ | |
| 120 | + private function validate_value( $value, array $config ) { | |
| 121 | + $is_valid = false; | |
| 122 | + | |
| 123 | + // Handle options groups. | |
| 124 | + if ( isset( $config['groups'] ) ) { | |
| 125 | + foreach ( $config['groups'] as $index => $group ) { | |
| 126 | + if ( isset( $group['options'][ $value ] ) ) { | |
| 127 | + $is_valid = true; | |
| 128 | + break; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + } else { | |
| 132 | + $is_valid = isset( $config['options'][ $value ] ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + // If it's not one of the control options. reset it to default. | |
| 136 | + if ( ! $is_valid ) { | |
| 137 | + $value = $config['default']; | |
| 138 | + } | |
| 139 | + | |
| 140 | + return $value; | |
| 98 | 141 | } |
| 99 | 142 | } |