PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14.1
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14.1
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / update / class-hustle-430-migration.php
wordpress-popup / inc / update Last commit date
class-hustle-410-migration.php 5 months ago class-hustle-430-migration.php 3 years ago class-hustle-441-migration.php 3 years ago
class-hustle-430-migration.php
881 lines
1 <?php
2 /**
3 * File for Hustle_430_Migration class.
4 *
5 * @package Hustle
6 * @since 4.3.0
7 */
8
9 /**
10 * Class Hustle_430_Migration.
11 *
12 * This class handles the migration when going from 4.x.x to 4.3.x.
13 * We introduced new appearance options for which we need to migrate the
14 * existing options so the module looks the same as before the upgrade.
15 *
16 * @since 4.3.0
17 */
18 class Hustle_430_Migration {
19
20 /**
21 * Flag name to mark the migration as "done".
22 *
23 * @since 4.3.0
24 */
25 const MIGRATION_FLAG = 'hustle_430_migrated';
26
27 /**
28 * Modules to migrate as an associative array.
29 * The module_id is the key, the module_mode is the value.
30 *
31 * @since 4.3.0
32 * @var array
33 */
34 private $modules_to_migrate = array();
35
36 /**
37 * Content metas of the modules to migrate in the current batch.
38 * The module ID is the key, and the content meta its value.
39 * Updated on each batch iteration.
40 *
41 * @since 4.3.0
42 * @var array
43 */
44 private $content_metas = array();
45
46 /**
47 * Current module ID during the metas iteration.
48 * Updated on each meta iteration.
49 *
50 * @var int
51 */
52 private $module_id;
53
54 /**
55 * Whether the current module is optin.
56 * Updated on each meta iteration.
57 *
58 * @var bool
59 */
60 private $is_optin;
61
62 /**
63 * Whether the colors should be switched to 'custom'.
64 * Updated on each meta iteration.
65 *
66 * @var bool
67 */
68 private $switch_colors_to_custom;
69
70 /**
71 * Hustle_401_Migration class constructor.
72 */
73 public function __construct() {
74
75 if ( $this->should_migrate() ) {
76 add_action( 'init', array( $this, 'do_migration' ) );
77 }
78 }
79
80 /**
81 * Checks whether we should run da migration.
82 *
83 * @since 4.1.0
84 *
85 * @return bool
86 */
87 private function should_migrate() {
88
89 // If migration is being forced, do it.
90 if ( filter_input( INPUT_GET, 'run-430-migration', FILTER_VALIDATE_BOOLEAN ) ) {
91 return true;
92 }
93
94 // If migration was already done, skip.
95 if ( Hustle_Migration::is_migrated( self::MIGRATION_FLAG ) ) {
96 return false;
97 }
98
99 return true;
100 }
101
102 /**
103 * Does the migration from 4.x.x to 4.3.x.
104 *
105 * @since 4.3.0
106 */
107 public function do_migration() {
108
109 $this->modules_to_migrate = $this->get_all_non_ssharing_modules();
110
111 // There are no modules to migrate. Set the flag as migrated and bail out.
112 if ( empty( $this->modules_to_migrate ) ) {
113 Hustle_Migration::migration_passed( self::MIGRATION_FLAG );
114 return;
115 }
116
117 $limit = apply_filters( 'hustle_430_migration_limit', 100 );
118
119 do {
120 $offset = get_option( 'hustle_430_migration_offset', 0 );
121
122 $module_ids = array_slice( array_keys( $this->modules_to_migrate ), $offset, $limit );
123
124 $count_modules = count( $module_ids );
125 $offset += $limit;
126
127 if ( ! empty( $count_modules ) ) {
128 $batch_of_design_metas = $this->get_modules_design_meta( $module_ids );
129
130 $this->content_metas = $this->get_modules_content_meta( $module_ids );
131
132 $this->migrate_batch_of_metas( $batch_of_design_metas );
133 }
134
135 update_option( 'hustle_430_migration_offset', $offset );
136
137 } while ( $count_modules === $limit );
138
139 Hustle_Migration::migration_passed( self::MIGRATION_FLAG );
140 delete_option( 'hustle_430_migration_offset' );
141 delete_option( 'hustle_430_modules_to_migrate' );
142 }
143
144 /**
145 * Retrieves the ID and Mode of all modules that are not Social Sharing.
146 *
147 * @since 4.3.0
148 * @return array
149 */
150 private function get_all_non_ssharing_modules() {
151 $modules = get_option( 'hustle_430_modules_to_migrate', false );
152
153 if ( ! $modules ) {
154 $raw_modules = $this->fetch_non_ssharing_modules();
155 $modules = wp_list_pluck( $raw_modules, 'module_mode', 'module_id' );
156
157 update_option( 'hustle_430_modules_to_migrate', $modules, false );
158 }
159
160 return $modules;
161 }
162
163 /**
164 * Fetch all non-ssharing modules id and mode.
165 *
166 * @since 4.3.0
167 * @return array
168 */
169 private function fetch_non_ssharing_modules() {
170 global $wpdb;
171
172 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
173 $results = $wpdb->get_results(
174 "SELECT module_id, module_mode
175 FROM {$wpdb->prefix}hustle_modules
176 WHERE module_type != 'social_sharing'"
177 );
178
179 return $results;
180 }
181
182 /**
183 * Gets all the stored design metas.
184 *
185 * @since 4.3.0
186 *
187 * @param array $module_ids Array with the IDs of the modules to retrieve the metas for.
188 * @return array
189 */
190 private function get_modules_design_meta( $module_ids ) {
191 global $wpdb;
192
193 $results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
194 $wpdb->prepare(
195 "SELECT meta_id, module_id, meta_value
196 FROM {$wpdb->prefix}hustle_modules_meta
197 WHERE module_id IN (" . implode( ', ', array_fill( 0, count( $module_ids ), '%d' ) ) . ")
198 AND meta_key = 'design'",
199 $module_ids
200 )
201 );
202
203 return $results;
204 }
205
206 /**
207 * Gets all the stored content metas.
208 *
209 * @since 4.3.0
210 *
211 * @param array $module_ids Array with the IDs of the modules to retrieve the metas for.
212 * @return array
213 */
214 private function get_modules_content_meta( $module_ids ) {
215 global $wpdb;
216
217 $results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
218 $wpdb->prepare(
219 "SELECT module_id, meta_value
220 FROM {$wpdb->prefix}hustle_modules_meta
221 WHERE module_id IN (" . implode( ', ', array_fill( 0, count( $module_ids ), '%d' ) ) . ")
222 AND meta_key = 'content'",
223 $module_ids
224 )
225 );
226
227 $metas = array();
228 foreach ( $results as $result ) {
229 $metas[ $result->module_id ] = json_decode( $result->meta_value );
230 }
231
232 return $metas;
233 }
234
235 /**
236 * Loops through the current batch of metas updating its settings in the database.
237 *
238 * @since 4.3.0
239 * @param array $design_metas Current batch of metas.
240 * @return void
241 */
242 private function migrate_batch_of_metas( $design_metas ) {
243 global $wpdb;
244
245 foreach ( $design_metas as $meta ) {
246 $old_design = json_decode( $meta->meta_value, true );
247
248 // Check for an old module property. If it's not set, it means that this module was created in 4.3.0. Skip.
249 if ( ! isset( $old_design['border'] ) ) {
250 continue;
251 }
252
253 $this->module_id = $meta->module_id;
254 $this->is_optin = 'optin' === $this->modules_to_migrate[ $meta->module_id ];
255 $this->switch_colors_to_custom = false;
256
257 // This should run before "migrate_colors" because "customize_colors" value depends on this.
258 $new_border_spacing_shadow = $this->migrate_border_spacing_shadow( $old_design );
259
260 $new_colors = $this->migrate_colors( $old_design );
261
262 $new_customize_elements = $this->migrate_customize_elements( $old_design );
263
264 $new_typography = $this->migrate_typography( $old_design );
265
266 $new_design = $new_typography + $new_customize_elements + $new_colors + $new_border_spacing_shadow + $old_design;
267
268 $new_design['enable_mobile_settings'] = '1';
269
270 if ( '1' === $old_design['customize_size'] && 'all' === $old_design['apply_custom_size_to'] ) {
271 $new_design['customize_size_mobile'] = '1';
272 $new_design['custom_width_mobile'] = $old_design['custom_width'];
273 $new_design['custom_height_mobile'] = $old_design['custom_height'];
274 }
275
276 // Save transformed conditions.
277 $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
278 Hustle_Db::modules_meta_table(),
279 array( 'meta_value' => wp_json_encode( $new_design ) ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
280 array( 'meta_id' => $meta->meta_id )
281 );
282
283 wp_cache_delete( $meta->module_id, 'hustle_module_meta' );
284 }
285 }
286
287 /**
288 * Migrates the old settings to the new one for Advanced -> Border, Spacing, Shadow.
289 *
290 * @since 4.3.0
291 * @param array $old_design Original settings.
292 * @return array
293 */
294 private function migrate_border_spacing_shadow( $old_design ) {
295
296 $new_design = array();
297
298 // Module Container -> Drop shadow.
299 if ( '1' === $old_design['drop_shadow'] ) {
300 $this->switch_colors_to_custom = true;
301
302 $new_design['module_cont_drop_shadow_x'] = $old_design['drop_shadow_x'];
303 $new_design['module_cont_drop_shadow_y'] = $old_design['drop_shadow_y'];
304 $new_design['module_cont_drop_shadow_blur'] = $old_design['drop_shadow_blur'];
305 $new_design['module_cont_drop_shadow_spread'] = $old_design['drop_shadow_spread'];
306 }
307
308 // Module Container -> Border.
309 if ( '1' === $old_design['border'] ) {
310 $this->switch_colors_to_custom = true;
311
312 $new_design['module_cont_radius_top_left'] = $old_design['border_radius'];
313 $new_design['module_cont_radius_top_right'] = $old_design['border_radius'];
314 $new_design['module_cont_radius_bottom_right'] = $old_design['border_radius'];
315 $new_design['module_cont_radius_bottom_left'] = $old_design['border_radius'];
316
317 $new_design['module_cont_border_top'] = $old_design['border_weight'];
318 $new_design['module_cont_border_right'] = $old_design['border_weight'];
319 $new_design['module_cont_border_bottom'] = $old_design['border_weight'];
320 $new_design['module_cont_border_left'] = $old_design['border_weight'];
321
322 $new_design['module_cont_border_type'] = $old_design['border_type'];
323 $new_design['module_cont_border_type_mobile'] = $old_design['border_type'];
324 }
325
326 // CTA.
327 if ( 'outlined' === $old_design['cta_style'] ) {
328 $new_design['cta_radius_top_left'] = $old_design['cta_border_radius'];
329 $new_design['cta_radius_top_right'] = $old_design['cta_border_radius'];
330 $new_design['cta_radius_bottom_right'] = $old_design['cta_border_radius'];
331 $new_design['cta_radius_bottom_left'] = $old_design['cta_border_radius'];
332
333 $new_design['cta_border_top'] = $old_design['cta_border_weight'];
334 $new_design['cta_border_right'] = $old_design['cta_border_weight'];
335 $new_design['cta_border_bottom'] = $old_design['cta_border_weight'];
336 $new_design['cta_border_left'] = $old_design['cta_border_weight'];
337 }
338
339 // Inputs & selects.
340 if ( 'outlined' === $old_design['form_fields_style'] ) {
341 $new_design['input_radius_top_left'] = $old_design['form_fields_border_radius'];
342 $new_design['input_radius_top_right'] = $old_design['form_fields_border_radius'];
343 $new_design['input_radius_bottom_right'] = $old_design['form_fields_border_radius'];
344 $new_design['input_radius_bottom_left'] = $old_design['form_fields_border_radius'];
345
346 $new_design['input_border_top'] = $old_design['form_fields_border_weight'];
347 $new_design['input_border_right'] = $old_design['form_fields_border_weight'];
348 $new_design['input_border_bottom'] = $old_design['form_fields_border_weight'];
349 $new_design['input_border_left'] = $old_design['form_fields_border_weight'];
350
351 $new_design['input_border_type'] = $old_design['form_fields_border_type'];
352 $new_design['input_border_type_mobile'] = $old_design['form_fields_border_type'];
353 }
354
355 // Submit button.
356 if ( 'outlined' === $old_design['button_style'] ) {
357 $new_design['submit_button_radius_top_left'] = $old_design['button_border_radius'];
358 $new_design['submit_button_radius_top_right'] = $old_design['button_border_radius'];
359 $new_design['submit_button_radius_bottom_right'] = $old_design['button_border_radius'];
360 $new_design['submit_button_radius_bottom_left'] = $old_design['button_border_radius'];
361
362 $new_design['submit_button_border_top'] = $old_design['button_border_weight'];
363 $new_design['submit_button_border_right'] = $old_design['button_border_weight'];
364 $new_design['submit_button_border_bottom'] = $old_design['button_border_weight'];
365 $new_design['submit_button_border_left'] = $old_design['button_border_weight'];
366
367 $new_design['submit_button_border_type'] = $old_design['button_border_type'];
368 $new_design['submit_button_border_type_mobile'] = $old_design['button_border_type'];
369 }
370
371 // GDPR checkbox.
372 if ( 'outlined' === $old_design['gdpr_checkbox_style'] ) {
373 $new_design['gdpr_radius_top_left'] = $old_design['gdpr_border_radius'];
374 $new_design['gdpr_radius_top_right'] = $old_design['gdpr_border_radius'];
375 $new_design['gdpr_radius_bottom_right'] = $old_design['gdpr_border_radius'];
376 $new_design['gdpr_radius_bottom_left'] = $old_design['gdpr_border_radius'];
377
378 $new_design['gdpr_border_top'] = $old_design['gdpr_border_weight'];
379 $new_design['gdpr_border_right'] = $old_design['gdpr_border_weight'];
380 $new_design['gdpr_border_bottom'] = $old_design['gdpr_border_weight'];
381 $new_design['gdpr_border_left'] = $old_design['gdpr_border_weight'];
382 }
383
384 // Maybe popups only?
385 $new_design['popup_cont_padding_are_sides_linked_mobile'] = '0';
386 $new_design['popup_cont_padding_left_mobile'] = 10;
387 $new_design['popup_cont_padding_right_mobile'] = 10;
388
389 $new_design['content_wrap_padding_top_mobile'] = 10;
390 $new_design['content_wrap_padding_right_mobile'] = 10;
391 $new_design['content_wrap_padding_bottom_mobile'] = 10;
392 $new_design['content_wrap_padding_left_mobile'] = 10;
393
394 // For informational modules.
395 if ( ! $this->is_optin ) {
396 if ( 'minimal' === $old_design['style'] ) {
397 $new_design = $this->get_informational_minimal_advanced( $new_design );
398 } elseif ( 'simple' === $old_design['style'] ) {
399 $new_design = $this->get_informational_simple_advanced( $new_design );
400 } else {
401 // Cabriolet (stacked).
402 $new_design = $this->get_informational_cabriolet_advanced( $new_design );
403 }
404 } else {
405 $new_design = $this->get_optin_advanced( $new_design );
406 }
407
408 $new_design['customize_border_shadow_spacing'] = '1';
409 $new_design['customize_border_shadow_spacing_mobile'] = '1';
410
411 return $new_design;
412 }
413
414 /**
415 * Gets the advanced settings for optin modules.
416 *
417 * @since 4.3.0
418 *
419 * @param array $new_design New design for the module.
420 * @return array
421 */
422 private function get_optin_advanced( $new_design ) {
423 $content = $this->content_metas[ $this->module_id ];
424
425 $new_design['form_cont_padding_top_mobile'] = 10;
426 $new_design['form_cont_padding_right_mobile'] = 10;
427 $new_design['form_cont_padding_bottom_mobile'] = 10;
428 $new_design['form_cont_padding_left_mobile'] = 10;
429
430 if ( empty( $content->title ) && ! empty( $content->sub_title ) ) {
431 $new_design['subtitle_margin_are_sides_linked'] = '0';
432 $new_design['subtitle_margin_top'] = 0;
433 }
434
435 if ( empty( $content->title ) && empty( $content->sub_title ) ) {
436 if ( ! empty( $content->main_content ) ) {
437 $new_design['main_content_margin_are_sides_linked'] = '0';
438 $new_design['main_content_margin_top'] = 0;
439
440 $new_design['cta_cont_margin_are_sides_linked_mobile'] = '0';
441 $new_design['cta_cont_margin_top_mobile'] = 10;
442 }
443
444 if ( empty( $content->main_content ) && '1' === $content->show_cta ) {
445 $new_design['cta_cont_margin_are_sides_linked'] = '0';
446 $new_design['cta_cont_margin_top'] = 0;
447 }
448 } else {
449 $new_design['main_content_margin_are_sides_linked_mobile'] = '0';
450 $new_design['main_content_margin_top_mobile'] = 10;
451
452 $new_design['cta_cont_margin_are_sides_linked_mobile'] = '0';
453 $new_design['cta_cont_margin_top_mobile'] = 10;
454 }
455
456 return $new_design;
457 }
458
459 /**
460 * Retrieves the advanced settings for the Informational modules with the "minimal" (Default) layout.
461 *
462 * @since 4.3.0
463 *
464 * @param array $new_design New design for the module.
465 * @return array
466 */
467 private function get_informational_minimal_advanced( $new_design ) {
468 $content = $this->content_metas[ $this->module_id ];
469
470 if ( ! empty( $content->title ) || ! empty( $content->sub_title ) ) {
471 $new_design['main_content_padding_are_sides_linked'] = '0';
472 $new_design['main_content_padding_top'] = 20;
473
474 $new_design['main_content_padding_are_sides_linked_mobile'] = '0';
475 $new_design['main_content_padding_top_mobile'] = 0;
476
477 $new_design['main_content_border_are_sides_linked'] = '0';
478 $new_design['main_content_border_top'] = 1;
479
480 $new_design['layout_header_border_are_sides_linked'] = '0';
481 if ( ! empty( $content->feature_image ) || ! empty( $content->main_content ) ) {
482 $new_design['layout_header_border_bottom'] = 1;
483
484 } elseif ( '0' === $content->show_cta && empty( $content->feature_image ) && empty( $content->main_content ) ) {
485 $new_design['layout_header_border_bottom'] = 0;
486 }
487
488 $new_design['layout_header_padding_top_mobile'] = 10;
489 $new_design['layout_header_padding_right_mobile'] = 10;
490 $new_design['layout_header_padding_bottom_mobile'] = 10;
491 $new_design['layout_header_padding_left_mobile'] = 10;
492 }
493
494 if ( empty( $content->title ) && ! empty( $content->sub_title ) ) {
495 $new_design['subtitle_margin_top'] = 0;
496 }
497
498 if ( '1' === $content->show_cta ) {
499 $new_design['layout_footer_padding_top'] = 20;
500 $new_design['layout_footer_padding_right'] = 20;
501 $new_design['layout_footer_padding_bottom'] = 20;
502 $new_design['layout_footer_padding_left'] = 20;
503
504 $new_design['layout_footer_padding_top_mobile'] = 10;
505 $new_design['layout_footer_padding_right_mobile'] = 10;
506 $new_design['layout_footer_padding_bottom_mobile'] = 10;
507 $new_design['layout_footer_padding_left_mobile'] = 10;
508
509 $new_design['cta_cont_margin_top'] = 0;
510 $new_design['cta_cont_margin_right'] = 0;
511 $new_design['cta_cont_margin_bottom'] = 0;
512 $new_design['cta_cont_margin_left'] = 0;
513 }
514
515 return $new_design;
516 }
517
518 /**
519 * Retrieves the advanced settings for the Informational modules with the "simple" (Compact) layout.
520 *
521 * @since 4.3.0
522 *
523 * @param array $new_design New design for the module.
524 * @return array
525 */
526 private function get_informational_simple_advanced( $new_design ) {
527 $content = $this->content_metas[ $this->module_id ];
528
529 $new_design['cta_cont_margin_are_sides_linked'] = '0';
530 $new_design['cta_cont_margin_top'] = 0;
531
532 // #1.
533 if (
534 ( ! empty( $content->title ) && empty( $content->sub_title ) ) &&
535 ( '1' === $content->show_cta || ! empty( $content->main_content ) )
536 ) {
537 $this->switch_colors_to_custom = true;
538
539 $new_design['title_border_are_sides_linked'] = '0';
540 $new_design['title_border_bottom'] = 1;
541
542 $new_design['title_padding_are_sides_linked'] = '0';
543 $new_design['title_padding_bottom'] = 20;
544
545 $new_design['title_padding_are_sides_linked_mobile'] = '0';
546 $new_design['title_padding_bottom_mobile'] = 10;
547 }
548
549 // #2.
550 if (
551 ! empty( $content->sub_title ) &&
552 ( '1' === $content->show_cta || ! empty( $content->main_content ) )
553 ) {
554 $this->switch_colors_to_custom = true;
555
556 $new_design['subtitle_border_are_sides_linked'] = '0';
557 $new_design['subtitle_border_bottom'] = 1;
558
559 $new_design['subtitle_padding_are_sides_linked'] = '0';
560 $new_design['subtitle_padding_bottom'] = 20;
561 }
562
563 // #3.
564 if ( empty( $content->title ) && ! empty( $content->sub_title ) ) {
565 $new_design['subtitle_margin_are_sides_linked'] = '0';
566 $new_design['subtitle_margin_top'] = 0;
567 }
568
569 // #4.
570 if ( ! empty( $content->title ) || ! empty( $content->sub_title ) ) {
571 $this->switch_colors_to_custom = true;
572
573 $new_design['main_content_border_are_sides_linked'] = '0';
574 $new_design['main_content_border_top'] = 1;
575
576 $new_design['main_content_padding_are_sides_linked'] = '0';
577 $new_design['main_content_padding_top'] = 20;
578 }
579
580 // #5.
581 if ( '1' === $content->show_cta ) {
582 $this->switch_colors_to_custom = true;
583
584 $new_design['main_content_border_are_sides_linked'] = '0';
585 $new_design['main_content_border_bottom'] = 1;
586
587 $new_design['main_content_padding_are_sides_linked'] = '0';
588 $new_design['main_content_padding_bottom'] = 20;
589 }
590
591 // #7.
592 if ( ! empty( $content->title ) || ! empty( $content->sub_title ) || ! empty( $content->main_content ) ) {
593 $this->switch_colors_to_custom = true;
594
595 $new_design['cta_cont_border_are_sides_linked'] = '0';
596 $new_design['cta_cont_border_top'] = 1;
597
598 // #8.
599 $new_design['cta_cont_padding_are_sides_linked'] = '0';
600 $new_design['cta_cont_padding_top'] = 20;
601
602 $new_design['cta_cont_padding_are_sides_linked_mobile'] = '0';
603 $new_design['cta_cont_padding_top_mobile'] = 10;
604 }
605
606 return $new_design;
607 }
608
609 /**
610 * Retrieves the advanced settings for the Informational modules with the "cabriolet" (Stacked) layout.
611 *
612 * @since 4.3.0
613 *
614 * @param array $new_design New design for the module.
615 * @return array
616 */
617 private function get_informational_cabriolet_advanced( $new_design ) {
618 $content = $this->content_metas[ $this->module_id ];
619
620 $new_design['layout_header_padding_are_sides_linked'] = '0';
621 $new_design['layout_header_padding_left'] = 0;
622 $new_design['layout_header_padding_top'] = 0;
623
624 $new_design['layout_header_border_are_sides_linked'] = '0';
625 $new_design['layout_header_border_bottom'] = 0;
626
627 $new_design['title_padding_are_sides_linked'] = '0';
628 $new_design['title_padding_right'] = 30;
629
630 $new_design['subtitle_padding_are_sides_linked'] = '0';
631 $new_design['subtitle_padding_right'] = 30;
632
633 if ( ! empty( $content->title ) || ! empty( $content->sub_title ) ) {
634 if ( empty( $content->main_content ) && empty( $content->feature_image ) && '0' === $content->show_cta ) {
635 $new_design['layout_header_padding_bottom'] = 0;
636 } else {
637 $new_design['layout_header_padding_are_sides_linked_mobile'] = '0';
638 $new_design['layout_header_padding_bottom_mobile'] = 10;
639 }
640 }
641
642 if ( '1' === $content->show_cta ) {
643 $new_design['cta_cont_margin_are_sides_linked'] = '0';
644 $new_design['cta_cont_margin_top'] = 0;
645
646 if ( ! empty( $content->main_content ) ) {
647 $this->switch_colors_to_custom = true;
648
649 $new_design['main_content_padding_are_sides_linked'] = '0';
650 $new_design['main_content_padding_bottom'] = 20;
651 $new_design['main_content_border_bottom'] = 1;
652
653 $new_design['main_content_padding_are_sides_linked_mobile'] = '0';
654 $new_design['main_content_padding_bottom_mobile'] = 10;
655
656 $new_design['cta_cont_padding_are_sides_linked'] = '0';
657 $new_design['cta_cont_padding_top'] = 20;
658
659 $new_design['cta_cont_border_are_sides_linked'] = '0';
660 $new_design['cta_cont_border_top'] = 1;
661
662 $new_design['cta_cont_padding_are_sides_linked_mobile'] = '0';
663 $new_design['cta_cont_padding_top_mobile'] = 10;
664 }
665 }
666
667 return $new_design;
668 }
669
670 /**
671 * Migrates colors.
672 *
673 * @since 4.3.0
674 * @param array $old_design Original settings.
675 * @return array
676 */
677 private function migrate_colors( $old_design ) {
678 $new_design = array();
679
680 // For informational modules.
681 if ( ! $this->is_optin ) {
682 if ( 'simple' === $old_design['style'] ) {
683 $new_design = $this->get_informational_simple_colors( $new_design );
684 } elseif ( 'cabriolet' === $old_design['style'] ) {
685 $new_design = $this->get_informational_cabriolet_colors( $new_design );
686 }
687 }
688
689 if ( '0' === $old_design['customize_colors'] && $this->switch_colors_to_custom ) {
690 $new_design = array_merge(
691 Hustle_Palettes_Helper::get_palette_array( $old_design['color_palette'], $this->is_optin ),
692 $new_design
693 );
694
695 $new_design['customize_colors'] = '1';
696 }
697
698 $new_design['module_cont_border'] = $old_design['border_color'];
699 $new_design['module_cont_drop_shadow'] = $old_design['drop_shadow_color'];
700
701 return $new_design;
702 }
703
704 /**
705 * Retrieves the colors for the Informational modules with the "simple" (Compact) layout.
706 *
707 * @since 4.3.0
708 *
709 * @param array $new_design New design for the module.
710 * @return array
711 */
712 private function get_informational_simple_colors( $new_design ) {
713 $content = $this->content_metas[ $this->module_id ];
714
715 // #1.
716 if (
717 ( ! empty( $content->title ) && empty( $content->sub_title ) ) &&
718 ( '1' === $content->show_cta || ! empty( $content->main_content ) )
719 ) {
720 $new_design['title_border'] = 'rgba(0,0,0,0.16)';
721 }
722
723 // #2.
724 if (
725 ! empty( $content->sub_title ) &&
726 ( '1' === $content->show_cta || ! empty( $content->main_content ) )
727 ) {
728 $new_design['subtitle_border'] = 'rgba(0,0,0,0.16)';
729 }
730
731 // #4.
732 if ( ! empty( $content->title ) && ! empty( $content->sub_title ) ) {
733 $new_design['content_border'] = 'rgba(255,255,255,0.08)';
734 }
735
736 // #5.
737 if ( '1' === $content->show_cta ) {
738 $new_design['content_border'] = 'rgba(255,255,255,0.08)';
739 }
740
741 // #6.
742 if ( empty( $content->title ) && empty( $content->sub_title ) && '1' === $content->show_cta ) {
743 $new_design['content_border'] = 'rgba(0,0,0,0.16)';
744 }
745
746 // #7.
747 if ( ! empty( $content->title ) || ! empty( $content->sub_title ) ) {
748 if ( ! empty( $content->main_content ) ) {
749 $new_design['cta_cont_border'] = 'rgba(0,0,0,0.16)';
750 } else {
751 $new_design['cta_cont_border'] = 'rgba(255,255,255,0.08)';
752 }
753 }
754
755 return $new_design;
756 }
757
758 /**
759 * Retrieves the colors for the Informational modules with the "cabriolet" (Stacked) layout.
760 *
761 * @since 4.3.0
762 *
763 * @param array $new_design New design for the module.
764 * @return array
765 */
766 private function get_informational_cabriolet_colors( $new_design ) {
767 $content = $this->content_metas[ $this->module_id ];
768
769 if ( ! empty( $content->main_content ) && '1' === $content->show_cta ) {
770 $new_design['content_border'] = 'rgba(0,0,0,0.16)';
771 $new_design['cta_cont_border'] = 'rgba(255,255,255,0.08)';
772 }
773
774 return $new_design;
775 }
776
777 /**
778 * Migrates Customize Elements.
779 *
780 * @since 4.3.0
781 * @param array $old_design Original settings.
782 * @return array
783 */
784 private function migrate_customize_elements( $old_design ) {
785 $new_design = array();
786
787 $new_design['feature_image_fit_mobile'] = $old_design['feature_image_fit'];
788
789 $new_design['feature_image_horizontal_position'] = $old_design['feature_image_horizontal'];
790 $new_design['feature_image_horizontal_position_mobile'] = $old_design['feature_image_horizontal'];
791
792 $new_design['feature_image_vertical_position'] = $old_design['feature_image_vertical'];
793 $new_design['feature_image_vertical_position_mobile'] = $old_design['feature_image_vertical'];
794
795 $new_design['feature_image_horizontal_value'] = $old_design['feature_image_horizontal_px'];
796 $new_design['feature_image_horizontal_value_mobile'] = $old_design['feature_image_horizontal_px'];
797
798 $new_design['feature_image_vertical_value'] = $old_design['feature_image_vertical_px'];
799 $new_design['feature_image_vertical_value_mobile'] = $old_design['feature_image_vertical_px'];
800
801 if ( 'joined' === $old_design['form_fields_proximity'] ) {
802 $new_design['customize_form_fields_proximity'] = '0';
803 $new_design['customize_form_fields_proximity_mobile'] = '0';
804 } else {
805 $new_design['customize_form_fields_proximity'] = '1';
806 $new_design['customize_form_fields_proximity_mobile'] = '1';
807
808 $new_design['form_fields_proximity_value'] = 10;
809 $new_design['form_fields_proximity_value_mobile'] = 10;
810 }
811
812 // For informational modules.
813 if ( ! $this->is_optin ) {
814 if ( 'minimal' === $old_design['style'] ) {
815 $new_design = $this->get_informational_minimal_customize( $new_design );
816 }
817 } else {
818 $new_design['cta_buttons_alignment_mobile'] = 'left';
819
820 if ( 'one' === $old_design['form_layout'] || 'two' === $old_design['form_layout'] ) {
821 $new_design['optin_form_layout'] = 'inline';
822 } else {
823 $new_design['optin_form_layout'] = 'stacked';
824 }
825 }
826
827 return $new_design;
828 }
829
830 /**
831 * Retrieves the customize elements for the Informational modules with the "minimal" (Default) layout.
832 *
833 * @since 4.3.0
834 *
835 * @param array $new_design New design for the module.
836 * @return array
837 */
838 private function get_informational_minimal_customize( $new_design ) {
839 $content = $this->content_metas[ $this->module_id ];
840
841 if ( '1' === $content->show_cta ) {
842 $new_design['cta_buttons_alignment'] = 'right';
843 $new_design['cta_buttons_alignment_mobile'] = 'left';
844 }
845
846 if (
847 ! empty( $content->feature_image ) &&
848 empty( $content->title ) && empty( $content->sub_title ) &&
849 empty( $content->main_content ) && '0' === $content->show_cta
850 ) {
851 $new_design['feature_image_height'] = 320;
852 }
853
854 return $new_design;
855 }
856
857 /**
858 * Migrates Typography.
859 *
860 * @since 4.3.0
861 * @param array $old_design Original settings.
862 * @return array
863 */
864 private function migrate_typography( $old_design ) {
865 $new_design = array();
866
867 if ( ! $this->is_optin ) {
868 $new_design['title_font_family'] = 'custom';
869 $new_design['title_font_family_custom'] = 'Georgia';
870 $new_design['title_font_size'] = 33;
871 $new_design['title_font_weight'] = 400;
872 $new_design['title_line_height'] = 38;
873 $new_design['subtitle_font_weight'] = 'bold';
874 $new_design['subtitle_line_height'] = 24;
875
876 }
877
878 return $new_design;
879 }
880 }
881