PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.3.2
Admin Columns v4.3.2
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Plugin / Update / V3005.php
codepress-admin-columns / classes / Plugin / Update Last commit date
V3005.php 5 years ago V3007.php 5 years ago V3201.php 5 years ago V4000.php 5 years ago
V3005.php
125 lines
1 <?php
2
3 namespace AC\Plugin\Update;
4
5 use AC\Plugin\Update;
6
7 class V3005 extends Update {
8
9 public function apply_update() {
10 $this->migrate_user_specific_settings();
11 $this->delete_deprecated_settings();
12 $this->delete_deprecated_options();
13 }
14
15 protected function set_version() {
16 $this->version = '3.0.5';
17 }
18
19 /**
20 * @param string $key
21 *
22 * @return bool
23 */
24 private function validate_key( $key ) {
25 if ( empty( $key ) ) {
26 return false;
27 }
28
29 if ( ! is_string( $key ) ) {
30 return false;
31 }
32
33 if ( strlen( $key ) < 10 ) {
34 return false;
35 }
36
37 return true;
38 }
39
40 /**
41 * @param string $key
42 *
43 * @return array
44 */
45 private function get_meta( $key ) {
46 global $wpdb;
47
48 if ( ! $this->validate_key( $key ) ) {
49 return [];
50 }
51
52 $sql = $wpdb->prepare( "
53 SELECT *
54 FROM {$wpdb->usermeta}
55 WHERE meta_key LIKE %s
56 ORDER BY user_id ASC
57 ", $key );
58
59 $results = $wpdb->get_results( $sql );
60
61 if ( ! $results ) {
62 return [];
63 }
64
65 return $results;
66 }
67
68 /**
69 * Migrate USER specific preferences
70 */
71 private function migrate_user_specific_settings() {
72 global $wpdb;
73
74 $mapping = [
75 'cpac-hide-install-addons-notice' => 'ac_hide_notice_addons',
76 'cpac-hide-review-notice' => 'ac_hide_notice_review',
77 ];
78
79 foreach ( $mapping as $current => $new ) {
80 $sql_meta_key = $wpdb->esc_like( $current ) . '%';
81
82 foreach ( $this->get_meta( $sql_meta_key ) as $row ) {
83 update_user_meta( $row->user_id, $new, $row->meta_value );
84 }
85
86 $this->delete( $current );
87 }
88 }
89
90 /**
91 * Preference to be REMOVED
92 */
93 private function delete_deprecated_settings() {
94 $this->delete( 'cpac_current_model' );
95 $this->delete( 'cpac-install-timestamp' );
96 }
97
98 private function delete_deprecated_options() {
99 delete_option( 'cpac_version' );
100 delete_option( 'cpac_version_prev' );
101 delete_option( 'cpac-install-timestamp' );
102 }
103
104 /**
105 * Remove meta data
106 *
107 * @param string $key
108 */
109 private function delete( $key ) {
110 global $wpdb;
111
112 if ( ! $this->validate_key( $key ) ) {
113 return;
114 }
115
116 $sql = $wpdb->prepare( "
117 DELETE
118 FROM {$wpdb->usermeta}
119 WHERE meta_key LIKE %s
120 ", $wpdb->esc_like( $key ) . '%' );
121
122 $wpdb->query( $sql );
123 }
124
125 }