PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 7.0
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v7.0
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Update / UpdateDB.php

UpdateDB.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 7.0, at classes/Update/UpdateDB.php

87 lines 2.4 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 FloatingButton
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 FloatingButton\Update;
17
18 use FloatingButton\Admin\DBManager;
19 use FloatingButton\WOWP_Plugin;
20
21 class UpdateDB {
22
23 public static function init(): void {
24 $current_db_version = get_site_option( WOWP_Plugin::PREFIX . '_db_version' );
25
26 if ( $current_db_version && version_compare( $current_db_version, '7.0', '>=' ) ) {
27 return;
28 }
29
30 self::start_update();
31
32 update_site_option( WOWP_Plugin::PREFIX . '_db_version', '7.0' );
33 }
34
35 public static function start_update(): void {
36 self::update_fields();
37 }
38
39 public static function update_fields(): void {
40 $results = DBManager::get_all_data();
41
42 if ( empty( $results ) || ! is_array( $results ) ) {
43 return;
44 }
45 foreach ( $results as $result ) {
46 $param = maybe_unserialize( $result->param );
47
48 $param = self::update_param( $param );
49
50 $data = [
51 'param' => maybe_serialize( $param ),
52 ];
53
54 $where = [ 'id' => $result->id ];
55
56 $data_formats = [ '%s' ];
57
58 DBManager::update( $data, $where, $data_formats );
59 }
60 }
61
62 public static function update_param( $param ) {
63 $param['mobile_on'] = ! empty( $param['include_mobile'] ) ? 1 : 0;
64 $param['mobile'] = ! empty( $param['screen'] ) ? $param['screen'] : '480';
65
66 $param['desktop_on'] = ! empty( $param['include_mobile'] ) ? 1 : 0;
67 $param['desktop'] = ! empty( $param['screen_more'] ) ? $param['screen_more'] : '1024';
68
69
70 $param['language_on'] = ! empty( $param['depending_language'] ) ? 1 : 0;
71 $param['language'] = ! empty( $param['screen_more'] ) ? $param['lang'] : '';
72
73 $param['users'] = ! empty( $param['item_user'] ) ? $param['item_user'] : 1;
74
75 $param['browser_opera'] = ! empty( $param['browsers']['opera'] ) ? 1 : 0;
76 $param['browser_edge'] = ! empty( $param['browsers']['edge'] ) ? 1 : 0;
77 $param['browser_chrome'] = ! empty( $param['browsers']['chrome'] ) ? 1 : 0;
78 $param['browser_safari'] = ! empty( $param['browsers']['safari'] ) ? 1 : 0;
79 $param['browser_firefox'] = ! empty( $param['browsers']['firefox'] ) ? 1 : 0;
80 $param['browser_ie'] = ! empty( $param['browsers']['ie'] ) ? 1 : 0;
81 $param['browser_other'] = ! empty( $param['browsers']['other'] ) ? 1 : 0;
82
83
84 return $param;
85 }
86
87 }