From 4c794c98cd212c0b65b400e6ee4187dbb9cd2d9f Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Thu, 13 Aug 2026 15:32:12 +0800 Subject: [PATCH] fix: hide the Shares widget outside WPCOM Simple, where shares are never counted --- .../changelog/wooa7s-1720-shares-simple-only | 4 +++ .../src/widget-type-support.php | 7 +++++ .../tests/php/Dashboard_Layout_Test.php | 22 +++++++++++++ .../tests/php/Widget_Availability_Test.php | 31 ++++++++++++++++--- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 projects/packages/premium-analytics/changelog/wooa7s-1720-shares-simple-only diff --git a/projects/packages/premium-analytics/changelog/wooa7s-1720-shares-simple-only b/projects/packages/premium-analytics/changelog/wooa7s-1720-shares-simple-only new file mode 100644 index 000000000000..2190b48dace3 --- /dev/null +++ b/projects/packages/premium-analytics/changelog/wooa7s-1720-shares-simple-only @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Shares: Hide the widget outside WPCOM Simple, where share counts are never recorded. diff --git a/projects/packages/premium-analytics/src/widget-type-support.php b/projects/packages/premium-analytics/src/widget-type-support.php index 23678d84bfd4..ab2c1457ca96 100644 --- a/projects/packages/premium-analytics/src/widget-type-support.php +++ b/projects/packages/premium-analytics/src/widget-type-support.php @@ -36,6 +36,13 @@ function get_unsupported_widget_types( $context ) { // the same boundary, which excludes self-hosted Jetpack and Atomic sites. if ( ! $context['is_wpcom_simple'] ) { $unsupported[] = 'jpa/file-downloads'; + + // Share counts are recorded when the share request is processed, which + // only happens on WPCOM Simple. Elsewhere the button click is handled by + // the site itself and never reaches the counter, so the site summary's + // `shares_` fields stay at zero however much the content is + // shared. Calypso excludes the module on the same grounds. + $unsupported[] = 'jpa/shares'; } return $unsupported; diff --git a/projects/packages/premium-analytics/tests/php/Dashboard_Layout_Test.php b/projects/packages/premium-analytics/tests/php/Dashboard_Layout_Test.php index 7e35a7dc6ff8..8ae635291d48 100644 --- a/projects/packages/premium-analytics/tests/php/Dashboard_Layout_Test.php +++ b/projects/packages/premium-analytics/tests/php/Dashboard_Layout_Test.php @@ -209,6 +209,28 @@ public function test_traffic_default_keeps_simple_only_widgets_on_wpcom_simple() $this->assertContains( 'jpa/file-downloads', $layout_types ); } + /** + * Shares is Simple-only too, so the Insights default drops it on self-hosted + * Jetpack sites (this test env). + */ + public function test_insights_default_excludes_shares_on_self_hosted() { + $layout_types = array_column( get_dashboard_default_layout_for( DASHBOARD_INSIGHTS_SECTION_ID ), 'type' ); + + $this->assertNotContains( 'jpa/shares', $layout_types, 'Simple-only widget instances must not be part of the default layout on self-hosted sites.' ); + $this->assertContains( 'jpa/tags', $layout_types, 'Regular widget instances remain in the default layout.' ); + } + + /** + * WPCOM Simple keeps Shares in the Insights default. + */ + public function test_insights_default_keeps_shares_on_wpcom_simple() { + Constants::set_constant( 'IS_WPCOM', true ); + + $layout_types = array_column( get_dashboard_default_layout_for( DASHBOARD_INSIGHTS_SECTION_ID ), 'type' ); + + $this->assertContains( 'jpa/shares', $layout_types ); + } + /** * Traffic section aliases resolve to the same default layout. */ diff --git a/projects/packages/premium-analytics/tests/php/Widget_Availability_Test.php b/projects/packages/premium-analytics/tests/php/Widget_Availability_Test.php index ca5f0bbee8e1..57d0feb60873 100644 --- a/projects/packages/premium-analytics/tests/php/Widget_Availability_Test.php +++ b/projects/packages/premium-analytics/tests/php/Widget_Availability_Test.php @@ -66,6 +66,10 @@ private function widget_candidates() { 'name' => 'jpa/file-downloads', 'category' => 'traffic', ), + array( + 'name' => 'jpa/shares', + 'category' => 'traffic', + ), array( 'name' => 'jpa/hello-world', 'category' => 'demo', @@ -155,6 +159,23 @@ public function test_type_policy_keeps_file_downloads_on_simple() { $this->assertContains( 'jpa/file-downloads', $this->available_names( true ) ); } + /** + * Shares is unavailable outside WPCOM Simple, where nothing records a share. + */ + public function test_type_policy_removes_shares_on_non_simple() { + $names = $this->available_names( false ); + + $this->assertNotContains( 'jpa/shares', $names ); + $this->assertContains( 'jpa/hello-world', $names ); + } + + /** + * WPCOM Simple keeps Shares. + */ + public function test_type_policy_keeps_shares_on_simple() { + $this->assertContains( 'jpa/shares', $this->available_names( true ) ); + } + /** * Non-array records pass through unchanged. */ @@ -362,9 +383,9 @@ public function test_uncategorized_widgets_are_not_capability_gated() { } /** - * The host callback removes File downloads on Atomic. + * The host callback removes the Simple-only types on Atomic. */ - public function test_registry_callback_removes_file_downloads_on_atomic() { + public function test_registry_callback_removes_simple_only_types_on_atomic() { Constants::set_constant( 'ATOMIC_SITE_ID', 123 ); Constants::set_constant( 'ATOMIC_CLIENT_ID', 456 ); @@ -374,12 +395,13 @@ public function test_registry_callback_removes_file_downloads_on_atomic() { ); $this->assertNotContains( 'jpa/file-downloads', $names ); + $this->assertNotContains( 'jpa/shares', $names ); } /** - * The host callback keeps File downloads on WPCOM Simple. + * The host callback keeps the Simple-only types on WPCOM Simple. */ - public function test_registry_callback_keeps_file_downloads_on_wpcom_simple() { + public function test_registry_callback_keeps_simple_only_types_on_wpcom_simple() { Constants::set_constant( 'IS_WPCOM', true ); $names = array_column( @@ -388,6 +410,7 @@ public function test_registry_callback_keeps_file_downloads_on_wpcom_simple() { ); $this->assertContains( 'jpa/file-downloads', $names ); + $this->assertContains( 'jpa/shares', $names ); } /**