| @@ -1,0 +1,75 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Handles VaultPress->Rewind transition by deactivating VaultPress when needed. | |
| 4 | + * | |
| 5 | + * @package automattic/jetpack | |
| 6 | + */ | |
| 7 | + | |
| 8 | +use Automattic\Jetpack\Redirect; | |
| 9 | + | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Notify user that VaultPress has been disabled. Hide VaultPress notice that requested attention. | |
| 16 | + * | |
| 17 | + * @since 5.8 | |
| 18 | + */ | |
| 19 | +function jetpack_vaultpress_rewind_enabled_notice() { | |
| 20 | + // The deactivation is performed here because there may be pages that admin_init runs on, | |
| 21 | + // such as admin_ajax, that could deactivate the plugin without showing this notification. | |
| 22 | + deactivate_plugins( 'vaultpress/vaultpress.php' ); | |
| 23 | + | |
| 24 | + // Remove WP core notice that says that the plugin was activated. | |
| 25 | + unset( $_GET['activate'] ); | |
| 26 | + $message = sprintf( | |
| 27 | + wp_kses( | |
| 28 | + /* Translators: variable is the full URL to the new dashboard */ | |
| 29 | + __( '<p style="margin-bottom: 0.25em;"><strong>Jetpack is now handling your backups.</strong></p><p>VaultPress is no longer needed and has been deactivated. You can access your backups at <a href="%s" target="_blank" rel="noopener noreferrer">this dashboard</a>.</p>', 'jetpack' ), | |
| 30 | + array( | |
| 31 | + 'a' => array( | |
| 32 | + 'href' => array(), | |
| 33 | + 'target' => array(), | |
| 34 | + 'rel' => array(), | |
| 35 | + ), | |
| 36 | + 'p' => array( | |
| 37 | + 'style' => array(), | |
| 38 | + ), | |
| 39 | + 'strong' => array(), | |
| 40 | + ) | |
| 41 | + ), | |
| 42 | + esc_url( Redirect::get_url( 'calypso-backups' ) ) | |
| 43 | + ); | |
| 44 | + wp_admin_notice( | |
| 45 | + $message, | |
| 46 | + array( | |
| 47 | + 'type' => 'success', | |
| 48 | + 'dismissible' => true, | |
| 49 | + 'additional_classes' => array( 'vp-deactivated' ), | |
| 50 | + 'paragraph_wrap' => false, | |
| 51 | + ) | |
| 52 | + ); | |
| 53 | + ?> | |
| 54 | + <style>#vp-notice{display:none;}</style> | |
| 55 | + <?php | |
| 56 | +} | |
| 57 | + | |
| 58 | +/** | |
| 59 | + * If Backup & Scan is enabled, remove its entry in sidebar, deactivate VaultPress, and show a notification. | |
| 60 | + * | |
| 61 | + * @since 5.8 | |
| 62 | + */ | |
| 63 | +function jetpack_vaultpress_rewind_check() { | |
| 64 | + if ( | |
| 65 | + Jetpack::is_connection_ready() && | |
| 66 | + Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) && | |
| 67 | + Jetpack::is_rewind_enabled() | |
| 68 | + ) { | |
| 69 | + remove_submenu_page( 'jetpack', 'vaultpress' ); | |
| 70 | + | |
| 71 | + add_action( 'admin_notices', 'jetpack_vaultpress_rewind_enabled_notice' ); | |
| 72 | + } | |
| 73 | +} | |
| 74 | + | |
| 75 | +add_action( 'admin_init', 'jetpack_vaultpress_rewind_check', 11 ); | |