Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
4 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| WPCOM_Backup | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| is_modernized | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| hides_menu_entry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| filter_jetpack_backup_dashboard | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- Feature entry file, named after the feature, also holds the WPCOM_Backup bootstrap class. |
| 2 | /** |
| 3 | * An in-wp-admin Backup page for WordPress.com Simple and WoA sites. |
| 4 | * Prompts for a plan upgrade or activation of backups. |
| 5 | * |
| 6 | * @package automattic/jetpack-mu-wpcom |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom; |
| 10 | |
| 11 | require_once __DIR__ . '/../wpcom-hosting-feature-page/class-wpcom-hosting-feature-page.php'; |
| 12 | |
| 13 | /** |
| 14 | * Registers the Backup admin page and its wp-build assets. |
| 15 | */ |
| 16 | class WPCOM_Backup extends WPCOM_Hosting_Feature_Page { |
| 17 | |
| 18 | /** |
| 19 | * Matches Jetpack_Backup::JETPACK_BACKUP_SLUG, which the Jetpack plugin takes over once |
| 20 | * backups are live. |
| 21 | */ |
| 22 | const MENU_SLUG = 'jetpack-backup'; |
| 23 | |
| 24 | /** |
| 25 | * Filter that switches Backup to wp-admin, shared with the Backup package's dashboard. |
| 26 | */ |
| 27 | const MODERNIZATION_FILTER = 'rsm_jetpack_ui_modernization_backup'; |
| 28 | |
| 29 | /** |
| 30 | * Blog sticker that puts a site back on the legacy Backup experience, shared with the Backup package. |
| 31 | */ |
| 32 | const LEGACY_DASHBOARD_STICKER = 'use-backup-legacy-dashboard'; |
| 33 | |
| 34 | /** |
| 35 | * As declared in routes/wpcom-backup/package.json. |
| 36 | */ |
| 37 | const WP_BUILD_PAGE = 'wpcom-backup'; |
| 38 | |
| 39 | /** |
| 40 | * Product name, do not translate. |
| 41 | */ |
| 42 | const PAGE_TITLE = 'Jetpack VaultPress Backup'; |
| 43 | |
| 44 | /** |
| 45 | * Product name, do not translate. |
| 46 | */ |
| 47 | const MENU_TITLE = 'Backup'; |
| 48 | |
| 49 | /** |
| 50 | * Self-serve backups. |
| 51 | */ |
| 52 | const FEATURE = 'BACKUPS_SELF_SERVE'; |
| 53 | |
| 54 | /** |
| 55 | * Whether Backup opens in wp-admin rather than Calypso. |
| 56 | * |
| 57 | * Defaults on unless the site has the legacy dashboard sticker, like the Backup package's dashboard. |
| 58 | * |
| 59 | * @return bool |
| 60 | */ |
| 61 | public static function is_modernized() { |
| 62 | $has_legacy_sticker = wpcom_has_blog_sticker( self::LEGACY_DASHBOARD_STICKER, get_wpcom_blog_id() ); |
| 63 | |
| 64 | return (bool) apply_filters( self::MODERNIZATION_FILTER, ! $has_legacy_sticker ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Left to wpcom_add_jetpack_submenu(), which hides the entry only where it links Calypso's Backup instead. |
| 69 | * |
| 70 | * @return bool |
| 71 | */ |
| 72 | public static function hides_menu_entry() { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Keep the Jetpack plugin's Backup dashboard off a WoA site whose plan lacks backups. |
| 78 | * |
| 79 | * Otherwise it claims the slug first and this page's upgrade prompt steps aside. |
| 80 | * |
| 81 | * @param bool $enabled Whether the Jetpack plugin offers its Backup dashboard. |
| 82 | * @return bool |
| 83 | */ |
| 84 | public static function filter_jetpack_backup_dashboard( $enabled ) { |
| 85 | return $enabled && self::has_feature(); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | add_action( 'init', array( WPCOM_Backup::class, 'init' ) ); |