configs
1 year ago
customize
1 week ago
views
6 months ago
class-everest-forms-style-customizer.php
1 week ago
class-evf-style-customizer-ajax.php
1 year ago
class-evf-style-customizer-api.php
1 week ago
functions.php
1 week ago
functions.php
461 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 | // Without an explicit weight list, Google Fonts only serves the family's single default |
| 14 | // face — every other Font Style weight the customizer offers then has no real face to |
| 15 | // use and falls back to inconsistent browser synthesis (EVF-2721). 300/400/700 match the |
| 16 | // weight options Schema::weight_options() actually offers. |
| 17 | $font_url = 'https://fonts.googleapis.com/css?family=' . evf_clean( $font_family ) . ':300,400,700'; |
| 18 | |
| 19 | $font_url = evf_maybe_get_local_font_url( $font_url ); |
| 20 | |
| 21 | wp_enqueue_style( 'everest-forms-google-fonts', $font_url, array(), EVF_VERSION, 'all' ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * The Google Fonts list used by the Style Customizer, cached for a week. |
| 27 | * |
| 28 | * Single source of truth for BOTH the legacy WP-Customizer select2 control |
| 29 | * ({@see EVF_Customize_Select2_Control::get_google_fonts()}) and the v2 React panel — so the |
| 30 | * font family dropdown is identical (order, labels) in either engine and the list is fetched |
| 31 | * once, not duplicated. |
| 32 | * |
| 33 | * @since x.x.x |
| 34 | * @return array List of font objects (each exposes a `family` property), or an empty array. |
| 35 | */ |
| 36 | function evfsc_get_google_fonts() { |
| 37 | $google_fonts = get_transient( 'evf_google_fonts' ); |
| 38 | |
| 39 | if ( false === $google_fonts ) { |
| 40 | $raw_google_fonts = wp_safe_remote_get( 'https://raw.githubusercontent.com/wpeverest/google-fonts/master/google-fonts.json' ); |
| 41 | $decoded = is_wp_error( $raw_google_fonts ) ? null : json_decode( wp_remote_retrieve_body( $raw_google_fonts ) ); |
| 42 | $google_fonts = isset( $decoded->items ) ? $decoded->items : array(); |
| 43 | |
| 44 | // Cache a failed/empty fetch too, just for an hour instead of a week, so a blocked or |
| 45 | // offline host retries periodically rather than repeating this blocking request on |
| 46 | // every single builder page load. |
| 47 | set_transient( 'evf_google_fonts', $google_fonts, empty( $google_fonts ) ? HOUR_IN_SECONDS : WEEK_IN_SECONDS ); |
| 48 | } |
| 49 | |
| 50 | /** This filter is documented in addons/StyleCustomizer/includes/customize/class-evf-customize-select2-control.php */ |
| 51 | $google_fonts = apply_filters( 'everest_forms_extensions_sections', $google_fonts ); |
| 52 | |
| 53 | return is_array( $google_fonts ) ? $google_fonts : array(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * The Google Fonts as a flat list of family-name strings (order preserved). |
| 58 | * |
| 59 | * Used by the v2 REST payload to populate the Font Family dropdown; matches the legacy |
| 60 | * customizer's list exactly since it derives from {@see evfsc_get_google_fonts()}. |
| 61 | * |
| 62 | * @since x.x.x |
| 63 | * @return string[] Font family names. |
| 64 | */ |
| 65 | function evfsc_get_google_font_families() { |
| 66 | $families = array(); |
| 67 | foreach ( evfsc_get_google_fonts() as $font ) { |
| 68 | if ( is_object( $font ) && isset( $font->family ) ) { |
| 69 | $families[] = (string) $font->family; |
| 70 | } elseif ( is_array( $font ) && isset( $font['family'] ) ) { |
| 71 | $families[] = (string) $font['family']; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // evfsc_get_google_fonts() derives its list from a live fetch to a GitHub-hosted JSON file |
| 76 | // (see there) — a third-party-maintained snapshot that can be stale (missing newer families |
| 77 | // like Inter/Manrope entirely) or, if the fetch fails/is blocked outright (offline local dev, |
| 78 | // a restrictive host), empty. Either way, always MERGE in a curated list of well-known |
| 79 | // families rather than only falling back to it when the live list is empty — a populated but |
| 80 | // incomplete snapshot needs the same guarantee. array_unique keeps the curated entry (first) |
| 81 | // on an exact-name collision; that's fine, the value is identical either way. |
| 82 | return array_values( array_unique( array_merge( evfsc_google_font_families_fallback(), $families ) ) ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Curated list of widely-used families, always merged into evfsc_get_google_font_families()'s |
| 87 | * result (not the full catalog) — guarantees these are always offered regardless of whether the |
| 88 | * live fetch succeeds, is stale, or fails outright. |
| 89 | * |
| 90 | * @return string[] Font family names. |
| 91 | */ |
| 92 | function evfsc_google_font_families_fallback() { |
| 93 | return array( |
| 94 | 'Roboto', |
| 95 | 'Open Sans', |
| 96 | 'Lato', |
| 97 | 'Montserrat', |
| 98 | 'Poppins', |
| 99 | 'Inter', |
| 100 | 'Nunito', |
| 101 | 'Nunito Sans', |
| 102 | 'Source Sans Pro', |
| 103 | 'Noto Sans', |
| 104 | 'Raleway', |
| 105 | 'Rubik', |
| 106 | 'Work Sans', |
| 107 | 'Mulish', |
| 108 | 'Karla', |
| 109 | 'Manrope', |
| 110 | 'Quicksand', |
| 111 | 'Ubuntu', |
| 112 | 'PT Sans', |
| 113 | 'Fira Sans', |
| 114 | 'Barlow', |
| 115 | 'Inconsolata', |
| 116 | 'DM Sans', |
| 117 | 'Josefin Sans', |
| 118 | 'Cabin', |
| 119 | 'Oxygen', |
| 120 | 'Heebo', |
| 121 | 'Hind', |
| 122 | 'Titillium Web', |
| 123 | 'Merriweather', |
| 124 | 'Playfair Display', |
| 125 | 'Lora', |
| 126 | 'PT Serif', |
| 127 | 'Libre Baskerville', |
| 128 | 'Crimson Text', |
| 129 | 'Bitter', |
| 130 | 'EB Garamond', |
| 131 | 'Roboto Slab', |
| 132 | 'Roboto Condensed', |
| 133 | 'Roboto Mono', |
| 134 | 'Oswald', |
| 135 | 'Anton', |
| 136 | 'Bebas Neue', |
| 137 | 'Dancing Script', |
| 138 | 'Pacifico', |
| 139 | 'Caveat', |
| 140 | 'Comfortaa', |
| 141 | 'Abril Fatface', |
| 142 | 'Archivo', |
| 143 | 'Space Grotesk', |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | function evfsc_migration() { |
| 148 | |
| 149 | if ( get_option( 'evfsc_migration_done' ) ) { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | $customizer_data = get_option( 'everest_forms_styles' ); |
| 154 | |
| 155 | if ( empty( $customizer_data ) ) { |
| 156 | return; |
| 157 | } |
| 158 | $new_structure = array(); |
| 159 | foreach ( $customizer_data as $key => $settings ) { |
| 160 | $new_structure[ $key ] = array(); |
| 161 | if ( isset( $settings['template'] ) ) { |
| 162 | $new_structure[ $key ]['template'] = $settings['template']; |
| 163 | } |
| 164 | |
| 165 | // Font Section. |
| 166 | $font_keys = array( |
| 167 | 'font_family' => 'font_family', |
| 168 | ); |
| 169 | |
| 170 | foreach ( $font_keys as $font_key => $font_container_key ) { |
| 171 | if ( isset( $settings['wrapper'][ $font_key ] ) ) { |
| 172 | $new_structure[ $key ]['font'][ $font_container_key ] = $settings['wrapper'][ $font_key ]; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // Form Container Section. |
| 177 | $wrapper_keys = array( |
| 178 | 'width' => 'width', |
| 179 | 'border_type' => 'border_type', |
| 180 | 'border_width' => 'border_width', |
| 181 | 'border_radius' => 'border_radius', |
| 182 | 'border_color' => 'border_color', |
| 183 | 'background_image' => 'background_image', |
| 184 | 'background_preset' => 'background_preset', |
| 185 | 'opacity' => 'opacity', |
| 186 | 'background_position' => 'background_position', |
| 187 | 'background_size' => 'background_size', |
| 188 | 'margin' => 'margin', |
| 189 | 'padding' => 'padding', |
| 190 | ); |
| 191 | |
| 192 | foreach ( $wrapper_keys as $wrapper_key => $wrapper_container_key ) { |
| 193 | if ( isset( $settings['wrapper'][ $wrapper_key ] ) ) { |
| 194 | $new_structure[ $key ]['form_container'][ $wrapper_container_key ] = $settings['wrapper'][ $wrapper_key ]; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Field Styles Section. |
| 199 | $field_styles_keys = array( |
| 200 | 'width' => 'width', |
| 201 | 'border_type' => 'border_type', |
| 202 | 'border_width' => 'border_width', |
| 203 | 'border_radius' => 'border_radius', |
| 204 | ); |
| 205 | |
| 206 | foreach ( $field_styles_keys as $field_styles_key => $field_styles_container_key ) { |
| 207 | if ( isset( $settings['field_styles'][ $field_styles_key ] ) ) { |
| 208 | $new_structure[ $key ]['field_styles'][ $field_styles_container_key ] = $settings['field_styles'][ $field_styles_key ]; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // file upload Sections. |
| 213 | $file_upload_keys = array( |
| 214 | 'width' => 'width', |
| 215 | 'border_type' => 'border_type', |
| 216 | 'border_width' => 'border_width', |
| 217 | 'border_radius' => 'border_radius', |
| 218 | ); |
| 219 | |
| 220 | foreach ( $file_upload_keys as $file_upload_key => $file_upload_container_key ) { |
| 221 | if ( isset( $settings['file_upload'][ $file_upload_key ] ) ) { |
| 222 | $new_structure[ $key ]['file_upload_styles'][ $file_upload_container_key ] = $settings['file_upload'][ $file_upload_key ]; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Button Section. |
| 227 | $button_keys = array( |
| 228 | 'width' => 'width', |
| 229 | 'border_type' => 'border_type', |
| 230 | 'border_width' => 'border_width', |
| 231 | 'border_radius' => 'border_radius', |
| 232 | ); |
| 233 | |
| 234 | foreach ( $button_keys as $button_key => $button_container_key ) { |
| 235 | if ( isset( $settings['button'][ $button_key ] ) ) { |
| 236 | $new_structure[ $key ]['button'][ $button_container_key ] = $settings['button'][ $button_key ]; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // field label typography. |
| 241 | $field_label_typography_keys = array( |
| 242 | 'font_size' => 'field_labels_font_size', |
| 243 | 'font_style' => 'field_labels_font_style', |
| 244 | 'text_alignment' => 'field_labels_text_alignment', |
| 245 | 'line_height' => 'field_labels_line_height', |
| 246 | 'margin' => 'field_labels_margin', |
| 247 | 'padding' => 'field_labels_padding', |
| 248 | ); |
| 249 | foreach ( $field_label_typography_keys as $field_label_typography_key => $field_label_typography_container_key ) { |
| 250 | if ( isset( $settings['field_label'][ $field_label_typography_key ] ) ) { |
| 251 | $new_structure[ $key ]['typography'][ $field_label_typography_container_key ] = $settings['field_label'][ $field_label_typography_key ]; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // field Sublabel typography. |
| 256 | $field_sublabels_typography_keys = array( |
| 257 | 'font_size' => 'field_sublabels_font_size', |
| 258 | 'font_style' => 'field_sublabels_font_style', |
| 259 | 'text_alignment' => 'field_sublabels_text_alignment', |
| 260 | 'line_height' => 'field_sublabels_line_height', |
| 261 | 'margin' => 'field_sublabels_margin', |
| 262 | 'padding' => 'field_sublabels_padding', |
| 263 | ); |
| 264 | foreach ( $field_sublabels_typography_keys as $field_sublabels_typography_key => $field_sublabels_typography_container_key ) { |
| 265 | if ( isset( $settings['field_sublabel'][ $field_sublabels_typography_key ] ) ) { |
| 266 | $new_structure[ $key ]['typography'][ $field_sublabels_typography_container_key ] = $settings['field_sublabel'][ $field_sublabels_typography_key ]; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // field style typography |
| 271 | $field_styles_typography_keys = array( |
| 272 | 'font_size' => 'field_styles_font_size', |
| 273 | 'font_color ' => 'field_styles_font_color', |
| 274 | 'placeholder_font_color' => 'field_styles_placeholder_font_color', |
| 275 | 'font_style' => 'field_styles_font_style', |
| 276 | 'alignment' => 'field_styles_alignment', |
| 277 | 'border_color' => 'field_styles_border_color', |
| 278 | 'border_focus_color' => 'field_styles_border_focus_color', |
| 279 | 'margin' => 'field_styles_margin', |
| 280 | 'padding' => 'field_styles_padding', |
| 281 | ); |
| 282 | foreach ( $field_styles_typography_keys as $field_styles_typography_key => $field_styles_typography_container_key ) { |
| 283 | if ( isset( $settings['field_styles'][ $field_styles_typography_key ] ) ) { |
| 284 | $new_structure[ $key ]['typography'][ $field_styles_typography_container_key ] = $settings['field_styles'][ $field_styles_typography_key ]; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Field Description typography. |
| 289 | $field_description_typography_keys = array( |
| 290 | 'font_size' => 'field_description_font_size', |
| 291 | 'font_color ' => 'field_description_font_color', |
| 292 | 'font_style' => 'field_description_font_style', |
| 293 | 'text_alignment' => 'field_description_text_alignment', |
| 294 | 'line_height' => 'field_description_line_height', |
| 295 | 'margin' => 'field_description_margin', |
| 296 | 'padding' => 'field_description_padding', |
| 297 | ); |
| 298 | foreach ( $field_description_typography_keys as $field_description_typography_key => $field_description_typography_container_key ) { |
| 299 | if ( isset( $settings['field_description'][ $field_description_typography_key ] ) ) { |
| 300 | $new_structure[ $key ]['typography'][ $field_description_typography_container_key ] = $settings['field_description'][ $field_description_typography_key ]; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // Section Title Typography. |
| 305 | $section_title_typography_keys = array( |
| 306 | 'font_size' => 'section_title_font_size', |
| 307 | 'font_color ' => 'section_title_font_color', |
| 308 | 'font_style' => 'section_title_font_style', |
| 309 | 'text_alignment' => 'section_title_text_alignment', |
| 310 | 'line_height' => 'section_title_line_height', |
| 311 | 'margin' => 'section_title_margin', |
| 312 | 'padding' => 'section_title_padding', |
| 313 | ); |
| 314 | foreach ( $section_title_typography_keys as $section_title_typography_key => $section_title_typography_container_key ) { |
| 315 | if ( isset( $settings['section_title'][ $section_title_typography_key ] ) ) { |
| 316 | $new_structure[ $key ]['typography'][ $section_title_typography_container_key ] = $settings['section_title'][ $section_title_typography_key ]; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | // File Upload Typography. |
| 321 | $file_upload_typography_keys = array( |
| 322 | 'font_size' => 'file_upload_font_size', |
| 323 | 'font_color ' => 'file_upload_font_color', |
| 324 | 'background_color' => 'file_upload_background_color', |
| 325 | 'icon_background_color' => 'file_upload_icon_background_color', |
| 326 | 'icon_color' => 'file_upload_icon_color', |
| 327 | 'border_color' => 'file_upload_border_color', |
| 328 | 'margin' => 'file_upload_margin', |
| 329 | 'padding' => 'file_upload_padding', |
| 330 | ); |
| 331 | foreach ( $file_upload_typography_keys as $file_upload_typography_key => $file_upload_typography_container_key ) { |
| 332 | if ( isset( $settings['file_upload_styles'][ $file_upload_typography_key ] ) ) { |
| 333 | $new_structure[ $key ]['typography'][ $file_upload_typography_container_key ] = $settings['file_upload_styles'][ $file_upload_typography_key ]; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Radio Checkbox Typography. |
| 338 | $checkbox_radio_typography_keys = array( |
| 339 | 'font_size' => 'checkbox_radio_font_size', |
| 340 | 'font_color ' => 'checkbox_radio_font_color', |
| 341 | 'font_style' => 'checkbox_radio_font_style', |
| 342 | 'alignment' => 'checkbox_radio_alignment', |
| 343 | 'style_variation' => 'checkbox_radio_style_variation', |
| 344 | 'size' => 'checkbox_radio_size', |
| 345 | 'color' => 'checkbox_radio_color', |
| 346 | 'checked_color' => 'checkbox_radio_checked_color', |
| 347 | 'margin' => 'checkbox_radio_margin', |
| 348 | ); |
| 349 | foreach ( $checkbox_radio_typography_keys as $checkbox_radio_typography_key => $checkbox_radio_typography_container_key ) { |
| 350 | if ( isset( $settings['checkbox_radio_styles'][ $checkbox_radio_typography_key ] ) ) { |
| 351 | $new_structure[ $key ]['typography'][ $checkbox_radio_typography_container_key ] = $settings['checkbox_radio_styles'][ $checkbox_radio_typography_key ]; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // Button Typography |
| 356 | $button_typography_keys = array( |
| 357 | 'font_size' => 'button_font_size', |
| 358 | 'font_style' => 'button_font_style', |
| 359 | 'hover_font_color' => 'button_hover_font_color', |
| 360 | 'hover_background_color' => 'button_hover_background_color', |
| 361 | 'border_color' => 'button_border_color', |
| 362 | 'alignment' => 'button_button_alignment', |
| 363 | 'border_hover_color' => 'button_border_hover_color', |
| 364 | 'line_height' => 'button_line_height', |
| 365 | 'margin' => 'button_margin', |
| 366 | 'padding' => 'button_padding', |
| 367 | ); |
| 368 | foreach ( $button_typography_keys as $button_typography_key => $button_typography_container_key ) { |
| 369 | if ( isset( $settings['button'][ $button_typography_key ] ) ) { |
| 370 | $new_structure[ $key ]['typography'][ $button_typography_container_key ] = $settings['button'][ $button_typography_key ]; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // Success Message. |
| 375 | $success_message_keys = array( |
| 376 | 'show_submission_message' => 'show_submission_message', |
| 377 | 'font_size' => 'font_size', |
| 378 | 'text_alignment' => 'text_alignment', |
| 379 | 'font_color' => 'font_color', |
| 380 | 'background_color' => 'background_color', |
| 381 | 'border_type' => 'border_type', |
| 382 | 'border_width' => 'border_width', |
| 383 | 'border_color' => 'border_color', |
| 384 | 'border_radius' => 'border_radius', |
| 385 | ); |
| 386 | |
| 387 | foreach ( $success_message_keys as $success_message_key => $success_message_container_key ) { |
| 388 | if ( isset( $settings['success_message'][ $success_message_key ] ) ) { |
| 389 | $new_structure[ $key ]['success_message'][ $success_message_container_key ] = $settings['success_message'][ $success_message_key ]; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | // Validation Message. |
| 394 | $validation_message_keys = array( |
| 395 | 'show_submission_message' => 'show_submission_message', |
| 396 | 'font_size' => 'font_size', |
| 397 | 'text_alignment' => 'text_alignment', |
| 398 | 'font_color' => 'font_color', |
| 399 | 'background_color' => 'background_color', |
| 400 | 'border_type' => 'border_type', |
| 401 | 'border_width' => 'border_width', |
| 402 | 'border_color' => 'border_color', |
| 403 | 'border_radius' => 'border_radius', |
| 404 | ); |
| 405 | |
| 406 | foreach ( $validation_message_keys as $validation_message_key => $validation_message_container_key ) { |
| 407 | if ( isset( $settings['validation_message'][ $validation_message_key ] ) ) { |
| 408 | $new_structure[ $key ]['validation_message'][ $validation_message_container_key ] = $settings['validation_message'][ $validation_message_key ]; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | // Error Message. |
| 413 | $error_message_keys = array( |
| 414 | 'show_submission_message' => 'show_submission_message', |
| 415 | 'font_size' => 'font_size', |
| 416 | 'text_alignment' => 'text_alignment', |
| 417 | 'font_color' => 'font_color', |
| 418 | 'background_color' => 'background_color', |
| 419 | 'border_type' => 'border_type', |
| 420 | 'border_width' => 'border_width', |
| 421 | 'border_color' => 'border_color', |
| 422 | 'border_radius' => 'border_radius', |
| 423 | ); |
| 424 | |
| 425 | foreach ( $error_message_keys as $error_message_key => $error_message_container_key ) { |
| 426 | if ( isset( $settings['error_message'][ $error_message_key ] ) ) { |
| 427 | $new_structure[ $key ]['error_message'][ $error_message_container_key ] = $settings['error_message'][ $error_message_key ]; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // Color Compatibility. |
| 432 | $color_mappings = array( |
| 433 | 'wrapper' => array( 'background_color' => 'form_background' ), |
| 434 | 'field_styles' => array( 'background_color' => 'field_background' ), |
| 435 | 'field_label' => array( 'font_color' => 'field_label' ), |
| 436 | 'field_sublabel' => array( 'font_color' => 'field_sublabel' ), |
| 437 | 'button' => array( |
| 438 | 'font_color' => 'button_text', |
| 439 | 'background_color' => 'button_background', |
| 440 | ), |
| 441 | ); |
| 442 | |
| 443 | foreach ( $color_mappings as $setting_key => $fields ) { |
| 444 | foreach ( $fields as $field_key => $new_key ) { |
| 445 | if ( isset( $settings[ $setting_key ][ $field_key ] ) ) { |
| 446 | $new_structure[ $key ]['color_palette']['color_12'][ $new_key ] = $settings[ $setting_key ][ $field_key ]; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | update_option( 'everest_forms_styles', array() ); |
| 453 | update_option( 'everest_forms_styles', $new_structure ); |
| 454 | update_option( 'evfsc_migration_done', true ); |
| 455 | |
| 456 | return $new_structure; |
| 457 | } |
| 458 | |
| 459 | // Run the migration function |
| 460 | evfsc_migration(); |
| 461 |