configs
1 year ago
customize
1 year ago
views
4 months ago
class-everest-forms-style-customizer.php
1 year ago
class-evf-style-customizer-ajax.php
1 year ago
class-evf-style-customizer-api.php
1 year ago
functions.php
1 year ago
functions.php
335 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Enqueue fonts. |
| 5 | * |
| 6 | * @param string $font_family Font Family. |
| 7 | * @param mixed $load_locally Load font stylesheet locally. |
| 8 | * @return void |
| 9 | */ |
| 10 | function evfsc_enqueue_fonts( $font_family = '' ) { |
| 11 | |
| 12 | if ( ! empty( $font_family ) ) { |
| 13 | $font_url = 'https://fonts.googleapis.com/css?family=' . evf_clean( $font_family ); |
| 14 | |
| 15 | $font_url = evf_maybe_get_local_font_url( $font_url ); |
| 16 | |
| 17 | wp_enqueue_style( 'everest-forms-google-fonts', $font_url, array(), EVF_VERSION, 'all' ); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | function evfsc_migration() { |
| 22 | |
| 23 | if ( get_option( 'evfsc_migration_done' ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | $customizer_data = get_option( 'everest_forms_styles' ); |
| 28 | |
| 29 | if ( empty( $customizer_data ) ) { |
| 30 | return; |
| 31 | } |
| 32 | $new_structure = array(); |
| 33 | foreach ( $customizer_data as $key => $settings ) { |
| 34 | $new_structure[ $key ] = array(); |
| 35 | if ( isset( $settings['template'] ) ) { |
| 36 | $new_structure[ $key ]['template'] = $settings['template']; |
| 37 | } |
| 38 | |
| 39 | // Font Section. |
| 40 | $font_keys = array( |
| 41 | 'font_family' => 'font_family', |
| 42 | ); |
| 43 | |
| 44 | foreach ( $font_keys as $font_key => $font_container_key ) { |
| 45 | if ( isset( $settings['wrapper'][ $font_key ] ) ) { |
| 46 | $new_structure[ $key ]['font'][ $font_container_key ] = $settings['wrapper'][ $font_key ]; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Form Container Section. |
| 51 | $wrapper_keys = array( |
| 52 | 'width' => 'width', |
| 53 | 'border_type' => 'border_type', |
| 54 | 'border_width' => 'border_width', |
| 55 | 'border_radius' => 'border_radius', |
| 56 | 'border_color' => 'border_color', |
| 57 | 'background_image' => 'background_image', |
| 58 | 'background_preset' => 'background_preset', |
| 59 | 'opacity' => 'opacity', |
| 60 | 'background_position' => 'background_position', |
| 61 | 'background_size' => 'background_size', |
| 62 | 'margin' => 'margin', |
| 63 | 'padding' => 'padding', |
| 64 | ); |
| 65 | |
| 66 | foreach ( $wrapper_keys as $wrapper_key => $wrapper_container_key ) { |
| 67 | if ( isset( $settings['wrapper'][ $wrapper_key ] ) ) { |
| 68 | $new_structure[ $key ]['form_container'][ $wrapper_container_key ] = $settings['wrapper'][ $wrapper_key ]; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Field Styles Section. |
| 73 | $field_styles_keys = array( |
| 74 | 'width' => 'width', |
| 75 | 'border_type' => 'border_type', |
| 76 | 'border_width' => 'border_width', |
| 77 | 'border_radius' => 'border_radius', |
| 78 | ); |
| 79 | |
| 80 | foreach ( $field_styles_keys as $field_styles_key => $field_styles_container_key ) { |
| 81 | if ( isset( $settings['field_styles'][ $field_styles_key ] ) ) { |
| 82 | $new_structure[ $key ]['field_styles'][ $field_styles_container_key ] = $settings['field_styles'][ $field_styles_key ]; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // file upload Sections. |
| 87 | $file_upload_keys = array( |
| 88 | 'width' => 'width', |
| 89 | 'border_type' => 'border_type', |
| 90 | 'border_width' => 'border_width', |
| 91 | 'border_radius' => 'border_radius', |
| 92 | ); |
| 93 | |
| 94 | foreach ( $file_upload_keys as $file_upload_key => $file_upload_container_key ) { |
| 95 | if ( isset( $settings['file_upload'][ $file_upload_key ] ) ) { |
| 96 | $new_structure[ $key ]['file_upload_styles'][ $file_upload_container_key ] = $settings['file_upload'][ $file_upload_key ]; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Button Section. |
| 101 | $button_keys = array( |
| 102 | 'width' => 'width', |
| 103 | 'border_type' => 'border_type', |
| 104 | 'border_width' => 'border_width', |
| 105 | 'border_radius' => 'border_radius', |
| 106 | ); |
| 107 | |
| 108 | foreach ( $button_keys as $button_key => $button_container_key ) { |
| 109 | if ( isset( $settings['button'][ $button_key ] ) ) { |
| 110 | $new_structure[ $key ]['button'][ $button_container_key ] = $settings['button'][ $button_key ]; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // field label typography. |
| 115 | $field_label_typography_keys = array( |
| 116 | 'font_size' => 'field_labels_font_size', |
| 117 | 'font_style' => 'field_labels_font_style', |
| 118 | 'text_alignment' => 'field_labels_text_alignment', |
| 119 | 'line_height' => 'field_labels_line_height', |
| 120 | 'margin' => 'field_labels_margin', |
| 121 | 'padding' => 'field_labels_padding', |
| 122 | ); |
| 123 | foreach ( $field_label_typography_keys as $field_label_typography_key => $field_label_typography_container_key ) { |
| 124 | if ( isset( $settings['field_label'][ $field_label_typography_key ] ) ) { |
| 125 | $new_structure[ $key ]['typography'][ $field_label_typography_container_key ] = $settings['field_label'][ $field_label_typography_key ]; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // field Sublabel typography. |
| 130 | $field_sublabels_typography_keys = array( |
| 131 | 'font_size' => 'field_sublabels_font_size', |
| 132 | 'font_style' => 'field_sublabels_font_style', |
| 133 | 'text_alignment' => 'field_sublabels_text_alignment', |
| 134 | 'line_height' => 'field_sublabels_line_height', |
| 135 | 'margin' => 'field_sublabels_margin', |
| 136 | 'padding' => 'field_sublabels_padding', |
| 137 | ); |
| 138 | foreach ( $field_sublabels_typography_keys as $field_sublabels_typography_key => $field_sublabels_typography_container_key ) { |
| 139 | if ( isset( $settings['field_sublabel'][ $field_sublabels_typography_key ] ) ) { |
| 140 | $new_structure[ $key ]['typography'][ $field_sublabels_typography_container_key ] = $settings['field_sublabel'][ $field_sublabels_typography_key ]; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // field style typography |
| 145 | $field_styles_typography_keys = array( |
| 146 | 'font_size' => 'field_styles_font_size', |
| 147 | 'font_color ' => 'field_styles_font_color', |
| 148 | 'placeholder_font_color' => 'field_styles_placeholder_font_color', |
| 149 | 'font_style' => 'field_styles_font_style', |
| 150 | 'alignment' => 'field_styles_alignment', |
| 151 | 'border_color' => 'field_styles_border_color', |
| 152 | 'border_focus_color' => 'field_styles_border_focus_color', |
| 153 | 'margin' => 'field_styles_margin', |
| 154 | 'padding' => 'field_styles_padding', |
| 155 | ); |
| 156 | foreach ( $field_styles_typography_keys as $field_styles_typography_key => $field_styles_typography_container_key ) { |
| 157 | if ( isset( $settings['field_styles'][ $field_styles_typography_key ] ) ) { |
| 158 | $new_structure[ $key ]['typography'][ $field_styles_typography_container_key ] = $settings['field_styles'][ $field_styles_typography_key ]; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Field Description typography. |
| 163 | $field_description_typography_keys = array( |
| 164 | 'font_size' => 'field_description_font_size', |
| 165 | 'font_color ' => 'field_description_font_color', |
| 166 | 'font_style' => 'field_description_font_style', |
| 167 | 'text_alignment' => 'field_description_text_alignment', |
| 168 | 'line_height' => 'field_description_line_height', |
| 169 | 'margin' => 'field_description_margin', |
| 170 | 'padding' => 'field_description_padding', |
| 171 | ); |
| 172 | foreach ( $field_description_typography_keys as $field_description_typography_key => $field_description_typography_container_key ) { |
| 173 | if ( isset( $settings['field_description'][ $field_description_typography_key ] ) ) { |
| 174 | $new_structure[ $key ]['typography'][ $field_description_typography_container_key ] = $settings['field_description'][ $field_description_typography_key ]; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // Section Title Typography. |
| 179 | $section_title_typography_keys = array( |
| 180 | 'font_size' => 'section_title_font_size', |
| 181 | 'font_color ' => 'section_title_font_color', |
| 182 | 'font_style' => 'section_title_font_style', |
| 183 | 'text_alignment' => 'section_title_text_alignment', |
| 184 | 'line_height' => 'section_title_line_height', |
| 185 | 'margin' => 'section_title_margin', |
| 186 | 'padding' => 'section_title_padding', |
| 187 | ); |
| 188 | foreach ( $section_title_typography_keys as $section_title_typography_key => $section_title_typography_container_key ) { |
| 189 | if ( isset( $settings['section_title'][ $section_title_typography_key ] ) ) { |
| 190 | $new_structure[ $key ]['typography'][ $section_title_typography_container_key ] = $settings['section_title'][ $section_title_typography_key ]; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // File Upload Typography. |
| 195 | $file_upload_typography_keys = array( |
| 196 | 'font_size' => 'file_upload_font_size', |
| 197 | 'font_color ' => 'file_upload_font_color', |
| 198 | 'background_color' => 'file_upload_background_color', |
| 199 | 'icon_background_color' => 'file_upload_icon_background_color', |
| 200 | 'icon_color' => 'file_upload_icon_color', |
| 201 | 'border_color' => 'file_upload_border_color', |
| 202 | 'margin' => 'file_upload_margin', |
| 203 | 'padding' => 'file_upload_padding', |
| 204 | ); |
| 205 | foreach ( $file_upload_typography_keys as $file_upload_typography_key => $file_upload_typography_container_key ) { |
| 206 | if ( isset( $settings['file_upload_styles'][ $file_upload_typography_key ] ) ) { |
| 207 | $new_structure[ $key ]['typography'][ $file_upload_typography_container_key ] = $settings['file_upload_styles'][ $file_upload_typography_key ]; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // Radio Checkbox Typography. |
| 212 | $checkbox_radio_typography_keys = array( |
| 213 | 'font_size' => 'checkbox_radio_font_size', |
| 214 | 'font_color ' => 'checkbox_radio_font_color', |
| 215 | 'font_style' => 'checkbox_radio_font_style', |
| 216 | 'alignment' => 'checkbox_radio_alignment', |
| 217 | 'style_variation' => 'checkbox_radio_style_variation', |
| 218 | 'size' => 'checkbox_radio_size', |
| 219 | 'color' => 'checkbox_radio_color', |
| 220 | 'checked_color' => 'checkbox_radio_checked_color', |
| 221 | 'margin' => 'checkbox_radio_margin', |
| 222 | ); |
| 223 | foreach ( $checkbox_radio_typography_keys as $checkbox_radio_typography_key => $checkbox_radio_typography_container_key ) { |
| 224 | if ( isset( $settings['checkbox_radio_styles'][ $checkbox_radio_typography_key ] ) ) { |
| 225 | $new_structure[ $key ]['typography'][ $checkbox_radio_typography_container_key ] = $settings['checkbox_radio_styles'][ $checkbox_radio_typography_key ]; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Button Typography |
| 230 | $button_typography_keys = array( |
| 231 | 'font_size' => 'button_font_size', |
| 232 | 'font_style' => 'button_font_style', |
| 233 | 'hover_font_color' => 'button_hover_font_color', |
| 234 | 'hover_background_color' => 'button_hover_background_color', |
| 235 | 'border_color' => 'button_border_color', |
| 236 | 'alignment' => 'button_button_alignment', |
| 237 | 'border_hover_color' => 'button_border_hover_color', |
| 238 | 'line_height' => 'button_line_height', |
| 239 | 'margin' => 'button_margin', |
| 240 | 'padding' => 'button_padding', |
| 241 | ); |
| 242 | foreach ( $button_typography_keys as $button_typography_key => $button_typography_container_key ) { |
| 243 | if ( isset( $settings['button'][ $button_typography_key ] ) ) { |
| 244 | $new_structure[ $key ]['typography'][ $button_typography_container_key ] = $settings['button'][ $button_typography_key ]; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Success Message. |
| 249 | $success_message_keys = array( |
| 250 | 'show_submission_message' => 'show_submission_message', |
| 251 | 'font_size' => 'font_size', |
| 252 | 'text_alignment' => 'text_alignment', |
| 253 | 'font_color' => 'font_color', |
| 254 | 'background_color' => 'background_color', |
| 255 | 'border_type' => 'border_type', |
| 256 | 'border_width' => 'border_width', |
| 257 | 'border_color' => 'border_color', |
| 258 | 'border_radius' => 'border_radius', |
| 259 | ); |
| 260 | |
| 261 | foreach ( $success_message_keys as $success_message_key => $success_message_container_key ) { |
| 262 | if ( isset( $settings['success_message'][ $success_message_key ] ) ) { |
| 263 | $new_structure[ $key ]['success_message'][ $success_message_container_key ] = $settings['success_message'][ $success_message_key ]; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Validation Message. |
| 268 | $validation_message_keys = array( |
| 269 | 'show_submission_message' => 'show_submission_message', |
| 270 | 'font_size' => 'font_size', |
| 271 | 'text_alignment' => 'text_alignment', |
| 272 | 'font_color' => 'font_color', |
| 273 | 'background_color' => 'background_color', |
| 274 | 'border_type' => 'border_type', |
| 275 | 'border_width' => 'border_width', |
| 276 | 'border_color' => 'border_color', |
| 277 | 'border_radius' => 'border_radius', |
| 278 | ); |
| 279 | |
| 280 | foreach ( $validation_message_keys as $validation_message_key => $validation_message_container_key ) { |
| 281 | if ( isset( $settings['validation_message'][ $validation_message_key ] ) ) { |
| 282 | $new_structure[ $key ]['validation_message'][ $validation_message_container_key ] = $settings['validation_message'][ $validation_message_key ]; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Error Message. |
| 287 | $error_message_keys = array( |
| 288 | 'show_submission_message' => 'show_submission_message', |
| 289 | 'font_size' => 'font_size', |
| 290 | 'text_alignment' => 'text_alignment', |
| 291 | 'font_color' => 'font_color', |
| 292 | 'background_color' => 'background_color', |
| 293 | 'border_type' => 'border_type', |
| 294 | 'border_width' => 'border_width', |
| 295 | 'border_color' => 'border_color', |
| 296 | 'border_radius' => 'border_radius', |
| 297 | ); |
| 298 | |
| 299 | foreach ( $error_message_keys as $error_message_key => $error_message_container_key ) { |
| 300 | if ( isset( $settings['error_message'][ $error_message_key ] ) ) { |
| 301 | $new_structure[ $key ]['error_message'][ $error_message_container_key ] = $settings['error_message'][ $error_message_key ]; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // Color Compatibility. |
| 306 | $color_mappings = array( |
| 307 | 'wrapper' => array( 'background_color' => 'form_background' ), |
| 308 | 'field_styles' => array( 'background_color' => 'field_background' ), |
| 309 | 'field_label' => array( 'font_color' => 'field_label' ), |
| 310 | 'field_sublabel' => array( 'font_color' => 'field_sublabel' ), |
| 311 | 'button' => array( |
| 312 | 'font_color' => 'button_text', |
| 313 | 'background_color' => 'button_background', |
| 314 | ), |
| 315 | ); |
| 316 | |
| 317 | foreach ( $color_mappings as $setting_key => $fields ) { |
| 318 | foreach ( $fields as $field_key => $new_key ) { |
| 319 | if ( isset( $settings[ $setting_key ][ $field_key ] ) ) { |
| 320 | $new_structure[ $key ]['color_palette']['color_12'][ $new_key ] = $settings[ $setting_key ][ $field_key ]; |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | update_option( 'everest_forms_styles', array() ); |
| 327 | update_option( 'everest_forms_styles', $new_structure ); |
| 328 | update_option( 'evfsc_migration_done', true ); |
| 329 | |
| 330 | return $new_structure; |
| 331 | } |
| 332 | |
| 333 | // Run the migration function |
| 334 | evfsc_migration(); |
| 335 |