AbstractMigration.php
5 years ago
DateTimeUtils.php
5 years ago
Debugging.php
5 years ago
GenerateModal.php
5 years ago
Migration.php
5 years ago
UserUtils.php
5 years ago
Migration.php
87 lines
| 1 | <?php |
| 2 | namespace WP2FA\Utils; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
| 5 | |
| 6 | /** |
| 7 | * Migration class |
| 8 | */ |
| 9 | if ( ! class_exists( '\WP2FA\Utils\Migration' ) ) { |
| 10 | |
| 11 | /** |
| 12 | * Put all you migration methods here |
| 13 | * |
| 14 | * @package WP2FA\Utils |
| 15 | * @since 1.6 |
| 16 | */ |
| 17 | class Migration extends AbstractMigration { |
| 18 | |
| 19 | /** |
| 20 | * The name of the option from which we should extact version |
| 21 | * Note: version is expected in version format - 1.0.0; 1; 1.0; 1.0.0.0 |
| 22 | * Note: only numbers will be processed |
| 23 | */ |
| 24 | protected static $versionOptionName = 'wp_2fa_plugin_version'; |
| 25 | |
| 26 | /** |
| 27 | * The constant name where the plugin version is stored |
| 28 | * Note: version is expected in version format - 1.0.0; 1; 1.0; 1.0.0.0 |
| 29 | * Note: only numbers will be processed |
| 30 | */ |
| 31 | protected static $constNameOfPluginVersion = 'WP_2FA_VERSION'; |
| 32 | |
| 33 | /** |
| 34 | * Migration for version upto 1.6.0 |
| 35 | * |
| 36 | * @return void |
| 37 | * @since 1.6.0 |
| 38 | */ |
| 39 | protected static function migrateUpTo_160() { |
| 40 | $settings = get_option( 'wp_2fa_settings' ); |
| 41 | if ( ! is_array( $settings ) ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | $needsUpdate = false; |
| 46 | |
| 47 | $settings_to_convert = [ 'enforced_roles', 'enforced_users', 'excluded_users', 'excluded_roles' ]; |
| 48 | foreach ( $settings_to_convert as $setting_name ) { |
| 49 | if ( array_key_exists( $setting_name, $settings ) && ! is_array( $settings[ $setting_name ] ) ) { |
| 50 | $settings[ $setting_name ] = array_filter( |
| 51 | explode( ',', $settings[ $setting_name ] ) |
| 52 | ); |
| 53 | $needsUpdate = true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if ( ! isset( $settings['backup_codes_enabled'] ) ) { |
| 58 | $settings['backup_codes_enabled'] = 'yes'; |
| 59 | $needsUpdate = true; |
| 60 | } |
| 61 | |
| 62 | if ( $needsUpdate ) { |
| 63 | // Update settings. |
| 64 | update_site_option( 'wp_2fa_settings', $settings ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Migration for version upto 1.5.0 |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | protected static function migrateUpTo_150() { |
| 74 | $settings = get_option( 'wp_2fa_settings' ); |
| 75 | |
| 76 | if ( is_array( $settings ) && array_key_exists( 'enforcment-policy', $settings ) ) { |
| 77 | // Correct setting name. |
| 78 | $settings['enforcement-policy'] = $settings['enforcment-policy']; |
| 79 | // Remove old setting. |
| 80 | unset( $settings['enforcment-policy'] ); |
| 81 | // Update settings. |
| 82 | update_site_option( 'wp_2fa_settings', $settings ); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 |