PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / classes / class-migration.php

class-migration.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at classes/class-migration.php

164 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Migrations
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Migrations
14 */
15 class GhostKit_Migrations {
16 /**
17 * The version.
18 *
19 * @var string
20 */
21 protected $version = GHOSTKIT_VERSION;
22
23 /**
24 * Initial version.
25 *
26 * @var string
27 */
28 protected $initial_version = '2.25.0';
29
30 /**
31 * GhostKit_Migrations constructor.
32 */
33 public function __construct() {
34 if ( is_admin() ) {
35 add_action( 'admin_init', array( $this, 'init' ), 3 );
36 } else {
37 add_action( 'wp', array( $this, 'init' ), 3 );
38 }
39 }
40
41 /**
42 * Init.
43 */
44 public function init() {
45 // Migration code added after `$this->initial_version` plugin version.
46 $saved_version = get_option( 'ghostkit_db_version', $this->initial_version );
47 $current_version = $this->version;
48
49 foreach ( $this->get_migrations() as $migration ) {
50 if (
51 version_compare( $saved_version, $migration['version'], '<' ) &&
52 // A migration keyed above the plugin version belongs to a later release and waits for it.
53 version_compare( $migration['version'], $current_version, '<=' )
54 ) {
55 call_user_func( $migration['cb'] );
56 }
57 }
58
59 if ( version_compare( $saved_version, $current_version, '<' ) ) {
60 update_option( 'ghostkit_db_version', $current_version );
61 }
62 }
63
64 /**
65 * Get all available migrations.
66 *
67 * @return array
68 */
69 public function get_migrations() {
70 return array(
71 array(
72 'version' => '2.25.1',
73 'cb' => array( $this, 'v_2_25_1' ),
74 ),
75 array(
76 'version' => '3.7.2',
77 'cb' => array( $this, 'v_3_7_2' ),
78 ),
79 );
80 }
81
82 /**
83 * Remove what the runtime SCSS compiler left behind: compiled CSS in uploads,
84 * the cron event of its queue, and the options of the queue.
85 */
86 public function v_3_7_2() {
87 global $wpdb;
88
89 $upload_dir = wp_get_upload_dir();
90
91 GhostKit_Breakpoints::remove_dir( $upload_dir['basedir'] . '/ghostkit/gutenberg' );
92
93 wp_clear_scheduled_hook( 'ghostkit_run_breakpoints_processing_cron' );
94
95 delete_option( 'ghostkit_saved_breakpoints_hash' );
96
97 // The queue kept its batches and status as site options: sitemeta on multisite, options otherwise.
98 delete_site_option( 'ghostkit_run_breakpoints_processing_status' );
99
100 $batch_like = $wpdb->esc_like( 'ghostkit_run_breakpoints_processing_batch_' ) . '%';
101
102 if ( is_multisite() ) {
103 // phpcs:ignore
104 $batch_options = $wpdb->get_col(
105 $wpdb->prepare(
106 "SELECT meta_key FROM {$wpdb->sitemeta} WHERE site_id = %d AND meta_key LIKE %s",
107 get_current_network_id(),
108 $batch_like
109 )
110 );
111 } else {
112 // phpcs:ignore
113 $batch_options = $wpdb->get_col(
114 $wpdb->prepare(
115 "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
116 $batch_like
117 )
118 );
119 }
120
121 foreach ( $batch_options as $batch_option ) {
122 delete_site_option( $batch_option );
123 }
124 }
125
126 /**
127 * Fix typography with google-fonts category.
128 */
129 public function v_2_25_1() {
130 $current_typography_encode = get_option( 'ghostkit_typography', array() );
131 $typography_migrated = false;
132 if ( ! empty( $current_typography_encode ) ) {
133 $current_typography_decode = json_decode( $current_typography_encode['ghostkit_typography'], true );
134 $fonts_list = apply_filters( 'gkt_fonts_list', array() );
135 if ( ! empty( $current_typography_decode ) && ! empty( $fonts_list ) ) {
136 foreach ( $current_typography_decode as &$typography ) {
137 if (
138 isset( $typography['fontFamilyCategory'] ) &&
139 'default' === $typography['fontFamilyCategory'] &&
140 isset( $typography['fontFamily'] )
141 ) {
142 // Find typography font from fonts list default category.
143 $found_default_font = null !== $fonts_list['default']['fonts'] ? array_search( $typography['fontFamily'], array_column( $fonts_list['default']['fonts'], 'name' ), true ) : false;
144 // If not find, search font from google fonts category.
145 if ( false === $found_default_font ) {
146 $found_google_font = array_search( $typography['fontFamily'], array_column( $fonts_list['google-fonts']['fonts'], 'name' ), true );
147 if ( false !== $found_google_font ) {
148 $typography['fontFamilyCategory'] = 'google-fonts';
149 $typography_migrated = true;
150 }
151 }
152 }
153 }
154 if ( $typography_migrated ) {
155 $current_typography_encode['ghostkit_typography'] = wp_json_encode( $current_typography_decode );
156 update_option( 'ghostkit_typography', $current_typography_encode );
157 }
158 }
159 }
160 }
161 }
162
163 new GhostKit_Migrations();
164