| 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 |
|