Skip to content

Untangling: Replace Calypso stats menu w WP-Admin version #44524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Change the link of the Stats menu to point to the WP-Admin version


Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Subscribers_Dashboard\Dashboard as Subscribers_Dashboard;

require_once __DIR__ . '/../../common/wpcom-callout.php';
Expand Down Expand Up @@ -97,6 +98,28 @@ function wpcom_add_my_home_menu() {
}
add_action( 'admin_menu', 'wpcom_add_my_home_menu' );

/**
* Add the top menu item for the "Stats".
*
* @return void
*/
function wpcom_add_stats_menu() {
$host = new Host();

/**
* If the site is Atomic and the module is disabled, the page doesn't exist.
*/
// @phan-suppress-next-line PhanUndeclaredClassMethod -- We need to suppress it for WordPress.com tests.
if ( $host->is_atomic_platform() && ! Jetpack::is_module_active( 'stats' ) ) {
return;
}

// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_menu_page( __( 'Stats', 'jetpack-mu-wpcom' ), __( 'Stats', 'jetpack-mu-wpcom' ), 'view_stats', 'admin.php?page=stats', null, 'dashicons-chart-bar', 3 );
}

add_action( 'admin_menu', 'wpcom_add_stats_menu' );

/**
* Adds a Hosting menu.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Change the link of the Stats menu to point to the WP-Admin version


Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function __construct() {
public function reregister_menu_items() {
// Remove separators.
remove_menu_page( 'separator1' );
$this->add_stats_menu();
$this->add_upgrades_menu();
$this->add_posts_menu();
$this->add_media_menu();
Expand Down Expand Up @@ -117,14 +116,6 @@ public function add_my_mailboxes_menu() {
add_menu_page( __( 'My Mailboxes', 'jetpack-masterbar' ), __( 'My Mailboxes', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/mailboxes/' . $this->domain, null, 'dashicons-email', 4.64424 );
}

/**
* Adds Stats menu.
*/
public function add_stats_menu() {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_menu_page( __( 'Stats', 'jetpack-masterbar' ), __( 'Stats', 'jetpack-masterbar' ), 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
}

/**
* Adds Upgrades menu.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,6 @@ public function add_jetpack_menu() {
}
}

/**
* Adds Stats menu.
*/
public function add_stats_menu() {
$menu_title = __( 'Stats', 'jetpack-masterbar' );
if (
! $this->is_api_request &&
( new Modules() )->is_active( 'stats' ) &&
function_exists( 'stats_get_image_chart_src' )
) {
$img_src = esc_attr(
stats_get_image_chart_src( 'admin-bar-hours-scale-2x', array( 'masterbar' => '' ) )
);
$alt = esc_attr__( 'Hourly views', 'jetpack-masterbar' );

$menu_title .= "<img class='sidebar-unified__sparkline' src='$img_src' width='80' height='20' alt='$alt'>";
}

// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_menu_page( __( 'Stats', 'jetpack-masterbar' ), $menu_title, 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
}

/**
* Adds Upgrades menu.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function reregister_menu_items() {

parent::reregister_menu_items();

$this->add_stats_menu();
$this->add_feedback_menu();
$this->add_cpt_menus();
$this->add_wp_admin_menu();
Expand Down Expand Up @@ -81,6 +82,14 @@ public function get_cpt_menu_link( $ptype_obj ) {
}
}

/**
* Adds Stats menu.
*/
public function add_stats_menu() {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_menu_page( __( 'Stats', 'jetpack-masterbar' ), __( 'Stats', 'jetpack-masterbar' ), 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
}

/**
* Adds Posts menu.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,6 @@ public function get_upsell_nudge() {
}
}

/**
* Adds Stats menu.
*/
public function add_stats_menu() {
$menu_title = __( 'Stats', 'jetpack-masterbar' );

if ( ! $this->is_api_request ) {
$menu_title .= sprintf(
'<img class="sidebar-unified__sparkline" width="80" height="20" src="%1$s" alt="%2$s">',
esc_url( site_url( 'wp-includes/charts/admin-bar-hours-scale-2x.php?masterbar=1&s=' . get_current_blog_id() ) ),
esc_attr__( 'Hourly views', 'jetpack-masterbar' )
);
}

// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_menu_page( __( 'Stats', 'jetpack-masterbar' ), $menu_title, 'read', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
}

/**
* Gets the current plan and stores it in $this->current_plan so the database is only called once per request.
*
Expand Down
19 changes: 1 addition & 18 deletions projects/packages/masterbar/tests/php/Admin_Menu_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function test_admin_menu_output() {

static::$admin_menu->reregister_menu_items();

$this->assertCount( 18, $menu, 'Admin menu should not have unexpected top menu items.' );
$this->assertCount( 17, $menu, 'Admin menu should not have unexpected top menu items.' );

$this->assertEquals( static::$submenu_data[''], $submenu[''], 'Submenu items without parent should stay the same.' );
}
Expand All @@ -120,23 +120,6 @@ public function test_get_preferred_view() {
$this->assertSame( 'default', static::$admin_menu->get_preferred_view( 'options-general.php' ) );
}

/**
* Tests add_stats_menu
*/
public function test_add_stats_menu() {
global $menu;

static::$admin_menu->add_stats_menu();
// Ignore position keys, since the key used for the Stats menu contains a pseudorandom number
// that we shouldn't hardcode. The only thing that matters is that the menu should be in the
// 3rd position regardless of the key.
// @see https://core.trac.wordpress.org/ticket/40927
ksort( $menu );
$menu_items = array_values( $menu );

$this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[2][2] );
}

/**
* Tests add_upgrades_menu
*/
Expand Down
Loading