Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
12 / 14 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| WPCOM_Backup | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
8 | |
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 | |||
| filter_my_jetpack_feature_upgrade | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| get_plans_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | * Send My Jetpack's Backup upgrade on a WoA site to the WordPress.com plans that include backups. |
| 90 | * |
| 91 | * @param array $upgrade Where the Upgrade button goes. |
| 92 | * @param string $slug The My Jetpack feature slug. |
| 93 | * @param bool $included Whether the site already pays for the feature. |
| 94 | * @return array |
| 95 | */ |
| 96 | public static function filter_my_jetpack_feature_upgrade( $upgrade, $slug, $included ) { |
| 97 | if ( 'backup' !== $slug || $included ) { |
| 98 | return $upgrade; |
| 99 | } |
| 100 | |
| 101 | return array( |
| 102 | 'path' => '', |
| 103 | 'name' => 'WordPress.com Business', // Product name, do not translate. |
| 104 | 'url' => self::get_plans_url( wpcom_get_site_slug() ), |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * The WordPress.com plans page, with Business picked: the lowest plan that includes backups. |
| 110 | * |
| 111 | * @param string $site_slug The site's WordPress.com slug. |
| 112 | * @return string |
| 113 | */ |
| 114 | public static function get_plans_url( $site_slug ) { |
| 115 | return 'https://wordpress.com/plans/' . $site_slug . '?plan=business-bundle'; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | add_action( 'init', array( WPCOM_Backup::class, 'init' ) ); |