PluginProbe
Shariff Wrapper / trunk
Shariff Wrapper vtrunk
4.6.22 4.6.21 4.6.20 4.6.19 trunk 1.0.0 1.9.0 1.9.9 2.4.3 3.4.2 4.0.8 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.3.0 4.4.2 4.4.3 4.4.4 4.5.0 4.5.1 4.5.2 4.5.3 4.6.0 All 42 releases
shariff / updates.php

updates.php in Shariff Wrapper trunk, at updates.php

407 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Will be included by shariff3uu_update() only if needed.
4 * Put all update task here. Make sure that all "older" updates are checked first.
5 * At least you must set $shariff3uu['version'] = [YOUR VERSION]; to avoid includes later on.
6 *
7 * @package WordPress
8 */
9
10 // Prevent direct calls.
11 if ( ! class_exists( 'WP' ) ) { die(); }
12 // and again the same because the WP Plugin Check does not understand what the line above does ;-)
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 /**
16 * Migration < 2.3
17 * Split options in database according to new setting tabs.
18 * Delete old cache directory.
19 */
20 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '2.2.5' ) ) {
21
22 // Basic options.
23 if ( isset( $shariff3uu['version'] ) ) {
24 $shariff3uu_basic['version'] = $shariff3uu['version'];
25 }
26 if ( isset( $shariff3uu['services'] ) ) {
27 $shariff3uu_basic['services'] = $shariff3uu['services'];
28 }
29 if ( isset( $shariff3uu['add_after_all_posts'] ) ) {
30 $shariff3uu_basic['add_after']['posts'] = $shariff3uu['add_after_all_posts'];
31 }
32 if ( isset( $shariff3uu['add_after_all_overview'] ) ) {
33 $shariff3uu_basic['add_after']['posts_blogpage'] = $shariff3uu['add_after_all_overview'];
34 }
35 if ( isset( $shariff3uu['add_after_all_pages'] ) ) {
36 $shariff3uu_basic['add_after']['pages'] = $shariff3uu['add_after_all_pages'];
37 }
38 if ( isset( $shariff3uu['add_after_all_custom_type'] ) ) {
39 $shariff3uu_basic['add_after']['custom_type'] = $shariff3uu['add_after_all_custom_type'];
40 }
41 if ( isset( $shariff3uu['add_before_all_posts'] ) ) {
42 $shariff3uu_basic['add_before']['posts'] = $shariff3uu['add_before_all_posts'];
43 }
44 if ( isset( $shariff3uu['add_before_all_overview'] ) ) {
45 $shariff3uu_basic['add_before']['posts_blogpage'] = $shariff3uu['add_before_all_overview'];
46 }
47 if ( isset( $shariff3uu['add_before_all_pages'] ) ) {
48 $shariff3uu_basic['add_before']['pages'] = $shariff3uu['add_before_all_pages'];
49 }
50 if ( isset( $shariff3uu['disable_on_protected'] ) ) {
51 $shariff3uu_basic['disable_on_protected'] = $shariff3uu['disable_on_protected'];
52 }
53 if ( isset( $shariff3uu['backend'] ) ) {
54 $shariff3uu_basic['backend'] = $shariff3uu['backend'];
55 }
56
57 // Design options.
58 if ( isset( $shariff3uu['language'] ) ) {
59 $shariff3uu_design['language'] = $shariff3uu['language'];
60 }
61 if ( isset( $shariff3uu['theme'] ) ) {
62 $shariff3uu_design['theme'] = $shariff3uu['theme'];
63 }
64 if ( isset( $shariff3uu['buttonsize'] ) ) {
65 $shariff3uu_design['buttonsize'] = $shariff3uu['buttonsize'];
66 }
67 if ( isset( $shariff3uu['vertical'] ) ) {
68 $shariff3uu_design['vertical'] = $shariff3uu['vertical'];
69 }
70 if ( isset( $shariff3uu['align'] ) ) {
71 $shariff3uu_design['align'] = $shariff3uu['align'];
72 }
73 if ( isset( $shariff3uu['align_widget'] ) ) {
74 $shariff3uu_design['align_widget'] = $shariff3uu['align_widget'];
75 }
76 if ( isset( $shariff3uu['style'] ) ) {
77 $shariff3uu_design['style'] = $shariff3uu['style'];
78 }
79
80 // Advanced options.
81 if ( isset( $shariff3uu['info_url'] ) ) {
82 $shariff3uu_advanced['info_url'] = $shariff3uu['info_url'];
83 }
84 if ( isset( $shariff3uu['twitter_via'] ) ) {
85 $shariff3uu_advanced['twitter_via'] = $shariff3uu['twitter_via'];
86 }
87 if ( isset( $shariff3uu['flattruser'] ) ) {
88 $shariff3uu_advanced['flattruser'] = $shariff3uu['flattruser'];
89 }
90 if ( isset( $shariff3uu['default_pinterest'] ) ) {
91 $shariff3uu_advanced['default_pinterest'] = $shariff3uu['default_pinterest'];
92 }
93
94 // Mailform options.
95 if ( isset( $shariff3uu['mail_add_post_content'] ) ) {
96 $GLOBALS['shariff3UU_mailform']['mail_add_post_content'] = $shariff3uu['mail_add_post_content'];
97 }
98 if ( isset( $shariff3uu['mail_sender_name'] ) ) {
99 $GLOBALS['shariff3UU_mailform']['mail_sender_name'] = $shariff3uu['mail_sender_name'];
100 }
101 if ( isset( $shariff3uu['mail_sender_from'] ) ) {
102 $GLOBALS['shariff3UU_mailform']['mail_sender_from'] = $shariff3uu['mail_sender_from'];
103 }
104 // Default options should be as save as possible, same reason the statistics are disabled by default.
105 $GLOBALS['shariff3UU_mailform']['require_sender'] = 1;
106
107 // Update global.
108 $shariff3uu = array_merge( $shariff3uu_basic, $shariff3uu_design, $shariff3uu_advanced, $GLOBALS['shariff3UU_mailform'] );
109
110 // Update version.
111 $shariff3uu['version'] = '2.3.0';
112 }
113
114 /**
115 * Migration < 3.3
116 * Update options that were moved.
117 * Delete old cache directory and db entry.
118 */
119 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '3.3.0' ) ) {
120
121 // Update options that were moved.
122 if ( isset( $shariff3uu['backend'] ) ) {
123 $shariff3uu_statistic['backend'] = $shariff3uu['backend'];
124 }
125 if ( isset( $shariff3uu['fb_id'] ) ) {
126 $shariff3uu_statistic['fb_id'] = $shariff3uu['fb_id'];
127 }
128 if ( isset( $shariff3uu['fb_secret'] ) ) {
129 $shariff3uu_statistic['fb_secret'] = $shariff3uu['fb_secret'];
130 }
131 if ( isset( $shariff3uu['ttl'] ) ) {
132 $shariff3uu_statistic['ttl'] = $shariff3uu['ttl'];
133 }
134 if ( isset( $shariff3uu['disable'] ) ) {
135 $shariff3uu_statistic['disable'] = $shariff3uu['disable'];
136 }
137
138 // Delete old cache directory and db entry.
139 if ( is_multisite() ) {
140 global $wpdb;
141 // phpcs:ignore
142 $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A );
143 if ( $blogs ) {
144 foreach ( $blogs as $blog ) {
145 // Switch to each blog.
146 switch_to_blog( $blog['blog_id'] );
147 // Delete cache dir.
148 shariff_removeoldcachedir();
149 // Delete old db entry.
150 delete_option( 'shariff3UU' );
151 // Switch back to main.
152 restore_current_blog();
153 }
154 }
155 } else {
156 // Delete cache dir.
157 shariff_removeoldcachedir();
158 // Delete old db entry.
159 delete_option( 'shariff3UU' );
160 }
161
162 // Disable Twitter backend due to new service OpenShareCount.com.
163 $shariff3uu_statistic['disable']['twitter'] = 1;
164
165 // Update version.
166 $shariff3uu['version'] = '3.3.0';
167 }
168
169 /**
170 * Helper function to delete old cache directory.
171 */
172 function shariff_removeoldcachedir() {
173 $upload_dir = wp_upload_dir();
174 $cache_dir = $upload_dir['basedir'] . '/1970/01';
175 $cache_dir2 = $upload_dir['basedir'] . '/1970';
176 shariff_removeoldfiles( $cache_dir );
177 // Remove /1970/01 and /1970 if they are empty.
178 rmdir( $cache_dir );
179 rmdir( $cache_dir2 );
180 }
181
182 /**
183 * Helper function to delete old .dat files that begin with 'Shariff' and empty folders that also start with 'Shariff'.
184 *
185 * @param string $directory Path to Shariff cache directory.
186 */
187 function shariff_removeoldfiles( $directory ) {
188 foreach ( glob( $directory . '/Shariff*' ) as $file ) {
189 if ( is_dir( $file ) ) {
190 shariff_removeoldfiles( $file );
191 } elseif ( substr( $file, -4 ) === '.dat' ) {
192 unlink( $file );
193 }
194 }
195 rmdir( $directory );
196 }
197
198 /**
199 * Migration < 4.0
200 */
201 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.0.0' ) ) {
202
203 // Set new option share counts, if statistic is enabled.
204 if ( isset( $shariff3uu_statistic['backend'] ) ) {
205 $shariff3uu_statistic['sharecounts'] = 1;
206 }
207
208 // Disable share counts if WP version < 4.4.
209 if ( version_compare( get_bloginfo( 'version' ), '4.4.0' ) < 1 ) {
210 unset( $shariff3uu_statistic['backend'] );
211 }
212
213 // Change button language to WordPress language, if it is set to auto and http_negotiate_language is not available (auto will not work without it).
214 if ( ! isset( $shariff3uu_design['lang'] ) && ! function_exists( 'http_negotiate_language' ) ) {
215 $shariff3uu_design['lang'] = substr( get_bloginfo( 'language' ), 0, 2 );
216 }
217
218 // Update version.
219 $shariff3uu['version'] = '4.0.0';
220 }
221
222 /**
223 * Migration < 4.2
224 */
225 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.2.0' ) ) {
226 // Make sure we have the $wpdb class ready.
227 global $wpdb;
228
229 // Delete user meta entry shariff3UU_ignore_notice to display update message again after an update (check for multisite).
230 if ( is_multisite() ) {
231 // phpcs:ignore
232 $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A );
233 if ( $blogs ) {
234 foreach ( $blogs as $blog ) {
235 // Switch to each blog.
236 switch_to_blog( $blog['blog_id'] );
237 // Delete user meta entry shariff3UU_ignore_notice.
238 $users = get_users( 'role=administrator' );
239 foreach ( $users as $user ) {
240 if ( get_user_meta( $user->ID, 'shariff3UU_ignore_notice', true ) ) {
241 delete_user_meta( $user->ID, 'shariff3UU_ignore_notice' );
242 }
243 }
244 // Switch back to main.
245 restore_current_blog();
246 }
247 }
248 } else {
249 // Delete user meta entry shariff3UU_ignore_notice.
250 $users = get_users( 'role=administrator' );
251 foreach ( $users as $user ) {
252 if ( get_user_meta( $user->ID, 'shariff3UU_ignore_notice', true ) ) {
253 delete_user_meta( $user->ID, 'shariff3UU_ignore_notice' );
254 }
255 }
256 }
257 $shariff3uu['version'] = '4.2.0';
258 }
259
260 /**
261 * Migration < 4.5
262 */
263 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.5.0' ) ) {
264 // Update language settings.
265 if ( ! isset( $shariff3uu_design['lang'] ) ) {
266 $shariff3uu_design['autolang'] = 1;
267 $shariff3uu_design['lang'] = substr( get_locale(), 0, 2 );
268 }
269 // Update version.
270 $shariff3uu['version'] = '4.5.0';
271 }
272
273
274 /**
275 * Migration < 4.6.13
276 * cleanup the post/pages/custom types
277 */
278 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.6.13' ) ) {
279 // cleanup the post/pages/custom types options to avoid code confusion with double variables
280 if ( isset( $shariff3uu_basic['add_after']['posts'] ) ) {
281 $shariff3uu_basic['add_after']['post'] = $shariff3uu_basic['add_after']['posts'];
282 unset($shariff3uu_basic['add_after']['posts']);
283 }
284 if ( isset( $shariff3uu_basic['add_after']['posts_blogpage'] ) ) {
285 $shariff3uu_basic['add_after']['blogpage'] = $shariff3uu_basic['add_after']['posts_blogpage'];
286 unset($shariff3uu_basic['add_after']['posts_blogpage']);
287 }
288 if ( isset( $shariff3uu_basic['add_after']['pages'] ) ) {
289 $shariff3uu_basic['add_after']['page'] = $shariff3uu_basic['']['pages'];
290 unset($shariff3uu_basic['']['pages']);
291 }
292
293 if ( isset( $shariff3uu_basic['add_before']['posts'] ) ) {
294 $shariff3uu_basic['add_before']['post'] = $shariff3uu_basic['add_before']['posts'];
295 unset($shariff3uu_basic['add_before']['posts']);
296 }
297 if ( isset( $shariff3uu_basic['add_before']['posts_blogpage'] ) ) {
298 $shariff3uu_basic['add_before']['blogpage'] = $shariff3uu_basic['add_before']['posts_blogpage'];
299 unset($shariff3uu_basic['add_before']['posts_blogpage']);
300 }
301 if ( isset( $shariff3uu_basic['add_before']['pages'] ) ) {
302 $shariff3uu_basic['add_before']['page'] = $shariff3uu_basic['']['pages'];
303 unset($shariff3uu_basic['']['pages']);
304 }
305 // Update version.
306 $shariff3uu['version'] = '4.6.13';
307 }
308
309
310 /**
311 * Migration < 4.6.21
312 * Security fix: re-sanitize headline after %total replacement.
313 */
314 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.6.21' ) ) {
315 update_option( 'shariff3uu_admin_notice', '4.6.21: A security fix was applied to headline sanitization. Please review your headline settings and any use of the %total placeholder.' );
316 $shariff3uu['version'] = '4.6.21';
317 }
318
319 /**
320 * Migration < 4.6.22
321 * Fix add_after/add_before values incorrectly stored as strings instead of integers
322 * since 4.6.18 introduced sanitize_key() instead of absint() for these checkbox values.
323 * The strict 1 === comparisons in shariff.php require integers.
324 */
325 if ( isset( $shariff3uu['version'] ) && -1 === version_compare( $shariff3uu['version'], '4.6.22' ) ) {
326 foreach ( array( 'add_after', 'add_before' ) as $key ) {
327 if ( isset( $shariff3uu_basic[ $key ] ) && is_array( $shariff3uu_basic[ $key ] ) ) {
328 $shariff3uu_basic[ $key ] = array_map( 'absint', $shariff3uu_basic[ $key ] );
329 $shariff3uu_basic[ $key ] = array_filter( $shariff3uu_basic[ $key ] );
330 }
331 }
332 $shariff3uu['version'] = '4.6.22';
333 }
334
335 /**
336 * General tasks we do on every update, like clean up transients and so on.
337 */
338
339 // Purge transients (check for multisite).
340 if ( is_multisite() ) {
341 global $wpdb;
342 // phpcs:ignore
343 $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A );
344 if ( $blogs ) {
345 foreach ( $blogs as $blog ) {
346 // Switch to each blog.
347 switch_to_blog( $blog['blog_id'] );
348 // Purge transients.
349 shariff3uu_purge_transients();
350 // Switch back to main.
351 restore_current_blog();
352 }
353 }
354 } else {
355 // Purge transients.
356 shariff3uu_purge_transients();
357 }
358
359 /**
360 * Helper function to purge all the transients associated with our plugin.
361 */
362 function shariff3uu_purge_transients() {
363 // Make sure we have the $wpdb class ready.
364 if ( ! isset( $wpdb ) ) {
365 global $wpdb;
366 }
367 // Delete transients.
368 // phpcs:disable
369 $wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "_transient_timeout_shariff%"' );
370 $wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "_transient_shariff%"' );
371 // phpcs:enable
372 // Clear object cache.
373 wp_cache_flush();
374 }
375
376 // Set new version.
377 $shariff3uu['version'] = $code_version;
378 $shariff3uu_basic['version'] = $code_version;
379
380 /**
381 * Remove empty elements and save to options table. We had a mix up with shariff3uu and shariff3UU in the past and update_option is not case senitive. Therefore we actually need to delete and recreate it.
382 */
383 // Basic.
384 delete_option( 'shariff3uu_basic' );
385 $shariff3uu_basic = array_filter( $shariff3uu_basic );
386 update_option( 'shariff3uu_basic', $shariff3uu_basic );
387 // Design.
388 delete_option( 'shariff3uu_design' );
389 $shariff3uu_design = array_filter( $shariff3uu_design );
390 update_option( 'shariff3uu_design', $shariff3uu_design );
391 // Advanced.
392 delete_option( 'shariff3uu_advanced' );
393 $shariff3uu_advanced = array_filter( $shariff3uu_advanced );
394 update_option( 'shariff3uu_advanced', $shariff3uu_advanced );
395 // Statistic.
396 delete_option( 'shariff3uu_statistic' );
397 $shariff3uu_statistic = array_filter( $shariff3uu_statistic );
398 update_option( 'shariff3uu_statistic', $shariff3uu_statistic );
399
400 // Remove old settings.
401 delete_option( 'shariff3UU_mailform' );
402 delete_option( 'shariff3UU_hide_update_notice' );
403
404 // Remove Shariff cron job and add it again, if wanted.
405 wp_clear_scheduled_hook( 'shariff3uu_fill_cache' );
406 do_action( 'shariff3uu_save_statistic_options' );
407