PluginProbe
Button Generator – Easily Create Custom Buttons with Icons and Analytics / 3.2
Button Generator – Easily Create Custom Buttons with Icons and Analytics v3.2
trunk 1.1.1 2.0 2.1 2.2 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.2 3.2.1 3.2.2 3.2.3 All 28 releases
button-generation / classes / Update / UpdateDB.php

UpdateDB.php in Button Generator – Easily Create Custom Buttons with Icons and Analytics 3.2, at classes/Update/UpdateDB.php

226 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class UpdateDB
5 *
6 * Contains methods for updating the database structure and data
7 *
8 * @package ButtonGenerator
9 * @subpackage Update
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 *
14 */
15
16 namespace ButtonGenerator\Update;
17
18 use ButtonGenerator\Admin\DBManager;
19 use ButtonGenerator\Settings_Helper;
20 use ButtonGenerator\WOWP_Plugin;
21
22 class UpdateDB {
23
24 public static function init(): void {
25 $current_db_version = get_site_option( WOWP_Plugin::PREFIX . '_db_version' );
26
27 if ( $current_db_version && version_compare( $current_db_version, '3.0', '>=' ) ) {
28 return;
29 }
30
31 self::start_update();
32
33 update_site_option( WOWP_Plugin::PREFIX . '_db_version', '3.0' );
34 }
35
36 public static function start_update(): void {
37 self::update_database();
38 self::update_options();
39 self::update_fields();
40 }
41
42 public static function update_database(): void {
43
44 global $wpdb;
45 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
46 $charset_collate = $wpdb->get_charset_collate();
47
48 $columns = "
49 id mediumint(9) NOT NULL AUTO_INCREMENT,
50 title VARCHAR(200) DEFAULT '' NOT NULL,
51 param longtext DEFAULT '' NOT NULL,
52 status boolean DEFAULT 0 NOT NULL,
53 mode boolean DEFAULT 0 NOT NULL,
54 tag text DEFAULT '' NOT NULL,
55 PRIMARY KEY (id)
56 ";
57
58 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
59
60 $sql = "CREATE TABLE $table ($columns) $charset_collate;";
61 dbDelta( $sql );
62 }
63
64 public static function update_options(): void {
65
66 $license = get_option( 'wow_license_key_fmp' );
67 $status = get_option( 'wow_license_status_fmp' );
68 if ( $license !== false ) {
69 update_option( 'wow_license_key_' . WOWP_Plugin::PREFIX, $license );
70 }
71
72 if ( $status !== false ) {
73 update_option( 'wow_license_status_' . WOWP_Plugin::PREFIX, $status );
74 }
75 }
76
77 public static function update_fields(): void {
78 $results = DBManager::get_all_data();
79
80 if ( empty( $results ) || ! is_array( $results ) ) {
81 return;
82 }
83 foreach ( $results as $result ) {
84 $param = maybe_unserialize( $result->param );
85 $status = 0;
86 $test_mode = 0;
87
88 $param = self::update_param( $param );
89
90 $data = [
91 'param' => maybe_serialize( $param ),
92 'status' => absint( $status ),
93 'mode' => absint( $test_mode ),
94 'tag' => '',
95 ];
96
97 $where = [ 'id' => $result->id ];
98
99 $data_formats = [ '%s', '%d', '%d', '%s' ];
100
101 DBManager::update( $data, $where, $data_formats );
102
103 }
104 }
105
106 public static function update_param( $param ) {
107 if ( isset( $param['text_location'] ) ) {
108 if ( $param['text_location'] === 'before' ) {
109 $param['text_location'] = 'row';
110 }
111 if ( $param['text_location'] === 'after' ) {
112 $param['text_location'] = 'row-reverse';
113 }
114 }
115
116 $param['hover_effects'] = 'none';
117
118 if ( ! isset( $param['icon_size'] ) ) {
119 $param['icon_size'] = $param['font_size'];
120 }
121
122 if ( ! isset( $param['icon_color'] ) ) {
123 $param['icon_color'] = $param['color'];
124 }
125
126 if ( ! isset( $param['icon_hover_color'] ) ) {
127 $param['icon_hover_color'] = $param['hover_color'];
128 }
129
130 // Responsive
131 if ( ! isset( $param['mobile_on'] ) ) {
132 $param['mobile_on'] = $param['include_mobile'] ?? 0;
133 }
134 if ( ! isset( $param['mobile'] ) ) {
135 $param['mobile'] = $param['screen'] ?? 768;
136 }
137 if ( ! isset( $param['desktop_on'] ) ) {
138 $param['desktop_on'] = $param['include_more_screen'] ?? 0;
139 }
140 if ( ! isset( $param['desktop'] ) ) {
141 $param['desktop'] = $param['screen_more'] ?? 1024;
142 }
143
144 // Other options
145 if ( ! isset( $param['fontawesome'] ) ) {
146 $param['fontawesome'] = $param['disable_fontawesome'] ?? 0;
147 }
148
149
150 // Show
151 if ( ! is_array( $param['show'] ) ) {
152 $show_old = ! empty( $param['show'] ) ? $param['show'] : 'shortcode';
153
154 $param['show'] = [];
155 $param['operator'] = [];
156 $param['page_type'] = [];
157 $param['ids'] = [];
158
159 $param['show'][0] = 'shortcode';
160 $param['operator'][0] = '1';
161 $param['page_type'][0] = 'is_front_page';
162 $param['ids'][0] = '';
163
164 switch ( $show_old ) {
165 case 'all':
166 $param['show'][0] = 'everywhere';
167 break;
168 case 'onlypost':
169 $param['show'][0] = 'post_all';
170 break;
171 case 'posts':
172 $param['show'][0] = 'post_selected';
173 $param['ids'][0] = ! empty( $param['id_post'] ) ? $param['id_post'] : '';
174 break;
175 case 'postsincat':
176 $param['show'][0] = 'post_category';
177 $param['ids'][0] = ! empty( $param['id_post'] ) ? $param['id_post'] : '';
178 break;
179 case 'expost':
180 $param['show'][0] = 'post_selected';
181 $param['operator'][0] = 0;
182 $param['ids'][0] = ! empty( $param['id_post'] ) ? $param['id_post'] : '';
183 break;
184 case 'onlypage':
185 $param['show'][0] = 'page_all';
186 break;
187 case 'pages':
188 $param['show'][0] = 'page_selected';
189 $param['ids'][0] = ! empty( $param['id_post'] ) ? $param['id_post'] : '';
190 break;
191 case 'expage':
192 $param['show'][0] = 'page_selected';
193 $param['operator'][0] = 0;
194 $param['ids'][0] = ! empty( $param['id_post'] ) ? $param['id_post'] : '';
195 break;
196 case 'homepage':
197 $param['show'][0] = 'page_type';
198 $param['page_type'][0] = 'is_front_page';
199 break;
200 case 'searchpage':
201 $param['show'][0] = 'page_type';
202 $param['page_type'][0] = 'is_search';
203 break;
204 case 'archivepage':
205 $param['show'][0] = 'page_type';
206 $param['page_type'][0] = 'is_archive';
207 break;
208 case 'error_page':
209 $param['show'][0] = 'page_type';
210 $param['page_type'][0] = 'is_404';
211 break;
212 case 'post_type':
213 $custom_post = $param['post_types'] ?? '';
214 $param['show'][0] = 'custom_post_all_' . $custom_post;
215 break;
216 case 'taxonomy':
217 $taxonomy = $param['taxonomy'] ?? '';
218 $param['show'][0] = 'custom_post_tax_|' . $taxonomy;
219 break;
220 }
221 }
222
223 return $param;
224 }
225
226 }