diff --git a/projects/packages/jetpack-mu-wpcom/changelog/agency-managed-check b/projects/packages/jetpack-mu-wpcom/changelog/agency-managed-check
new file mode 100644
index 0000000000000..5032112d7fb44
--- /dev/null
+++ b/projects/packages/jetpack-mu-wpcom/changelog/agency-managed-check
@@ -0,0 +1,4 @@
+Significance: minor
+Type: changed
+
+Hide wpcom features when site is agency-managed or user is local
diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php
index 72900e2db60b1..fed6a758c9f8d 100644
--- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php
+++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php
@@ -28,10 +28,14 @@ public static function init() {
// Shared code for src/features.
require_once self::PKG_DIR . 'src/common/index.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
+ require_once __DIR__ . '/utils.php';
// Load features that don't need any special loading considerations.
add_action( 'plugins_loaded', array( __CLASS__, 'load_features' ) );
+ // Load features that only apply to WordPress.com-connected users.
+ add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_user_features' ) );
+
// Load ETK features that need higher priority than the ETK plugin.
add_action( 'plugins_loaded', array( __CLASS__, 'load_etk_features' ), 0 );
@@ -43,10 +47,6 @@ public static function init() {
add_action( 'plugins_loaded', array( __CLASS__, 'load_coming_soon' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_rest_api_endpoints' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'load_block_theme_previews' ) );
- add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_command_palette' ) );
- add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_admin_interface' ) );
- add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_site_management_widget' ) );
- add_action( 'plugins_loaded', array( __CLASS__, 'load_replace_site_visibility' ) );
// These features run only on simple sites.
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
@@ -81,9 +81,6 @@ public static function init() {
* Load features that don't need any special loading considerations.
*/
public static function load_features() {
- // Shared features.
- require_once __DIR__ . '/features/agency-managed/agency-managed.php';
-
// Please keep the features in alphabetical order.
require_once __DIR__ . '/features/100-year-plan/enhanced-ownership.php';
require_once __DIR__ . '/features/100-year-plan/locked-mode.php';
@@ -94,21 +91,14 @@ public static function load_features() {
require_once __DIR__ . '/features/error-reporting/error-reporting.php';
require_once __DIR__ . '/features/first-posts-stream/first-posts-stream-helpers.php';
require_once __DIR__ . '/features/font-smoothing-antialiased/font-smoothing-antialiased.php';
- // To avoid potential collisions with ETK.
- if ( ! class_exists( 'A8C\FSE\Help_Center' ) ) {
- require_once __DIR__ . '/features/help-center/class-help-center.php';
- }
require_once __DIR__ . '/features/import-customizations/import-customizations.php';
require_once __DIR__ . '/features/marketplace-products-updater/class-marketplace-products-updater.php';
require_once __DIR__ . '/features/media/heif-support.php';
require_once __DIR__ . '/features/site-editor-dashboard-link/site-editor-dashboard-link.php';
require_once __DIR__ . '/features/wpcom-admin-dashboard/wpcom-admin-dashboard.php';
- require_once __DIR__ . '/features/wpcom-admin-bar/wpcom-admin-bar.php';
- require_once __DIR__ . '/features/wpcom-admin-menu/wpcom-admin-menu.php';
require_once __DIR__ . '/features/wpcom-block-editor/class-jetpack-wpcom-block-editor.php';
require_once __DIR__ . '/features/wpcom-block-editor/functions.editor-type.php';
- require_once __DIR__ . '/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php';
- require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php';
+ require_once __DIR__ . '/features/wpcom-themes/wpcom-theme-fixes.php';
require_once __DIR__ . '/features/google-analytics/google-analytics.php';
// Initializers, if needed.
@@ -128,6 +118,30 @@ public static function load_features() {
}
}
+ /**
+ * Load features that only apply to WordPress.com users.
+ */
+ public static function load_wpcom_user_features() {
+ if ( ! is_wpcom_user() ) {
+ require_once __DIR__ . '/features/replace-site-visibility/hide-site-visibility.php';
+
+ return;
+ }
+
+ // To avoid potential collisions with ETK.
+ if ( ! class_exists( 'A8C\FSE\Help_Center' ) ) {
+ require_once __DIR__ . '/features/help-center/class-help-center.php';
+ }
+ require_once __DIR__ . '/features/replace-site-visibility/replace-site-visibility.php';
+ require_once __DIR__ . '/features/wpcom-admin-bar/wpcom-admin-bar.php';
+ require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php';
+ require_once __DIR__ . '/features/wpcom-admin-menu/wpcom-admin-menu.php';
+ require_once __DIR__ . '/features/wpcom-command-palette/wpcom-command-palette.php';
+ require_once __DIR__ . '/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php';
+ require_once __DIR__ . '/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php';
+ require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php';
+ }
+
/**
* Laod ETK features that need higher priority than the ETK plugin.
* Can be moved back to load_features() once the feature no longer exists in the ETK plugin.
@@ -326,18 +340,6 @@ public static function load_verbum_comments_admin() {
new \Automattic\Jetpack\Verbum_Admin();
}
- /**
- * Load WPCOM Command Palette.
- *
- * @return void
- */
- public static function load_wpcom_command_palette() {
- if ( is_agency_managed_site() || ! current_user_has_wpcom_account() ) {
- return;
- }
- require_once __DIR__ . '/features/wpcom-command-palette/wpcom-command-palette.php';
- }
-
/**
* Load Odyssey Stats in Simple sites.
*/
@@ -347,34 +349,6 @@ public static function load_wpcom_simple_odyssey_stats() {
}
}
- /**
- * Load WPCOM Admin Interface.
- *
- * @return void
- */
- public static function load_wpcom_admin_interface() {
- require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php';
- }
-
- /**
- * Load WPCOM Site Management widget.
- */
- public static function load_wpcom_site_management_widget() {
- if ( is_agency_managed_site() || ! current_user_has_wpcom_account() || ! current_user_can( 'manage_options' ) ) {
- return;
- }
- if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
- require_once __DIR__ . '/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php';
- }
- }
-
- /**
- * Load Replace Site Visibility feature.
- */
- public static function load_replace_site_visibility() {
- require_once __DIR__ . '/features/replace-site-visibility/replace-site-visibility.php';
- }
-
/**
* Load the Jetpack Custom CSS feature.
*/
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/agency-managed/agency-managed.php b/projects/packages/jetpack-mu-wpcom/src/features/agency-managed/agency-managed.php
index 25a2d6cba370b..b7c78ba020625 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/agency-managed/agency-managed.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/agency-managed/agency-managed.php
@@ -4,13 +4,3 @@
*
* @package jetpack-mu-wpcom
*/
-
-/**
- * Whether to enable "fully managed agency site" features.
- * This is primarily used to hide WPCOM links, upsells, and features.
- *
- * @return bool True if the site is "fully managed agency site", false otherwise.
- */
-function is_agency_managed_site() {
- return ! empty( get_option( 'is_fully_managed_agency_site' ) );
-}
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/hide-site-visibility.php b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/hide-site-visibility.php
new file mode 100644
index 0000000000000..cbf4b4979b207
--- /dev/null
+++ b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/hide-site-visibility.php
@@ -0,0 +1,23 @@
+
+ .option-site-visibility {
+ display: none !important;
+ }
+ ';
+}
+add_action( 'load-options-reading.php', 'wpcom_hide_site_visibility_setting' );
+
+/**
+ * Remove the "Update Services" section in Writing Settings.
+ */
+add_filter( 'enable_update_services_configuration', '__return_false' );
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php
index 157dcbbe64283..60fb6a1255fb9 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php
@@ -55,30 +55,3 @@ function replace_site_visibility() {
id === 'options-reading' ) {
- echo '';
- }
-}
-add_action( 'admin_head', 'wpcom_hide_site_visibility_setting' );
-
-/**
- * Remove the "Update Services" section in Writing Settings if is_agency_managed_site is true.
- */
-function wpcom_remove_update_services_section() {
- return ! is_agency_managed_site();
-}
-add_filter( 'enable_update_services_configuration', 'wpcom_remove_update_services_section' );
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php
index a2cc36ac0d8b4..7edefbba95a1d 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php
@@ -53,10 +53,6 @@ function wpcom_enqueue_admin_bar_assets() {
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar core object.
*/
function wpcom_repurpose_wp_logo_as_all_sites_menu( $wp_admin_bar ) {
- if ( is_agency_managed_site() ) {
- return;
- }
-
foreach ( $wp_admin_bar->get_nodes() as $node ) {
if ( $node->parent === 'wp-logo' || $node->parent === 'wp-logo-external' ) {
$wp_admin_bar->remove_node( $node->id );
@@ -86,10 +82,6 @@ function wpcom_repurpose_wp_logo_as_all_sites_menu( $wp_admin_bar ) {
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar core object.
*/
function wpcom_add_reader_menu( $wp_admin_bar ) {
- if ( is_agency_managed_site() ) {
- return;
- }
-
$wp_admin_bar->add_node(
array(
'id' => 'reader',
@@ -109,10 +101,6 @@ function wpcom_add_reader_menu( $wp_admin_bar ) {
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar core object.
*/
function wpcom_add_my_account_item_to_profile_menu( $wp_admin_bar ) {
- if ( is_agency_managed_site() || ! current_user_has_wpcom_account() ) {
- return;
- }
-
$logout_node = $wp_admin_bar->get_node( 'logout' );
if ( $logout_node ) {
// Adds the 'My Account' menu item before 'Log Out'.
@@ -133,20 +121,3 @@ function wpcom_add_my_account_item_to_profile_menu( $wp_admin_bar ) {
}
}
add_action( 'admin_bar_menu', 'wpcom_add_my_account_item_to_profile_menu' );
-
-/**
- * Hides the Help Center menu.
- */
-function wpcom_hide_help_center_menu() {
- if ( ! is_agency_managed_site() ) {
- return;
- }
- ?>
-
- 'esc_attr' ) );
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php
index e8626d01a6e37..da7b842838a96 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php
@@ -12,28 +12,6 @@
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
-/**
- * Checks if the current user has a WordPress.com account connected.
- *
- * @return bool
- */
-function current_user_has_wpcom_account() {
- $user_id = get_current_user_id();
-
- if ( function_exists( '\A8C\Billingdaddy\Users\get_wpcom_user' ) ) {
- // On Simple sites, use get_wpcom_user function to check if the user has a WordPress.com account.
- $user = \A8C\Billingdaddy\Users\get_wpcom_user( $user_id );
- $has_account = isset( $user->ID );
- } else {
- // On Atomic sites, use the Connection Manager to check if the user has a WordPress.com account.
- $connection_manager = new Connection_Manager();
- $wpcom_user_data = $connection_manager->get_connected_user_data( $user_id );
- $has_account = isset( $wpcom_user_data['ID'] );
- }
-
- return $has_account;
-}
-
/**
* Adds a Hosting menu.
*/
@@ -41,17 +19,6 @@ function wpcom_add_hosting_menu() {
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
return;
}
- if ( is_agency_managed_site() ) {
- return;
- }
-
- /**
- * Don't show `Hosting` to administrators without a WordPress.com account being attached,
- * as they don't have access to any of the pages.
- */
- if ( ! current_user_has_wpcom_account() ) {
- return;
- }
$parent_slug = 'wpcom-hosting-menu';
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
@@ -167,14 +134,6 @@ function wpcom_add_jetpack_submenu() {
return;
}
- /**
- * Don't show to administrators without a WordPress.com account being attached,
- * as they don't have access to any of the pages.
- */
- if ( ! current_user_has_wpcom_account() ) {
- return;
- }
-
/*
* Do not display if we're in Offline mode, or if the user is not connected.
*/
@@ -289,7 +248,6 @@ function wpcom_add_plugins_menu() {
$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';
- $is_agency_managed_site = is_agency_managed_site();
if ( $is_simple_site ) {
$has_plugins_menu = false;
@@ -329,10 +287,6 @@ function wpcom_add_plugins_menu() {
}
}
- if ( $is_agency_managed_site || ! current_user_has_wpcom_account() ) {
- return;
- }
-
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
if ( $uses_wp_admin_interface ) {
add_submenu_page(
@@ -349,11 +303,6 @@ function wpcom_add_plugins_menu() {
if ( $is_atomic_site ) {
if (
- /**
- * Don't show `Scheduled Updates` to administrators without a WordPress.com account being attached,
- * as they don't have access to any of the pages.
- */
- current_user_has_wpcom_account() &&
! get_option( 'wpcom_is_staging_site' ) &&
function_exists( 'wpcom_site_has_feature' ) &&
wpcom_site_has_feature( \WPCOM_Features::SCHEDULED_UPDATES )
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php
index b6b2e6f13fddc..a990df311c20c 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php
@@ -89,9 +89,6 @@ function wpcom_enqueue_sidebar_notice_assets() {
* @return array | null
*/
function wpcom_get_sidebar_notice() {
- if ( is_agency_managed_site() ) {
- return null;
- }
$message_path = 'calypso:sites:sidebar_notice';
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php
index 0285f7a04ee85..5c976bec65662 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php
@@ -32,6 +32,10 @@ public static function get_instance() {
* Register widget with WordPress.
*/
public function __construct() {
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return;
+ }
+
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) );
}
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-theme-fixes.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-theme-fixes.php
new file mode 100644
index 0000000000000..e5801cac8f7b8
--- /dev/null
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-theme-fixes.php
@@ -0,0 +1,44 @@
+ 'defer',
+ 'in_footer' => true,
+ )
+ );
+}
+add_action( 'load-themes.php', 'wpcom_themes_remove_wpcom_actions' );
+
+/**
+ * Adds a CSS file to fix UI issues in the theme browser.
+ */
+function wpcom_themes_load_ui_fixes() {
+ wp_enqueue_style(
+ 'wpcom-themes-ui-fixes',
+ plugins_url( 'css/ui-fixes.css', __FILE__ ),
+ array(),
+ Jetpack_Mu_Wpcom::PACKAGE_VERSION
+ );
+}
+add_action( 'load-themes.php', 'wpcom_themes_load_ui_fixes' );
diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php
index b2e9240c33d26..f41d700df1a21 100644
--- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php
+++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php
@@ -9,13 +9,14 @@
use Automattic\Jetpack\Jetpack_Mu_Wpcom;
+if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
+ return;
+}
+
/**
* Displays a banner before the theme browser that links to the WP.com Theme Showcase.
*/
function wpcom_themes_show_banner() {
- if ( is_agency_managed_site() || ! current_user_has_wpcom_account() ) {
- return;
- }
$site_slug = wp_parse_url( home_url(), PHP_URL_HOST );
$wpcom_logo = plugins_url( 'images/wpcom-logo.svg', __FILE__ );
$background_image = plugins_url( 'images/banner-background.webp', __FILE__ );
@@ -55,13 +56,6 @@ function wpcom_themes_show_banner() {
* Registers an "Appearance > Theme Showcase" menu.
*/
function wpcom_themes_add_theme_showcase_menu() {
- if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
- return;
- }
- if ( is_agency_managed_site() || ! current_user_has_wpcom_account() ) {
- return;
- }
-
$site_slug = wp_parse_url( home_url(), PHP_URL_HOST );
add_submenu_page(
'themes.php',
@@ -72,37 +66,3 @@ function wpcom_themes_add_theme_showcase_menu() {
);
}
add_action( 'admin_menu', 'wpcom_themes_add_theme_showcase_menu' );
-
-/**
- * Removes actions from the active theme details added by Core to replicate our custom WP.com submenus.
- *
- * Core expect the menus to link to WP Admin, but our submenus point to wordpress.com so the actions won't work.
- *
- * @see https://github.com/WordPress/wordpress-develop/blob/80096ddf29d3ffa4d5654f5f788df7f598b48756/src/wp-admin/themes.php#L356-L412
- */
-function wpcom_themes_remove_wpcom_actions() {
- wp_enqueue_script(
- 'wpcom-theme-actions',
- plugins_url( 'js/theme-actions.js', __FILE__ ),
- array(),
- Jetpack_Mu_Wpcom::PACKAGE_VERSION,
- array(
- 'strategy' => 'defer',
- 'in_footer' => true,
- )
- );
-}
-add_action( 'load-themes.php', 'wpcom_themes_remove_wpcom_actions' );
-
-/**
- * Adds a CSS file to fix UI issues in the theme browser.
- */
-function wpcom_themes_load_ui_fixes() {
- wp_enqueue_style(
- 'wpcom-themes-ui-fixes',
- plugins_url( 'css/ui-fixes.css', __FILE__ ),
- array(),
- Jetpack_Mu_Wpcom::PACKAGE_VERSION
- );
-}
-add_action( 'load-themes.php', 'wpcom_themes_load_ui_fixes' );
diff --git a/projects/packages/jetpack-mu-wpcom/src/utils.php b/projects/packages/jetpack-mu-wpcom/src/utils.php
index 9f4cc67dea226..02a8b824e4d3b 100644
--- a/projects/packages/jetpack-mu-wpcom/src/utils.php
+++ b/projects/packages/jetpack-mu-wpcom/src/utils.php
@@ -5,8 +5,36 @@
* @package automattic/jetpack-mu-wpcom
*/
+use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Jetpack_Mu_Wpcom;
+/**
+ * Whether the current user is logged-in via WordPress.com account.
+ *
+ * @return bool True if the site is "fully managed agency site", false otherwise.
+ */
+function is_wpcom_user() {
+ // If the site is explicitly marked as agency-managed, treat the user as non-wpcom user.
+ if ( ! empty( get_option( 'is_fully_managed_agency_site' ) ) ) {
+ return false;
+ }
+
+ $user_id = get_current_user_id();
+
+ if ( function_exists( '\A8C\Billingdaddy\Users\get_wpcom_user' ) ) {
+ // On Simple sites, use get_wpcom_user function to check if the user has a WordPress.com account.
+ $user = \A8C\Billingdaddy\Users\get_wpcom_user( $user_id );
+ $has_account = isset( $user->ID );
+ } else {
+ // On Atomic sites, use the Connection Manager to check if the user has a WordPress.com account.
+ $connection_manager = new Connection_Manager();
+ $wpcom_user_data = $connection_manager->get_connected_user_data( $user_id );
+ $has_account = isset( $wpcom_user_data['ID'] );
+ }
+
+ return $has_account;
+}
+
/**
* Helper function to return the site slug for Calypso URLs.
* The fallback logic here is derived from the following code: