Skip to content

Commit

Permalink
Admin menu: Replace Jetpack Cloud links with WordPress.com links (#39393
Browse files Browse the repository at this point in the history
)

* Admin menu: Replace Jetpack Cloud links with WordPress.com links

* Add link to PR

* Suppress Phan errors in current line

* Move domain var below

* Remove quite param
  • Loading branch information
mmtr committed Sep 17, 2024
1 parent 016d8b3 commit 70d1104
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Admin menu: Replace Jetpack cloud links with WordPress.com links
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,6 @@ private function is_valid_admin_url_or_absolute_path( $input ) {
return true;
}

// Allow Jetpack Cloud URLs.
if ( strpos( $input, 'https://cloud.jetpack.com' ) === 0 ) {
return true;
}

// Checks if the string is URL starting with the admin URL.
if ( strpos( $input, admin_url() ) === 0 ) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ function wpcom_launchpad_should_use_wp_admin_link() {
return get_option( 'wpcom_admin_interface' ) === 'wp-admin';
}

/**
* Returns whether the task link should point to Jetpack Cloud page
* instead of Calypso page.
*
* @return bool
*/
function wpcom_launchpad_should_use_jetpack_cloud_link() {
return get_option( 'wpcom_admin_interface' ) === 'wp-admin';
}

/**
* Get the task definitions for the Launchpad.
*
Expand Down Expand Up @@ -258,9 +248,6 @@ function wpcom_launchpad_get_task_definitions() {
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => 'wpcom_launchpad_has_goal_import_subscribers',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/subscribers/' . $data['site_slug_encoded'] . '#add-subscribers';
}
return '/subscribers/' . $data['site_slug_encoded'] . '#add-subscribers';
},
),
Expand Down Expand Up @@ -526,9 +513,6 @@ function wpcom_launchpad_get_task_definitions() {
'target_repetitions' => 10,
'repetition_count_callback' => 'wpcom_launchpad_get_newsletter_subscriber_count',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/subscribers/' . $data['site_slug_encoded'];
}
return '/subscribers/' . $data['site_slug_encoded'];
},
),
Expand All @@ -552,9 +536,6 @@ function wpcom_launchpad_get_task_definitions() {
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => 'wpcom_launchpad_has_goal_import_subscribers',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/subscribers/' . $data['site_slug_encoded'];
}
return '/subscribers/' . $data['site_slug_encoded'];
},
),
Expand Down Expand Up @@ -606,9 +587,6 @@ function wpcom_launchpad_get_task_definitions() {
'earn-launchpad'
);
}
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/monetize/payments/' . $data['site_slug_encoded'];
}
return '/earn/payments/' . $data['site_slug_encoded'];
},
),
Expand All @@ -619,9 +597,6 @@ function wpcom_launchpad_get_task_definitions() {
'is_complete_callback' => 'wpcom_launchpad_has_paid_membership_plans',
'is_visible_callback' => '__return_true',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/monetize/payments/' . $data['site_slug_encoded'] . '#add-new-payment-plan';
}
return '/earn/payments/' . $data['site_slug_encoded'] . '#add-new-payment-plan';
},
),
Expand Down Expand Up @@ -677,9 +652,6 @@ function wpcom_launchpad_get_task_definitions() {
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => '__return_true',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( wpcom_launchpad_should_use_jetpack_cloud_link() ) {
return 'https://cloud.jetpack.com/subscribers/' . $data['site_slug_encoded'] . '#add-subscribers';
}
return '/subscribers/' . $data['site_slug_encoded'] . '#add-subscribers';
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;

/**
* Checks if the current user has a WordPress.com account connected.
Expand Down Expand Up @@ -148,31 +147,142 @@ function wpcom_add_hosting_menu() {
* Adds WordPress.com submenu items related to Jetpack under the Jetpack admin menu.
*/
function wpcom_add_jetpack_submenu() {
/*
* Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled).
* They already get a menu item under Users via nav-unification.
*/
if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
$is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
$is_atomic_site = ! $is_simple_site;
$uses_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';

if ( ! $uses_wp_admin_interface ) {
return;
}

if ( $is_atomic_site && ( ( new Status() )->is_offline_mode() || ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ) ) {
return;
}

/*
* Do not display if we're in Offline mode, or if the user is not connected.
*/
if ( ( new Status() )->is_offline_mode() || ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ) {
$blog_id = Connection_Manager::get_site_id();
if ( is_wp_error( $blog_id ) ) {
return;
}

// Hide submenu items that link to Jetpack Cloud.
wpcom_hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'cloud-activity-log-wp-menu', array( 'site' => $blog_id ) ) ) );
wpcom_hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ) );
wpcom_hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-backups' ) ) );
wpcom_hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'jetpack-menu-jetpack-manage-subscribers', array( 'site' => $blog_id ) ) ) );

