PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.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.0.1, at includes/public/class-wpupg-migrations.php

138 lines 4.1 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 <[email protected]>
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
65 $options = array_replace_recursive( $filter_defaults['isotope'], array(
66 'taxonomies' => $grid->unserialize( $grid->meta( 'filter_taxonomies', array() ) ),
67 'match_parents' => $grid->meta( 'filter_match_parents', false ),
68 'inverse' => $grid->meta( 'filter_inverse', false ),
69 'show_empty' => $grid->meta( 'filter_show_empty', false ),
70 'count' => $grid->meta( 'filter_count', false ),
71 'multiselect' => $grid->meta( 'filter_multiselect', false ),
72 'multiselect_type' => $grid->meta( 'filter_multiselect_type', 'match_all' ),
73 'limit' => $grid->meta( 'filter_limit', false ),
74 'limit_exclude' => $grid->meta( 'filter_limit_exclude', false ),
75 'limit_terms' => $grid->unserialize( $grid->meta( 'filter_limit_terms', array() ) ),
76 'all_button_text' => $filter_style['isotope']['all_button_text'],
77 'term_order' => $filter_style['isotope']['term_order'],
78 'style' => $filter_style['isotope'],
79 ) );
80
81 $filters[] = array(
82 'id' => '',
83 'type' => 'isotope',
84 'options' => $options,
85 );
86 }
87
88 return apply_filters( 'wpupg_migration_single_filter_to_multiple', $filters, $grid, $filter_type );
89 }
90
91 /**
92 * Get pagination style (pre 3.0.0) combined with pagination.
93 *
94 * @since 3.0.0
95 * @param mixed $grid Grid to migrate.
96 */
97 public static function get_pagination_with_style( $grid ) {
98 $pagination = $grid->unserialize( $grid->meta( 'pagination', array() ) );
99 $pagination_type = $grid->meta( 'pagination_type', 'none' );
100
101 if ( in_array( $pagination_type, array( 'pages', 'load_more', 'load_more_filter' ) ) ) {
102 $pagination_style = $grid->unserialize( $grid->meta( 'pagination_style', array() ) );
103
104 $pagination[ $pagination_type ]['style'] = $pagination_style;
105
106 if ( 'load_more_filter' === $pagination_type ) {
107 $pagination[ $pagination_type ]['load_on_filter'] = true;
108
109 // Not a separate pagination type anymore.
110 $pagination['load_more'] = $pagination['load_more_filter'];
111 unset( $pagination['load_more_filter'] );
112 }
113 }
114
115 return $pagination;
116 }
117
118 /**
119 * Get correct template from template id (pre 3.0.0).
120 *
121 * @since 3.0.0
122 * @param mixed $grid Grid to migrate.
123 */
124 public static function template_mapping( $grid ) {
125 $mapping = array(
126 0 => 'simple',
127 1 => 'simple-with-excerpt',
128 2 => 'overlay',
129 3 => 'hover-with-date',
130 );
131
132 $id = intval( $grid->meta( 'template', 0 ) );
133
134 return isset( $mapping[ $id ] ) ? $mapping[ $id ] : $mapping[ 0 ];
135 }
136 }
137
138 WPUPG_Migrations::init();