PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.0.2
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.0.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Upgrades / UserMeta_2.php

UserMeta_2.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.0.2, at classes/Upgrades/UserMeta_2.php

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Content Control Migrations
4 *
5 * @package ContentControl\Plugin
6 */
7
8 namespace ContentControl\Upgrades;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use function ContentControl\plugin;
13
14 /**
15 * User meta v2 migration.
16 */
17 class UserMeta_2 extends \ContentControl\Base\Upgrade {
18
19 const TYPE = 'user_meta';
20 const VERSION = 2;
21
22 /**
23 * Get the label for the upgrade.
24 *
25 * @return string
26 */
27 public function label() {
28 return __( 'Migrate user meta', 'content-control' );
29 }
30
31 /**
32 * Run the migration.
33 *
34 * @return void|WP_Error|false
35 */
36 public function run() {
37 global $wpdb;
38
39 // Gets a stream or mock stream for sending events.
40 $stream = $this->stream();
41
42 $stream->start_task( __( 'Migrating user meta', 'content-control' ) );
43
44 $remapped_keys = [
45 '_jp_cc_reviews_already_did' => 'content_control_reviews_already_did',
46 '_jp_cc_reviews_dismissed_triggers' => 'content_control_reviews_dismissed_triggers',
47 '_jp_cc_reviews_last_dismissed' => 'content_control_reviews_last_dismissed',
48 ];
49
50 // Update all keys via $wpdb.
51 foreach ( $remapped_keys as $old_key => $new_key ) {
52 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery
53 $wpdb->query(
54 $wpdb->prepare(
55 "UPDATE {$wpdb->usermeta} SET meta_key = %s WHERE meta_key = %s",
56 $new_key,
57 $old_key
58 )
59 );
60 }
61
62 $stream->complete_task( __( 'User meta migrated', 'content-control' ) );
63 }
64 }
65