$domain = wp_parse_url( home_url(), PHP_URL_HOST );
$activity_log_url = 'https://wordpress.com/activity-log/' . $domain;
$vaultpress_url = 'https://wordpress.com/backup/' . $domain;
$monetize_url = 'https://wordpress.com/earn/' . $domain;
$subscribers_url = 'https://wordpress.com/subscribers/' . $domain;
$newsletter_url = 'https://wordpress.com/settings/newsletter/' . $domain;
$scan_url = 'https://wordpress.com/scan/history/' . $domain;

// Add submenu items that link to WordPress.com.
add_submenu_page(
'jetpack',
__( 'Activity Log', 'jetpack-mu-wpcom' ),
__( 'Activity Log', 'jetpack-mu-wpcom' ),
'manage_options',
$activity_log_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);

add_submenu_page(
'jetpack',
__( 'VaultPress', 'jetpack-mu-wpcom' ),
__( 'VaultPress', 'jetpack-mu-wpcom' ),
'manage_options',
$vaultpress_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);

add_submenu_page(
'jetpack',
__( 'Monetize', 'jetpack-mu-wpcom' ),
__( 'Monetize', 'jetpack-mu-wpcom' ) . ' <span class="dashicons dashicons-external"></span>',
__( 'Monetize', 'jetpack-mu-wpcom' ),
'manage_options',
esc_url( Redirect::get_url( 'calypso-monetize' ) ),
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal
$monetize_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);

if ( $is_atomic_site ) {
add_submenu_page(
'jetpack',
__( 'Scan', 'jetpack-mu-wpcom' ),
__( 'Scan', 'jetpack-mu-wpcom' ),
'manage_options',
$scan_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);
}

add_submenu_page(
'jetpack',
__( 'Subscribers', 'jetpack-mu-wpcom' ),
__( 'Subscribers', 'jetpack-mu-wpcom' ),
'manage_options',
$subscribers_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);

if ( $is_simple_site ) {
add_submenu_page(
'jetpack',
__( 'Newsletter', 'jetpack-mu-wpcom' ),
__( 'Newsletter', 'jetpack-mu-wpcom' ),
'manage_options',
$newsletter_url,
null // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
);
}

// Re-order menu.
global $submenu;
if ( ! isset( $submenu['jetpack'] ) ) {
return;
}

$desired_order = array(
'my-jetpack',
'stats',
$activity_log_url,
$vaultpress_url,
'akismet-key-config',
'jetpack-search',
$scan_url,
$monetize_url,
$subscribers_url,
);
$ordered_submenu = array();

// Re-add submenu items in the desired order.
foreach ( $desired_order as $slug ) {
foreach ( $submenu['jetpack'] as $item ) {
if ( $item[2] === $slug ) {
$ordered_submenu[] = $item;
}
}
}

// Add any remaining submenu items.
foreach ( $submenu['jetpack'] as $item ) {
if ( ! in_array( $item[2], $desired_order, true ) ) {
$ordered_submenu[] = $item;
}
}

// phpcs:ignore WordPress.WP.GlobalVariablesOverride
$submenu['jetpack'] = $ordered_submenu;
}
add_action( 'jetpack_admin_menu', 'wpcom_add_jetpack_submenu' );
add_action( 'admin_menu', 'wpcom_add_jetpack_submenu', 999999 );

/*
* Prevents the Jetpack menu from being overridden on Simple sites.
*
* TODO: After deploying https://github.com/Automattic/jetpack/pull/39393, we can remove the `add_jetpack_submenu` function and this `remove_action` call.
*/
remove_action( 'admin_menu', 'add_jetpack_submenu', 999999 );

/**
* Ensures customizer menu and admin bar items are not visible on a block theme.
Expand Down

0 comments on commit 70d1104

Please sign in to comment.