Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
12 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Domain_Only_Admin_Menu | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| set_email_subscription_checker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| reregister_menu_items | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Domain-only sites Admin Menu file. |
| 4 | * |
| 5 | * @package automattic/jetpack-masterbar |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Masterbar; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit( 0 ); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Class Domain_Only_Admin_Menu. |
| 16 | */ |
| 17 | class Domain_Only_Admin_Menu extends Base_Admin_Menu { |
| 18 | /** |
| 19 | * The `WPCOM_Email_Subscription_Checker` instance used to verify if a site has an email subscription. |
| 20 | * |
| 21 | * @var WPCOM_Email_Subscription_Checker |
| 22 | */ |
| 23 | private $email_subscriptions_checker; |
| 24 | |
| 25 | /** |
| 26 | * Constructor that lets us pass in a WPCOM_Email_Subscription_Checker dependency. |
| 27 | * |
| 28 | * @param WPCOM_Email_Subscription_Checker $email_subscriptions_checker The WPCOM_Email_Subscription_Checker instance. |
| 29 | */ |
| 30 | protected function __construct( $email_subscriptions_checker = null ) { |
| 31 | parent::__construct(); |
| 32 | |
| 33 | $this->email_subscriptions_checker = $email_subscriptions_checker; |
| 34 | |
| 35 | if ( empty( $this->email_subscriptions_checker ) ) { |
| 36 | $this->set_email_subscription_checker( new WPCOM_Email_Subscription_Checker() ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * This setter lets us inject an WPCOM_Email_Subscription_Checker instance. |
| 42 | * |
| 43 | * @param WPCOM_Email_Subscription_Checker $email_subscriptions_checker An WPCOM_Email_Subscription_Checker instance. |
| 44 | * |
| 45 | * @return void |
| 46 | */ |
| 47 | public function set_email_subscription_checker( $email_subscriptions_checker ) { |
| 48 | $this->email_subscriptions_checker = $email_subscriptions_checker; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Create the desired menu output. |
| 53 | */ |
| 54 | public function reregister_menu_items() { |
| 55 | global $menu, $submenu; |
| 56 | |
| 57 | $menu = array(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 58 | $submenu = array(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 59 | |
| 60 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 61 | add_menu_page( esc_attr__( 'Manage Domain', 'jetpack-masterbar' ), __( 'Manage Domain', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/domains/manage/' . $this->domain . '/edit/' . $this->domain, null, 'dashicons-admin-settings' ); |
| 62 | |
| 63 | if ( $this->email_subscriptions_checker->has_email() ) { |
| 64 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 65 | add_menu_page( esc_attr__( 'Manage Email', 'jetpack-masterbar' ), __( 'Manage Email', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/email/' . $this->domain . '/manage/' . $this->domain, null, 'dashicons-admin-settings' ); |
| 66 | } |
| 67 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 68 | add_menu_page( esc_attr__( 'Manage Purchases', 'jetpack-masterbar' ), __( 'Manage Purchases', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/purchases/subscriptions/' . $this->domain, null, 'dashicons-cart' ); |
| 69 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 70 | add_menu_page( esc_attr__( 'My Mailboxes', 'jetpack-masterbar' ), __( 'My Mailboxes', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/mailboxes/' . $this->domain, null, 'dashicons-email' ); |
| 71 | } |
| 72 | } |