PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / trunk
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More vtrunk
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 / Settings_2.php

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

83 lines 1.7 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 __;
13 use function ContentControl\update_plugin_option;
14
15 /**
16 * Settings v2 migration.
17 */
18 class Settings_2 extends \ContentControl\Base\Upgrade {
19
20 const TYPE = 'settings';
21 const VERSION = 2;
22
23 /**
24 * Get the label for the upgrade.
25 *
26 * @return string
27 */
28 public function label() {
29 return __( 'Update plugin settings', 'content-control' );
30 }
31
32 /**
33 * Get the dependencies for this upgrade.
34 *
35 * @return string[]
36 */
37 public function get_dependencies() {
38 return [
39 'backup-2',
40 'restrictions-2',
41 ];
42 }
43
44 /**
45 * Run the migration.
46 *
47 * @return void
48 */
49 public function run() {
50 // Gets a stream or mock stream for sending events.
51 $stream = $this->stream();
52
53 $stream->start_task( __( 'Migrating plugin settings', 'content-control' ) );
54
55 $settings = \get_option( 'jp_cc_settings', [] );
56
57 if ( ! is_array( $settings ) ||
58 empty( $settings )
59 ) {
60 $settings = [];
61 }
62
63 $default_denial_message = isset( $settings['default_denial_message'] ) ? $settings['default_denial_message'] : '';
64
65 // For migrations, maintain the old default of not excluding admins.
66 update_plugin_option( 'excludeAdmins', false );
67
68 if ( ! empty( $default_denial_message ) ) {
69 update_plugin_option( 'defaultDenialMessage', $default_denial_message );
70 }
71
72 unset( $settings['default_denial_message'] );
73
74 if ( ! empty( $settings ) ) {
75 \update_option( 'jp_cc_settings', $settings );
76 } else {
77 \delete_option( 'jp_cc_settings' );
78 }
79
80 $stream->complete_task( __( 'Plugin settings migrated', 'content-control' ) );
81 }
82 }
83