PluginProbe
WP Ultimate Post Grid / 4.1.1
WP Ultimate Post Grid v4.1.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / includes / public / class-wpupg-migrations.php

class-wpupg-migrations.php in WP Ultimate Post Grid 4.1.1, at includes/public/class-wpupg-migrations.php

152 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for version migrations.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 3.0.0
7 *
8 * @package WP_Ultimate_Post_Grid
9 * @subpackage WP_Ultimate_Post_Grid/includes/public
10 */
11
12 /**
13 * Responsible for version migrations.
14 *
15 * @since 3.0.0
16 * @package WP_Ultimate_Post_Grid
17 * @subpackage WP_Ultimate_Post_Grid/includes/public
18 * @author Brecht Vandersmissen <brecht@bootstrapped.ventures>
19 */
20 class WPUPG_Migrations {
21
22 /**
23 * Register actions and filters.
24 *
25 * @since 3.0.0
26 */
27 public static function init() {
28 add_action( 'admin_init', array( __CLASS__, 'check_if_migration_needed' ) );
29 }
30
31
32 /**
33 * Check if a plugin migration is needed.
34 *
35 * @since 3.0.0
36 */
37 public static function check_if_migration_needed() {
38 // Version Migrations.
39 $migrated_to_version = get_option( 'wpupg_migrated_to_version', '0.0.0' );
40
41 if ( version_compare( $migrated_to_version, WPUPG_VERSION ) < 0 ) {
42 if ( version_compare( $migrated_to_version, '3.0.0' ) < 0 ) {
43 require_once( WPUPG_DIR . 'includes/public/migrations/wpupg-3-0-0-settings.php' );
44 }
45
46 update_option( 'wpupg_migrated_to_version', WPUPG_VERSION );
47 }
48 }
49
50 /**
51 * Single filter (pre 3.0.0) to multiple filters per grid.
52 *
53 * @since 3.0.0
54 * @param mixed $grid Grid to migrate.
55 */
56 public static function single_filter_to_multiple( $grid ) {
57 $filters = array();
58 $filter_type = $grid->meta( 'filter_type', 'none' );
59
60 if ( 'text_isotope' === $filter_type || 'isotope' === $filter_type ) {
61 $filter_defaults = WPUPG_Filter::get_defaults();
62
63 $filter_style = $grid->unserialize( $grid->meta( 'filter_style', array() ) );
64 $filter_style = is_array( $filter_style ) ? $filter_style : array();
65 $isotope_style = isset( $filter_style['isotope'] ) && is_array( $filter_style['isotope'] ) ? $filter_style['isotope'] : array();
66
67 $migrated_options = array(
68 'taxonomies' => $grid->unserialize( $grid->meta( 'filter_taxonomies', array() ) ),
69 'match_parents' => $grid->meta( 'filter_match_parents', false ),
70 'inverse' => $grid->meta( 'filter_inverse', false ),
71 'show_empty' => $grid->meta( 'filter_show_empty', false ),
72 'count' => $grid->meta( 'filter_count', false ),
73 'multiselect' => $grid->meta( 'filter_multiselect', false ),
74 'multiselect_type' => $grid->meta( 'filter_multiselect_type', 'match_all' ),
75 'limit' => $grid->meta( 'filter_limit', false ),
76 'limit_exclude' => $grid->meta( 'filter_limit_exclude', false ),
77 'limit_terms' => $grid->unserialize( $grid->meta( 'filter_limit_terms', array() ) ),
78 );
79
80 if ( isset( $isotope_style['all_button_text'] ) ) {
81 $migrated_options['all_button_text'] = $isotope_style['all_button_text'];
82 }
83
84 if ( isset( $isotope_style['term_order'] ) ) {
85 $migrated_options['term_order'] = $isotope_style['term_order'];
86 }
87
88 if ( $isotope_style ) {
89 $migrated_options['style'] = $isotope_style;
90 }
91
92 $options = array_replace_recursive( $filter_defaults['isotope'], $migrated_options );
93
94 $filters[] = array(
95 'id' => '',
96 'type' => 'isotope',
97 'options' => $options,
98 );
99 }
100
101 return apply_filters( 'wpupg_migration_single_filter_to_multiple', $filters, $grid, $filter_type );
102 }
103
104 /**
105 * Get pagination style (pre 3.0.0) combined with pagination.
106 *
107 * @since 3.0.0
108 * @param mixed $grid Grid to migrate.
109 */
110 public static function get_pagination_with_style( $grid ) {
111 $pagination = $grid->unserialize( $grid->meta( 'pagination', array() ) );
112 $pagination_type = $grid->meta( 'pagination_type', 'none' );
113
114 if ( in_array( $pagination_type, array( 'pages', 'load_more', 'load_more_filter' ) ) ) {
115 $pagination_style = $grid->unserialize( $grid->meta( 'pagination_style', array() ) );
116
117 $pagination[ $pagination_type ]['style'] = $pagination_style;
118
119 if ( 'load_more_filter' === $pagination_type ) {
120 $pagination[ $pagination_type ]['load_on_filter'] = true;
121
122 // Not a separate pagination type anymore.
123 $pagination['load_more'] = $pagination['load_more_filter'];
124 unset( $pagination['load_more_filter'] );
125 }
126 }
127
128 return $pagination;
129 }
130
131 /**
132 * Get correct template from template id (pre 3.0.0).
133 *
134 * @since 3.0.0
135 * @param mixed $grid Grid to migrate.
136 */
137 public static function template_mapping( $grid ) {
138 $mapping = array(
139 0 => 'simple',
140 1 => 'simple-with-excerpt',
141 2 => 'overlay',
142 3 => 'hover-with-date',
143 );
144
145 $id = intval( $grid->meta( 'template', 0 ) );
146
147 return isset( $mapping[ $id ] ) ? $mapping[ $id ] : $mapping[ 0 ];
148 }
149 }
150
151 WPUPG_Migrations::init();
152