PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.6
Strong Testimonials v3.3.6
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / class-strong-testimonials-updater.php
strong-testimonials / admin Last commit date
challenge 1 year ago css 1 month ago img 1 year ago js 2 months ago menu 2 months ago partials 1 month ago rest-api 1 week ago scss 1 year ago settings 1 week ago uninstall 1 year ago wpchill 2 months ago admin-notices.php 7 months ago admin.php 2 months ago class-strong-testimonials-addons.php 2 months ago class-strong-testimonials-admin-category-list.php 1 year ago class-strong-testimonials-admin-list.php 1 year ago class-strong-testimonials-admin-scripts.php 1 week ago class-strong-testimonials-admin.php 2 months ago class-strong-testimonials-debug.php 6 months ago class-strong-testimonials-exporter.php 1 year ago class-strong-testimonials-help.php 1 year ago class-strong-testimonials-helper.php 1 week ago class-strong-testimonials-list-table.php 1 year ago class-strong-testimonials-lite-vs-pro-page.php 2 months ago class-strong-testimonials-post-editor.php 8 months ago class-strong-testimonials-review.php 1 year ago class-strong-testimonials-updater.php 2 months ago class-strong-testimonials-upsell.php 1 month ago class-strong-views-list-table.php 2 months ago class-walker-strong-category-checklist.php 1 year ago class-walker-strong-form-category-checklist.php 1 year ago class-wpmtst-onboarding.php 1 year ago compat.php 1 year ago custom-fields-ajax.php 1 year ago custom-fields.php 1 month ago form-preview.php 1 year ago view-list-order.php 1 year ago views-ajax.php 2 months ago views-validate.php 1 year ago views.php 3 weeks ago
class-strong-testimonials-updater.php
1348 lines
1 <?php
2
3 /**
4 * Class Strong_Testimonials_Updater
5 *
6 * @since 2.28.0
7 */
8 class Strong_Testimonials_Updater {
9
10 /**
11 * The version before updating.
12 *
13 * @var string
14 */
15 private static $old_version = '3.0.0';
16
17 /**
18 * Log steps during update process.
19 *
20 * @var array
21 */
22 private static $new_log;
23
24 /**
25 * Strong_Testimonials_Updater constructor.
26 */
27 public function __construct() {
28 }
29
30 /**
31 * Add a log entry.
32 *
33 * @param $name
34 * @param string $entry
35 * @param string $variable
36 */
37 private static function log( $name, $entry = '', $variable = '' ) {
38 if ( $name ) {
39 $x = $name;
40 if ( $entry ) {
41 $x .= ' : ' . $entry;
42 if ( $variable ) {
43 $x .= ' = ';
44 if ( is_array( $variable ) || is_object( $variable ) ) {
45 // log the text
46 self::$new_log[] = $x;
47 // then log the variable
48 self::$new_log[] = $variable;
49 } else {
50 self::$new_log[] = $x . $variable;
51 }
52 } else {
53 self::$new_log[] = $x;
54 }
55 } else {
56 self::$new_log[] = $x;
57 }
58 }
59 }
60
61 /**
62 * Plugin activation and update.
63 *
64 * ---------
65 * REMEMBER!
66 * ---------
67 * If you are changing the value of a default field property,
68 * then you need to unset that value in the current field
69 * before merging in the new default values.
70 *
71 * For example, when changing a rating field property from
72 * disabled (0) to enabled (1) in order for the property to
73 * be displayed in the form editor.
74 */
75 public static function update() {
76 if ( get_transient( 'wpmtst_update_in_progress' ) ) {
77 return;
78 }
79
80 set_transient( 'wpmtst_update_in_progress', 1, 10 );
81
82 /**
83 * Add custom capablities.
84 *
85 * @since 2.27.1
86 */
87 self::add_caps();
88
89 /**
90 * Check DB version.
91 */
92 self::update_db_check();
93
94 /**
95 * Let's start updating.
96 */
97 $history = get_option( 'wpmtst_history', array() );
98
99 /**
100 * Options.
101 */
102 update_option( 'wpmtst_options', self::update_options() );
103
104 /**
105 * Custom fields.
106 */
107 update_option( 'wpmtst_fields', self::update_fields(), 'no' );
108
109 /**
110 * Forms.
111 */
112 update_option( 'wpmtst_base_forms', self::update_base_forms(), 'no' );
113 update_option( 'wpmtst_custom_forms', self::update_custom_forms() );
114 update_option( 'wpmtst_form_options', self::update_form_options() );
115
116 /**
117 * Compatibility options.
118 *
119 * @since 2.28.0
120 */
121 update_option( 'wpmtst_compat_options', self::update_compat_options() );
122
123 /**
124 * Overwrite default view settings.
125 *
126 * @since 2.15.0
127 */
128 update_option( 'wpmtst_view_default', self::update_default_view(), 'no' );
129
130 /**
131 * Update views.
132 */
133 self::update_views();
134
135 /**
136 * Convert nofollow
137 */
138 if ( ! isset( $history['2.23.0_convert_nofollow'] ) ) {
139 self::convert_nofollow();
140 self::update_history_log( '2.23.0_convert_nofollow' );
141 self::convert_noopener();
142 self::convert_noreferrer();
143 }
144
145 /**
146 * Legacy stuff.
147 */
148 if ( ! isset( $history['2.28_new_update_process'] ) ) {
149 // Upgrade from version 1.x
150 delete_option( 'wpmtst_cycle' );
151
152 // L10n context no longer used.
153 delete_option( 'wpmtst_l10n_contexts' );
154
155 // Remove older attempts at admin notices.
156 delete_option( 'wpmtst_news_flag' );
157
158 self::update_history_log( '2.28_new_update_process' );
159 }
160
161 /**
162 * Fix add-ons.
163 */
164 self::update_addons();
165
166 /**
167 * Update the plugin version.
168 */
169 update_option( 'wpmtst_plugin_version', WPMTST_VERSION );
170
171 /**
172 * Update log.
173 */
174 self::update_log();
175
176 /**
177 * Update admin notices.
178 */
179 self::update_admin_notices();
180
181 /**
182 * Ensure default views exist after every update.
183 */
184 wpmtst_create_default_views();
185
186 delete_transient( 'wpmtst_update_in_progress' );
187 }
188
189 public static function update_admin_notices() {
190 wpmtst_add_admin_notice( 'feedback-notice', true );
191 wpmtst_add_admin_notice( 'upsell-notice', true );
192 }
193
194 /**
195 * Fix add-on file names.
196 *
197 * @since 2.30.9
198 */
199 public static function update_addons() {
200 $addons = get_option( 'wpmtst_addons' );
201 if ( $addons ) {
202 foreach ( $addons as $addon => $data ) {
203 if ( isset( $addons[ $addon ]['file'] ) ) {
204 $addons[ $addon ]['file'] = plugin_basename( basename( $data['file'], '.php' ) . '/' . basename( $data['file'] ) );
205 }
206 }
207 update_option( 'wpmtst_addons', $addons );
208 }
209 }
210
211 /**
212 * Update the log in options table.
213 */
214 public static function update_log() {
215 $log = get_option( 'wpmtst_update_log', array() );
216 $log[ current_time( 'mysql' ) ] = self::$new_log;
217 update_option( 'wpmtst_update_log', $log );
218 }
219
220 /**
221 * Return admin role.
222 *
223 * @since 2.27.0
224 *
225 * @return bool|null|WP_Role
226 */
227 public static function get_admins() {
228 return get_role( 'administrator' );
229 }
230
231 /**
232 * Add custom capabilities.
233 *
234 * @since 2.27.1
235 */
236 public static function add_caps() {
237 $admins = self::get_admins();
238 if ( $admins ) {
239 $admins->add_cap( 'strong_testimonials_views' );
240 $admins->add_cap( 'strong_testimonials_fields' );
241 $admins->add_cap( 'strong_testimonials_options' );
242 $admins->add_cap( 'strong_testimonials_about' );
243 } else {
244 self::log( __FUNCTION__, 'failed' );
245 }
246 }
247
248 /**
249 * Remove custom capabilities.
250 *
251 * Was part of uninstall process but cannot be run from static class.
252 *
253 * @todo Move to Leave No Trace.
254 *
255 * @since 2.27.1
256 */
257 public static function remove_caps() {
258 $admins = self::get_admins();
259 if ( $admins ) {
260 $admins->remove_cap( 'strong_testimonials_views' );
261 $admins->remove_cap( 'strong_testimonials_fields' );
262 $admins->remove_cap( 'strong_testimonials_options' );
263 $admins->remove_cap( 'strong_testimonials_about' );
264 }
265 }
266
267 /**
268 * Update tables.
269 *
270 * @since 1.21.0 Checking for new table version.
271 */
272 public static function update_db_check() {
273 if ( get_option( 'wpmtst_db_version' ) !== WPMST()->get_db_version() ) {
274 wpmtst_update_tables();
275 self::log( __FUNCTION__, 'tables updated' );
276 }
277 }
278
279 /**
280 * Update history log.
281 *
282 * @param $event
283 */
284 public static function update_history_log( $event ) {
285 $history = get_option( 'wpmtst_history', array() );
286 $history[ $event ] = current_time( 'mysql' );
287 update_option( 'wpmtst_history', $history );
288 }
289
290 /**
291 * Update options.
292 *
293 * @return array
294 */
295 public static function update_options() {
296 $options = get_option( 'wpmtst_options' );
297 if ( ! $options ) {
298 return Strong_Testimonials_Defaults::get_options();
299 }
300
301 /**
302 * Remove version 1 options
303 */
304 if ( version_compare( '2.0', self::$old_version ) ) {
305
306 if ( isset( $options['captcha'] ) ) {
307 unset( $options['captcha'] );
308 }
309
310 if ( isset( $options['plugin_version'] ) ) {
311 unset( $options['plugin_version'] );
312 }
313
314 if ( isset( $options['per_page'] ) ) {
315 unset( $options['per_page'] );
316 }
317
318 if ( isset( $options['load_page_style'] ) ) {
319 unset( $options['load_page_style'] );
320 }
321
322 if ( isset( $options['load_widget_style'] ) ) {
323 unset( $options['load_widget_style'] );
324 }
325
326 if ( isset( $options['load_form_style'] ) ) {
327 unset( $options['load_form_style'] );
328 }
329
330 if ( isset( $options['load_rtl_style'] ) ) {
331 unset( $options['load_rtl_style'] );
332 }
333
334 if ( isset( $options['shortcode'] ) ) {
335 unset( $options['shortcode'] );
336 }
337
338 if ( isset( $options['default_template'] ) ) {
339 unset( $options['default_template'] );
340 }
341
342 if ( isset( $options['client_section'] ) ) {
343 unset( $options['client_section'] );
344 }
345 }
346
347 /**
348 * Remove slideshow z-index (Cycle)
349 *
350 * @since 2.15.0
351 */
352 if ( isset( $options['slideshow_zindex'] ) ) {
353 unset( $options['slideshow_zindex'] );
354 }
355
356 /**
357 * Replace zero embed_width with empty value.
358 *
359 * @since 2.27.0
360 */
361 if ( 0 === $options['embed_width'] ) {
362 $options['embed_width'] = '';
363 }
364
365 /**
366 * Remove email logging.
367 *
368 * @since 2.28.4
369 */
370 if ( isset( $options['email_log_level'] ) ) {
371 unset( $options['email_log_level'] );
372 }
373
374 // Merge in new options
375 $options = array_merge( Strong_Testimonials_Defaults::get_options(), $options );
376
377 return $options;
378 }
379
380 /**
381 * Default custom fields.
382 *
383 * @since 2.31.0 There is a rare bug/conflict where the default fields are incomplete.
384 * Overwrite existing fields on every update to auto-repair.
385 *
386 * @return array
387 */
388 public static function update_fields() {
389 return Strong_Testimonials_Defaults::get_fields();
390 }
391
392 /**
393 * Base forms.
394 *
395 * @return array
396 */
397 public static function update_base_forms() {
398 return Strong_Testimonials_Defaults::get_base_forms();
399 }
400
401 /**
402 * Custom forms.
403 *
404 * @return array
405 */
406 public static function update_custom_forms() {
407 $custom_forms = get_option( 'wpmtst_custom_forms' );
408 if ( ! $custom_forms ) {
409 return Strong_Testimonials_Defaults::get_custom_forms();
410 }
411
412 foreach ( $custom_forms as $form_id => $form_properties ) {
413 foreach ( $form_properties['fields'] as $key => $form_field ) {
414
415 /*
416 * Convert categories to category-selector.
417 * @since 2.17.0
418 */
419 if ( 'categories' === $form_field['input_type'] ) {
420 $custom_forms[ $form_id ]['fields'][ $key ]['input_type'] = 'category-selector';
421 }
422
423 /*
424 * Unset `show_default_options` for rating field. Going from 0 to 1.
425 * @since 2.21.0
426 */
427 if ( 'rating' === $form_field['input_type'] ) {
428 unset( $form_field['show_default_options'] );
429 }
430
431 /*
432 * Add `show_required_option` to shortcode field. Initial value is false.
433 * @since 2.22.0
434 */
435 if ( 'shortcode' === $form_field['input_type'] ) {
436 $form_field['show_required_option'] = false;
437 }
438
439 /*
440 * Add `show_default_options` to checkbox field.
441 *
442 * @since 2.27.0
443 */
444 if ( 'checkbox' === $form_field['input_type'] ) {
445 $form_field['show_default_options'] = 1;
446 }
447
448 /*
449 * Merge in new default.
450 * Custom fields are in display order (not associative) so we must find them by `input_type`.
451 * @since 2.21.0 Using default fields instead of default form as source
452 */
453 $new_default = array();
454 $fields = get_option( 'wpmtst_fields', array() );
455
456 foreach ( $fields['field_types'] as $field_type_group_key => $field_type_group ) {
457 foreach ( $field_type_group as $field_type_key => $field_type_field ) {
458 if ( $field_type_field['input_type'] === $form_field['input_type'] ) {
459 $new_default = $field_type_field;
460 break;
461 }
462 }
463 }
464
465 if ( $new_default ) {
466 $custom_forms[ $form_id ]['fields'][ $key ] = array_merge( $new_default, $form_field );
467 }
468 }
469 }
470
471 return $custom_forms;
472 }
473
474 /**
475 * Form options.
476 *
477 * @return array
478 */
479 public static function update_form_options() {
480 $form_options = get_option( 'wpmtst_form_options' );
481 if ( ! $form_options ) {
482 return Strong_Testimonials_Defaults::get_form_options();
483 }
484
485 $options = get_option( 'wpmtst_options', array() );
486 $history = get_option( 'wpmtst_history', array() );
487
488 /**
489 * Move existing options.
490 */
491 if ( isset( $options['admin_notify'] ) ) {
492 $form_options['admin_notify'] = $options['admin_notify'];
493 unset( $options['admin_notify'] );
494
495 $form_options['admin_email'] = $options['admin_email'];
496 unset( $options['admin_email'] );
497
498 update_option( 'wpmtst_options', $options );
499 }
500
501 /**
502 * Update single email recipient to multiple.
503 *
504 * @since 1.18
505 */
506 if ( ! isset( $form_options['recipients'] ) ) {
507 $form_options['recipients'] = array(
508 array(
509 'admin_name' => isset( $form_options['admin_name'] ) ? $form_options['admin_name'] : '',
510 'admin_site_email' => isset( $form_options['admin_site_email'] ) ? $form_options['admin_site_email'] : 1,
511 'admin_email' => isset( $form_options['admin_email'] ) ? $form_options['admin_email'] : '',
512 'primary' => 1, // cannot be deleted
513 ),
514 );
515
516 unset( $form_options['admin_name'] );
517 unset( $form_options['admin_site_email'] );
518 unset( $form_options['admin_email'] );
519 }
520
521 /**
522 * Add default required-notice setting
523 *
524 * @since 2.24.1
525 */
526 if ( ! isset( $form_options['messages']['required-field']['enabled'] ) ) {
527 $form_options['messages']['required-field']['enabled'] = 1;
528 }
529
530 /**
531 * Delete form options
532 *
533 * @since 2.38
534 */
535 unset( $form_options['captcha'] );
536 unset( $form_options['messages']['captcha'] );
537
538 /**
539 * Merge in new options.
540 */
541 $defaults = Strong_Testimonials_Defaults::get_form_options();
542
543 $form_options = array_merge( $defaults, $form_options );
544
545 // Merge nested arrays individually. Don't use array_merge_recursive.
546
547 $form_options['default_recipient'] = array_merge( $defaults['default_recipient'], $form_options['default_recipient'] );
548 foreach ( $defaults['messages'] as $key => $message ) {
549 if ( isset( $form_options['messages'][ $key ] ) ) {
550 $form_options['messages'][ $key ] = array_merge( $message, $form_options['messages'][ $key ] );
551 }
552 }
553
554 return $form_options;
555 }
556
557 /**
558 * Compatibility options.
559 *
560 * @since 2.28.0
561 *
562 * @return array
563 */
564 public static function update_compat_options() {
565 $options = get_option( 'wpmtst_compat_options' );
566 if ( ! $options ) {
567 return Strong_Testimonials_Defaults::get_compat_options();
568 }
569
570 // Merge in new options.
571 $defaults = Strong_Testimonials_Defaults::get_compat_options();
572
573 // Merge nested arrays individually. Don't use array_merge_recursive.
574
575 if ( isset( $options['controller'] ) ) {
576 $options['ajax'] = array_merge( $defaults['ajax'], $options['ajax'] );
577 } else {
578 $options['ajax'] = $defaults['ajax'];
579 }
580
581 /**
582 * Controller
583 *
584 * @since 2.31.0
585 */
586 if ( isset( $options['controller'] ) ) {
587 $options['controller'] = array_merge( $defaults['controller'], $options['controller'] );
588 } else {
589 $options['controller'] = $defaults['controller'];
590 }
591
592 /**
593 * Lazy load
594 *
595 * @since 2.31.0
596 */
597 if ( isset( $options['lazyload'] ) ) {
598 // first level only: enabled, classes (array)
599 $options['lazyload'] = array_merge( $defaults['lazyload'], $options['lazyload'] );
600 } else {
601 $options['lazyload'] = $defaults['lazyload'];
602 }
603
604 $options = array_merge( $defaults, $options );
605
606 return $options;
607 }
608
609 /**
610 * Default view.
611 *
612 * @return array
613 */
614 public static function update_default_view() {
615 return apply_filters( 'wpmtst_view_default', Strong_Testimonials_Defaults::get_default_view() );
616 }
617
618 /**
619 * Update views.
620 *
621 * @uses wpmtst_save_view
622 */
623 public static function update_views() {
624 $views = wpmtst_get_views();
625
626 if ( ! $views ) {
627 return;
628 }
629
630 $default_view = wpmtst_get_view_default();
631 $history = get_option( 'wpmtst_history', array() );
632
633 foreach ( $views as $key => $view ) {
634
635 $view_data = unserialize( $view['value'] );
636 if ( ! is_array( $view_data ) ) {
637 self::log( __FUNCTION__, 'view ' . $view['id'] . ' data is not an array' );
638 continue;
639 }
640
641 /**
642 * For version 2.28.
643 */
644 if ( ! isset( $history['2.28_new_update_process'] ) ) {
645 /**
646 * Compat mode no longer needed.
647 *
648 * @since 2.22.0
649 */
650 unset( $view_data['compat'] );
651
652 $view_data = self::convert_template_name( $view_data );
653 $view_data = self::convert_background_color( $view_data );
654 $view_data = self::convert_form_ajax( $view_data );
655 $view_data = self::convert_layout( $view_data );
656 $view_data = self::convert_word_count( $view_data );
657 $view_data = self::convert_excerpt_length( $view_data );
658 $view_data = self::convert_more_text( $view_data );
659 $view_data = self::convert_modern_title( $view_data );
660 $view_data = self::convert_slideshow( $view_data );
661 $view_data = self::convert_title_link( $view_data );
662 $view_data = self::convert_pagination_type( $view_data );
663 }
664
665 /**
666 * For version 2.30.
667 */
668 if ( ! isset( $history['2.30_new_template_structure'] ) ) {
669 $view_data = self::convert_template_structure( $view_data );
670 $view_data = self::convert_count( $view_data );
671 if ( isset( $view_data['background']['example-font-color'] ) ) {
672 unset( $view_data['background']['example-font-color'] );
673 }
674
675 self::update_history_log( '2.30_new_template_structure' );
676 }
677
678 /**
679 * Add carousel breakpoints.
680 *
681 * @since 2.32.2
682 */
683 if ( ! isset( $history['2.32.2_carousel_breakpoints'] ) ) {
684 $view['data'] = self::add_carousel_breakpoints( $view_data );
685 self::update_history_log( '2.32.2_carousel_breakpoints' );
686 }
687
688 /**
689 * Merge in new default values.
690 * Merge nested arrays individually. Don't use array_merge_recursive.
691 */
692 $view['data'] = array_merge( $default_view, $view_data );
693
694 /**
695 * Background defaults.
696 */
697 $view['data']['background'] = array_merge( $default_view['background'], $view_data['background'] );
698
699 /**
700 * Pagination defaults.
701 * Attempt to repair bug from 2.28.2
702 *
703 * @since 2.28.3
704 */
705 if ( isset( $view_data['pagination_settings'] ) ) {
706 $view['data']['pagination_settings'] = array_merge( $default_view['pagination_settings'], $view_data['pagination_settings'] );
707
708 if ( ! isset( $view['data']['pagination_settings']['end_size'] ) || ! $view['data']['pagination_settings']['end_size'] ) {
709 $view['data']['pagination_settings']['end_size'] = 1;
710 }
711 if ( ! isset( $view['data']['pagination_settings']['mid_size'] ) || ! $view['data']['pagination_settings']['mid_size'] ) {
712 $view['data']['pagination_settings']['mid_size'] = 2;
713 }
714 if ( ! isset( $view['data']['pagination_settings']['per_page'] ) || ! $view['data']['pagination_settings']['per_page'] ) {
715 $view['data']['pagination_settings']['per_page'] = 5;
716 }
717 } else {
718 $view['data']['pagination_settings'] = $default_view['pagination_settings'];
719 }
720
721 /**
722 * Slideshow defaults.
723 */
724 if ( isset( $view_data['slideshow_settings'] ) ) {
725 $view['data']['slideshow_settings'] = array_merge( $default_view['slideshow_settings'], $view_data['slideshow_settings'] );
726 } else {
727 $view['data']['slideshow_settings'] = $default_view['slideshow_settings'];
728 }
729 ksort( $view['data']['slideshow_settings'] );
730
731 /**
732 * Save it.
733 */
734 wpmtst_save_view( $view );
735
736 } // foreach $view
737 }
738
739 /**
740 * Add carousel breakpoints.
741 *
742 * @param array $view_data
743 * @since 2.32.2
744 *
745 * @return array
746 */
747 public static function add_carousel_breakpoints( $view_data ) {
748 if ( ! isset( $view_data['slideshow_settings']['max_slides'] ) ) {
749 return $view_data;
750 }
751
752 if ( 1 === absint( $view_data['slideshow_settings']['max_slides'] ) ) {
753
754 // Convert to single
755 $view_data['slideshow_settings']['type'] = 'show_single';
756
757 $view_data['slideshow_settings']['show_single'] = array(
758 'max_slides' => $view_data['slideshow_settings']['max_slides'],
759 'move_slides' => $view_data['slideshow_settings']['move_slides'],
760 'margin' => 1,
761 );
762
763 } else {
764
765 // Convert to multiple
766 $view_data['slideshow_settings']['type'] = 'show_multiple';
767
768 $view_data['slideshow_settings']['breakpoints']['desktop'] = array(
769 'max_slides' => $view_data['slideshow_settings']['max_slides'],
770 'move_slides' => $view_data['slideshow_settings']['move_slides'],
771 'margin' => 1,
772 );
773
774 }
775
776 // Remove old values
777 unset(
778 $view_data['slideshow_settings']['max_slides'],
779 $view_data['slideshow_settings']['move_slides'],
780 $view_data['slideshow_settings']['margin']
781 );
782
783 return $view_data;
784 }
785
786 /**
787 * Convert template naming structure.
788 *
789 * @since 2.30.0
790 *
791 * @param $view_data
792 *
793 * @return array
794 */
795 public static function convert_template_structure( $view_data ) {
796 /*
797 Array
798 (
799 [0] => default:content
800 [1] => default-dark:form
801 [2] => default-dark:content
802 [3] => default:form
803 [4] => image-right:content
804 [5] => no-quotes:content
805 [6] => large:widget
806 [7] => modern:content
807 [8] => simple:content
808 [9] => simple:form
809 [10] => unstyled:content
810 [11] => unstyled:form
811 [12] => default:widget
812 [13] => image-right:widget
813 )
814 */
815 switch ( $view_data['template'] ) {
816 case 'default:content':
817 $view_data['template'] = 'default';
818 break;
819 case 'default-dark:form':
820 $view_data['template'] = 'default-form';
821 $view_data['template_settings'][ $view_data['template'] ] = array( 'theme' => 'dark' );
822 break;
823 case 'default-dark:content':
824 $view_data['template'] = 'default';
825 $view_data['template_settings'][ $view_data['template'] ] = array( 'theme' => 'dark' );
826 break;
827 case 'default:form':
828 $view_data['template'] = 'default-form';
829 break;
830 case 'image-right:content':
831 $view_data['template'] = 'default';
832 $view_data['template_settings'][ $view_data['template'] ] = array( 'image_position' => 'right' );
833 break;
834 case 'no-quotes:content':
835 $view_data['template'] = 'default';
836 $view_data['template_settings'][ $view_data['template'] ] = array( 'quotes' => 'off' );
837 break;
838 case 'large:widget':
839 $view_data['template'] = 'bold';
840 break;
841 case 'modern:content':
842 $view_data['template'] = 'modern';
843 break;
844 case 'simple:content':
845 $view_data['template'] = 'simple';
846 break;
847 case 'simple:form':
848 $view_data['template'] = 'simple-form';
849 break;
850 case 'unstyled:content':
851 $view_data['template'] = 'unstyled';
852 break;
853 case 'unstyled:form':
854 $view_data['template'] = 'unstyled-form';
855 break;
856 case 'default:widget':
857 $view_data['template'] = 'small-widget';
858 break;
859 case 'image-right:widget':
860 $view_data['template'] = 'small-widget';
861 $view_data['template_settings'][ $view_data['template'] ] = array( 'image_position' => 'right' );
862 break;
863 default:
864 // Keep existing value; it's probably a custom template.
865 }
866
867 return $view_data;
868 }
869
870 /**
871 * Update template naming structure.
872 *
873 * @param $view_data
874 *
875 * @return array
876 */
877 public static function convert_template_name( $view_data ) {
878 // Change default template from empty to 'default:{type}'
879 if ( ! $view_data['template'] ) {
880 if ( 'form' === $view_data['mode'] ) {
881 $type = 'form';
882 } else {
883 $type = 'content';
884 }
885
886 $view_data['template'] = "default:$type";
887 } else {
888 // Convert name; e.g. 'simple/testimonials.php'
889 if ( 'widget/testimonials.php' === $view_data['template'] ) {
890 $view_data['template'] = 'default:widget';
891 } else {
892 $view_data['template'] = str_replace( '/', ':', $view_data['template'] );
893 $view_data['template'] = str_replace( 'testimonials.php', 'content', $view_data['template'] );
894 $view_data['template'] = str_replace( 'testimonial-form.php', 'form', $view_data['template'] );
895 }
896 }
897
898 return $view_data;
899 }
900
901 /**
902 * Convert length (characters).
903 *
904 * @since 2.10.0 word_count (deprecated)
905 * @since 2.11.4 excerpt_length
906 *
907 * @param $view_data
908 *
909 * @return array
910 */
911 public static function convert_excerpt_length( $view_data ) {
912 if ( ! isset( $view_data['excerpt_length'] ) || ! $view_data['excerpt_length'] ) {
913 $default_view = Strong_Testimonials_Defaults::get_default_view();
914 $average_word_length = self::get_average_word_length();
915
916 if ( isset( $view_data['length'] ) && $view_data['length'] ) {
917 $word_count = round( $view_data['length'] / $average_word_length );
918 $word_count = $word_count < 5 ? 5 : $word_count;
919 $word_count = $word_count > 300 ? 300 : $word_count;
920 $view_data['excerpt_length'] = $word_count;
921 } else {
922 $view_data['excerpt_length'] = $default_view['excerpt_length'];
923 }
924
925 unset( $view_data['length'] );
926 }
927
928 return $view_data;
929 }
930
931 /**
932 * Convert more_text to post or page.
933 *
934 * @since 2.10.0
935 *
936 * @param $view_data
937 *
938 * @return array
939 */
940 public static function convert_more_text( $view_data ) {
941 if ( isset( $view_data['more_text'] ) ) {
942 if ( isset( $view_data['more_page'] ) && $view_data['more_page'] > 1 ) {
943 // convert more_page to toggle and move page id to more_page_id
944 $view_data['more_page_id'] = $view_data['more_page'];
945 $view_data['more_page'] = 1;
946 $view_data['more_page_text'] = $view_data['more_text'];
947 } elseif ( isset( $view_data['more_post'] ) && $view_data['more_post'] ) {
948 $view_data['more_post_text'] = $view_data['more_text'];
949 }
950 unset( $view_data['more_text'] );
951 }
952
953 return $view_data;
954 }
955
956 /**
957 * Convert slideshow settings.
958 *
959 * @since 2.15.0
960 *
961 * @param $view_data
962 *
963 * @return array
964 */
965 public static function convert_slideshow( $view_data ) {
966 if ( isset( $view_data['slideshow_settings'] ) ) {
967 return $view_data;
968 }
969
970 if ( 'scrollHorz' === $view_data['effect'] ) {
971 $view_data['effect'] = 'horizontal';
972 }
973
974 $view_data['slideshow_settings'] = array(
975 'effect' => $view_data['effect'],
976 'speed' => $view_data['effect_for'],
977 'pause' => $view_data['show_for'],
978 'auto_hover' => ! $view_data['no_pause'],
979 'adapt_height' => false,
980 'adapt_height_speed' => .5,
981 'stretch' => isset( $view_data['stretch'] ) ? 1 : 0,
982 );
983
984 unset(
985 $view_data['effect'],
986 $view_data['effect_for'],
987 $view_data['no_pause'],
988 $view_data['show_for'],
989 $view_data['stretch']
990 );
991
992 if ( isset( $view_data['slideshow_nav'] ) ) {
993 switch ( $view_data['slideshow_nav'] ) {
994 case 'simple':
995 $view_data['slideshow_settings']['controls_type'] = 'none';
996 $view_data['slideshow_settings']['controls_style'] = 'buttons';
997 $view_data['slideshow_settings']['pager_type'] = 'full';
998 $view_data['slideshow_settings']['pager_style'] = 'buttons';
999 $view_data['slideshow_settings']['nav_position'] = 'inside';
1000 break;
1001 case 'buttons1':
1002 $view_data['slideshow_settings']['controls_type'] = 'sides';
1003 $view_data['slideshow_settings']['controls_style'] = 'buttons';
1004 $view_data['slideshow_settings']['pager_type'] = 'none';
1005 $view_data['slideshow_settings']['pager_style'] = 'buttons';
1006 $view_data['slideshow_settings']['nav_position'] = 'inside';
1007 break;
1008 case 'buttons2':
1009 $view_data['slideshow_settings']['controls_type'] = 'simple';
1010 $view_data['slideshow_settings']['controls_style'] = 'buttons2';
1011 $view_data['slideshow_settings']['pager_type'] = 'none';
1012 $view_data['slideshow_settings']['pager_style'] = 'buttons';
1013 $view_data['slideshow_settings']['nav_position'] = 'inside';
1014 break;
1015 case 'indexed':
1016 $view_data['slideshow_settings']['controls_type'] = 'none';
1017 $view_data['slideshow_settings']['controls_style'] = 'buttons';
1018 $view_data['slideshow_settings']['pager_type'] = 'full';
1019 $view_data['slideshow_settings']['pager_style'] = 'text';
1020 $view_data['slideshow_settings']['nav_position'] = 'inside';
1021 break;
1022 default:
1023 // none
1024 }
1025 unset( $view_data['slideshow_nav'] );
1026 }
1027
1028 return $view_data;
1029 }
1030
1031 /**
1032 * Convert 'all' to 'count'.
1033 *
1034 * @param $view_data
1035 *
1036 * @return array
1037 */
1038 public static function convert_count( $view_data ) {
1039 if ( isset( $view_data['all'] ) ) {
1040 if ( $view_data['all'] ) {
1041 $view_data['count'] = -1;
1042 }
1043 unset( $view_data['all'] );
1044 }
1045
1046 return $view_data;
1047 }
1048
1049 /**
1050 * Convert background color.
1051 *
1052 * @param $view_data
1053 *
1054 * @return array
1055 */
1056 public static function convert_background_color( $view_data ) {
1057 if ( ! is_array( $view_data['background'] ) ) {
1058 $view_data['background'] = array(
1059 'color' => $view_data['background'],
1060 'type' => 'single',
1061 );
1062 }
1063
1064 return $view_data;
1065 }
1066
1067 /**
1068 * Convert 'form-ajax' (hyphen) to 'form_ajax' (underscore).
1069 *
1070 * @param $view_data
1071 *
1072 * @return array
1073 */
1074 public static function convert_form_ajax( $view_data ) {
1075 if ( isset( $view_data['form-ajax'] ) ) {
1076 $view_data['form_ajax'] = $view_data['form-ajax'];
1077 unset( $view_data['form-ajax'] );
1078 }
1079
1080 return $view_data;
1081 }
1082
1083 /**
1084 * Prevent incompatible layouts.
1085 *
1086 * @param $view_data
1087 *
1088 * @return array
1089 */
1090 public static function convert_layout( $view_data ) {
1091 if ( isset( $view_data['pagination'] ) && $view_data['pagination'] ) {
1092 if ( isset( $view_data['layout'] ) && 'masonry' === $view_data['layout'] ) {
1093 $view_data['layout'] = '';
1094 }
1095 }
1096
1097 return $view_data;
1098 }
1099
1100 /**
1101 * Move word_count to excerpt_length for versions 2.10.0 to 2.11.3.
1102 *
1103 * @since 2.11.4
1104 *
1105 * @param $view_data
1106 *
1107 * @return array
1108 */
1109 public static function convert_word_count( $view_data ) {
1110 if ( isset( $view_data['word_count'] ) ) {
1111 $view_data['excerpt_length'] = $view_data['word_count'];
1112 unset( $view_data['word_count'] );
1113 }
1114
1115 return $view_data;
1116 }
1117
1118 /**
1119 * Disable title on Modern template because new version of template has the title.
1120 * Only if updating from version earlier than 2.12.4.
1121 *
1122 * @param $view_data
1123 *
1124 * @return array
1125 */
1126 public static function convert_modern_title( $view_data ) {
1127 if ( 'modern:content' === $view_data['template'] ) {
1128 if ( ! isset( $history['2.12.4_convert_modern_template'] ) ) {
1129 $view_data['title'] = 0;
1130 self::update_history_log( '2.12.4_convert_modern_template' );
1131 }
1132 }
1133
1134 return $view_data;
1135 }
1136
1137 /**
1138 * Title link
1139 *
1140 * @since 2.26.0
1141 *
1142 * @param $view_data
1143 *
1144 * @return array
1145 */
1146 public static function convert_title_link( $view_data ) {
1147 if ( ! isset( $view_data['title_link'] ) ) {
1148 $view_data['title_link'] = 'none';
1149 }
1150
1151 return $view_data;
1152 }
1153
1154
1155 /**
1156 * Convert nofollow from (on|off) to (1|0).
1157 *
1158 * @since 2.23.0
1159 */
1160 public static function convert_nofollow() {
1161 $args = array(
1162 'posts_per_page' => - 1,
1163 'post_type' => 'wpm-testimonial',
1164 'post_status' => 'publish',
1165 'suppress_filters' => true,
1166 );
1167 $posts = get_posts( $args );
1168 if ( ! $posts ) {
1169 return;
1170 }
1171
1172 /**
1173 * Remove the equivocation. There is no false.
1174 */
1175 foreach ( $posts as $post ) {
1176 $nofollow = get_post_meta( $post->ID, 'nofollow', true );
1177 $new_value = 'default';
1178
1179 if ( 'on' === $nofollow ) {
1180 $new_value = 'yes';
1181 } elseif ( 1 === $nofollow ) {
1182 $new_value = 'yes';
1183 } elseif ( 'off' === $nofollow ) {
1184 $new_value = 'no';
1185 } elseif ( 0 === $nofollow ) {
1186 $new_value = 'no';
1187 } elseif ( is_bool( $nofollow ) ) {
1188 if ( $nofollow ) {
1189 $new_value = 'yes';
1190 } else {
1191 $new_value = 'default';
1192 }
1193 }
1194
1195 update_post_meta( $post->ID, 'nofollow', $new_value );
1196 }
1197 }
1198
1199 /**
1200 * Convert noopener from (on|off) to (1|0).
1201 *
1202 * @since 2.41.0
1203 */
1204 public static function convert_noopener() {
1205 $args = array(
1206 'posts_per_page' => - 1,
1207 'post_type' => 'wpm-testimonial',
1208 'post_status' => 'publish',
1209 'suppress_filters' => true,
1210 );
1211 $posts = get_posts( $args );
1212 if ( ! $posts ) {
1213 return;
1214 }
1215
1216 /**
1217 * Remove the equivocation. There is no false.
1218 */
1219 foreach ( $posts as $post ) {
1220 $noopener = get_post_meta( $post->ID, 'noopener', true );
1221 $new_value = 'default';
1222
1223 if ( 'on' === $noopener ) {
1224 $new_value = 'yes';
1225 } elseif ( 1 === $noopener ) {
1226 $new_value = 'yes';
1227 } elseif ( 'off' === $noopener ) {
1228 $new_value = 'no';
1229 } elseif ( 0 === $noopener ) {
1230 $new_value = 'no';
1231 } elseif ( is_bool( $noopener ) ) {
1232 if ( $noopener ) {
1233 $new_value = 'yes';
1234 } else {
1235 $new_value = 'default';
1236 }
1237 }
1238
1239 update_post_meta( $post->ID, 'noopener', $new_value );
1240 }
1241 }
1242
1243 /**
1244 * Convert noreferrer from (on|off) to (1|0).
1245 *
1246 * @since 2.41.0
1247 */
1248 public static function convert_noreferrer() {
1249 $args = array(
1250 'posts_per_page' => - 1,
1251 'post_type' => 'wpm-testimonial',
1252 'post_status' => 'publish',
1253 'suppress_filters' => true,
1254 );
1255 $posts = get_posts( $args );
1256 if ( ! $posts ) {
1257 return;
1258 }
1259
1260 /**
1261 * Remove the equivocation. There is no false.
1262 */
1263 foreach ( $posts as $post ) {
1264 $noreferrer = get_post_meta( $post->ID, 'noreferrer', true );
1265 $new_value = 'default';
1266
1267 if ( 'on' === $noreferrer ) {
1268 $new_value = 'yes';
1269 } elseif ( 1 === $noreferrer ) {
1270 $new_value = 'yes';
1271 } elseif ( 'off' === $noreferrer ) {
1272 $new_value = 'no';
1273 } elseif ( 0 === $noreferrer ) {
1274 $new_value = 'no';
1275 } elseif ( is_bool( $noreferrer ) ) {
1276 if ( $noreferrer ) {
1277 $new_value = 'yes';
1278 } else {
1279 $new_value = 'default';
1280 }
1281 }
1282
1283 update_post_meta( $post->ID, 'noreferrer', $new_value );
1284 }
1285 }
1286
1287 /**
1288 * Convert pagination settings.
1289 *
1290 * @since 2.28.0
1291 *
1292 * @param $view_data
1293 *
1294 * @return mixed
1295 */
1296 public static function convert_pagination_type( $view_data ) {
1297 if ( isset( $view_data['pagination_type'] ) ) {
1298 $view_data['pagination_settings']['type'] = $view_data['pagination_type'];
1299 unset( $view_data['pagination_type'] );
1300 }
1301
1302 if ( isset( $view_data['nav'] ) ) {
1303 $view_data['pagination_settings']['nav'] = $view_data['nav'];
1304 unset( $view_data['nav'] );
1305 }
1306
1307 if ( isset( $view_data['per_page'] ) ) {
1308 $view_data['pagination_settings']['per_page'] = $view_data['per_page'];
1309 unset( $view_data['per_page'] );
1310 }
1311
1312 return $view_data;
1313 }
1314
1315 /**
1316 * Convert length to excerpt_length.
1317 *
1318 * @since 2.10.0
1319 */
1320 public static function get_average_word_length() {
1321 $args = array(
1322 'posts_per_page' => - 1,
1323 'post_type' => 'wpm-testimonial',
1324 'post_status' => 'publish',
1325 'suppress_filters' => true,
1326 );
1327 $posts = get_posts( $args );
1328 if ( ! $posts ) {
1329 return 5;
1330 }
1331
1332 $allwords = array();
1333
1334 foreach ( $posts as $post ) {
1335 $words = explode( ' ', $post->post_content );
1336 if ( count( $words ) > 5 ) {
1337 $allwords = $allwords + $words;
1338 }
1339 }
1340
1341 $wordstring = implode( '', $allwords );
1342
1343 return round( strlen( $wordstring ) / count( $allwords ) );
1344 }
1345 }
1346
1347 new Strong_Testimonials_Updater();
1348