From bd73f8d8c89ea4f22cca6e12d3b1c462b9126e62 Mon Sep 17 00:00:00 2001 From: Dean Sas Date: Thu, 23 May 2024 19:03:36 +0100 Subject: [PATCH 1/5] Plugins menu for untangled sites All sites should now get these plugin menu items: * Installed plugins (plugins.php) * Add New Plugin (plugin-install.php) * Plugin Marketplace (wordpress.com/plugins/:site) Additionally, atomic sites also get "Scheduled Updates" (wordpress.com/plugins/scheduled-updates/:site). This means that sites have consistency across simple and WoA environments, and the plugin marketplace is accessible. This is a WIP, this commit contains some TODOs. --- .../wpcom-site-menu/wpcom-site-menu.php | 77 +++++++++++++++---- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php index b6afa4557e040..6161dc2edd715 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php @@ -599,6 +599,8 @@ function wpcom_add_scheduled_updates_menu() { $domain = wp_parse_url( home_url(), PHP_URL_HOST ); + // TODO: When looking at wordpress.com/plugins/:site on an atomic site this menu + // item is highlighted rather than the Plugin Marketplace add_submenu_page( 'plugins.php', esc_attr__( 'Scheduled Updates', 'jetpack-mu-wpcom' ), @@ -611,26 +613,75 @@ function wpcom_add_scheduled_updates_menu() { add_action( 'admin_menu', 'wpcom_add_scheduled_updates_menu' ); /** - * Add the Plugins menu item to the admin menu on simple sites. + * Add the Plugins menu item to the admin menu + * + * * Adds a Plugin Marketplace link to the Plugins menu in the admin sidebar. + * * Adds Installed Plugins and Add New Plugin links to the Plugins menu in the admin sidebar if they don't exist + * * Updates the capability of the Installed Plugins and Add New Plugin links to manage_options if they do exist */ function wpcom_add_plugins_menu() { - - if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { + if ( ! function_exists( 'wpcom_is_nav_redesign_enabled' ) || ! wpcom_is_nav_redesign_enabled() ) { return; } + global $menu; + + $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM; + + $found_plugin_menu = false; + $found_plugin_install_submenu = false; + foreach ( $menu as &$menu_item ) { + if ( 'plugins.php' === $menu_item[2] ) { + $found_plugin_menu = true; + if ( $is_simple_site ) { + $menu_item[1] = 'manage_options'; + } + } + if ( 'plugin-install.php' === $menu_item[2] ) { + $found_plugin_install_submenu = true; + if ( $is_simple_site ) { + $menu_item[1] = 'manage_options'; + } + } + } + + $domain = wp_parse_url( home_url(), PHP_URL_HOST ); + + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + if ( ! $found_plugin_menu ) { + // Didn't find an existing plugins menu, so add one. + add_menu_page( + __( 'Plugins', 'jetpack-mu-wpcom' ), + __( 'Plugins', 'jetpack-mu-wpcom' ), + 'manage_options', // Roughly means "is a site admin" + 'plugins.php', + null, + 'dashicons-admin-plugins', + 65 + ); + $found_plugin_menu = true; + } + + if ( ! $found_plugin_install_submenu ) { + add_submenu_page( + 'plugins.php', + __( 'Add New Plugin', 'jetpack-mu-wpcom' ), + __( 'Add New Plugin', 'jetpack-mu-wpcom' ), + 'manage_options', // Roughly means "is a site admin" + // Don't have a plugin-install.php page on Simple sites yet + 'https://' . $domain . '/wp-admin/plugin-install.php' + ); + } + } - if ( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) { - $domain = wp_parse_url( home_url(), PHP_URL_HOST ); - $can_install_plugins = function_exists( 'wpcom_site_has_feature' ) && wpcom_site_has_feature( WPCOM_Features::INSTALL_PLUGINS ); + if ( $found_plugin_menu ) { - add_menu_page( - __( 'Plugins', 'jetpack-mu-wpcom' ), - __( 'Plugins', 'jetpack-mu-wpcom' ), + add_submenu_page( + 'plugins.php', + __( 'Plugin Marketplace', 'jetpack-mu-wpcom' ), + __( 'Plugin Marketplace', 'jetpack-mu-wpcom' ), 'manage_options', // Roughly means "is a site admin" - $can_install_plugins ? 'https://wordpress.com/plugins/' . $domain : 'plugins.php', - null, - 'dashicons-admin-plugins', - 65 + 'https://wordpress.com/plugins/' . $domain, + null ); } } From dc589f01c00720187d28e01fa295a614b1492ded Mon Sep 17 00:00:00 2001 From: Dean Sas Date: Thu, 23 May 2024 20:29:26 +0100 Subject: [PATCH 2/5] changelog --- .../jetpack-mu-wpcom/changelog/plugin-menu-consistency | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency diff --git a/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency b/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency new file mode 100644 index 0000000000000..57e4689dfd457 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Plugin menu: Increase consistency between environments From ed835ab5df9d251f66eb63675cba6b5faef0b9ab Mon Sep 17 00:00:00 2001 From: mmtr <1233880+mmtr@users.noreply.github.com> Date: Tue, 28 May 2024 14:59:08 +0200 Subject: [PATCH 3/5] Change copy of classic intro tour --- .../changelog/plugin-menu-consistency | 2 +- .../wpcom-site-menu/wpcom-site-menu.php | 134 +++++------------- 2 files changed, 34 insertions(+), 102 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency b/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency index 57e4689dfd457..702abe7afbdf8 100644 --- a/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency +++ b/projects/packages/jetpack-mu-wpcom/changelog/plugin-menu-consistency @@ -1,4 +1,4 @@ Significance: minor Type: changed -Plugin menu: Increase consistency between environments +Plugin menu: Register "Plugins Marketplace" menu diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php index 70dc9c4fb4b9b..8ee6ae991feec 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php @@ -435,123 +435,55 @@ function wpcom_maybe_enable_link_manager() { add_action( 'init', 'wpcom_maybe_enable_link_manager' ); /** - * Add the Scheduled Updates menu item to the Plugins menu. - * - * Limited to sites with scheduled updates feature. + * Handles the Plugins menu for WP.com sites. */ -function wpcom_add_scheduled_updates_menu() { - // Bail on Simple sites - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - return; - } - - /** - * 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. - */ - if ( ! current_user_has_wpcom_account() ) { - return; - } - - // Don't show on staging sites. - if ( get_option( 'wpcom_is_staging_site' ) ) { - return; - } - - if ( ! function_exists( 'wpcom_site_has_feature' ) ) { +function wpcom_add_plugins_menu() { + if ( ! function_exists( 'wpcom_is_nav_redesign_enabled' ) || ! wpcom_is_nav_redesign_enabled() ) { return; } - if ( ! wpcom_site_has_feature( \WPCOM_Features::SCHEDULED_UPDATES ) ) { - return; + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + add_menu_page( + __( 'Plugins', 'jetpack-mu-wpcom' ), + __( 'Plugins', 'jetpack-mu-wpcom' ), + 'manage_options', // Roughly means "is a site admin" + 'plugins.php', + null, + 'dashicons-admin-plugins', + 65 + ); } $domain = wp_parse_url( home_url(), PHP_URL_HOST ); - - // TODO: When looking at wordpress.com/plugins/:site on an atomic site this menu - // item is highlighted rather than the Plugin Marketplace add_submenu_page( 'plugins.php', - esc_attr__( 'Scheduled Updates', 'jetpack-mu-wpcom' ), - __( 'Scheduled Updates', 'jetpack-mu-wpcom' ), - 'update_plugins', - esc_url( "https://wordpress.com/plugins/scheduled-updates/$domain" ), + __( 'Plugins Marketplace', 'jetpack-mu-wpcom' ), + __( 'Plugins Marketplace', 'jetpack-mu-wpcom' ), + 'manage_options', // Roughly means "is a site admin" + 'https://wordpress.com/plugins/' . $domain, null ); -} -add_action( 'admin_menu', 'wpcom_add_scheduled_updates_menu' ); - -/** - * Add the Plugins menu item to the admin menu - * - * * Adds a Plugin Marketplace link to the Plugins menu in the admin sidebar. - * * Adds Installed Plugins and Add New Plugin links to the Plugins menu in the admin sidebar if they don't exist - * * Updates the capability of the Installed Plugins and Add New Plugin links to manage_options if they do exist - */ -function wpcom_add_plugins_menu() { - if ( ! function_exists( 'wpcom_is_nav_redesign_enabled' ) || ! wpcom_is_nav_redesign_enabled() ) { - return; - } - global $menu; - - $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM; - - $found_plugin_menu = false; - $found_plugin_install_submenu = false; - foreach ( $menu as &$menu_item ) { - if ( 'plugins.php' === $menu_item[2] ) { - $found_plugin_menu = true; - if ( $is_simple_site ) { - $menu_item[1] = 'manage_options'; - } - } - if ( 'plugin-install.php' === $menu_item[2] ) { - $found_plugin_install_submenu = true; - if ( $is_simple_site ) { - $menu_item[1] = 'manage_options'; - } - } - } - $domain = wp_parse_url( home_url(), PHP_URL_HOST ); - - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - if ( ! $found_plugin_menu ) { - // Didn't find an existing plugins menu, so add one. - add_menu_page( - __( 'Plugins', 'jetpack-mu-wpcom' ), - __( 'Plugins', 'jetpack-mu-wpcom' ), - 'manage_options', // Roughly means "is a site admin" - 'plugins.php', - null, - 'dashicons-admin-plugins', - 65 - ); - $found_plugin_menu = true; - } - - if ( ! $found_plugin_install_submenu ) { + if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { + 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 ) + ) { add_submenu_page( 'plugins.php', - __( 'Add New Plugin', 'jetpack-mu-wpcom' ), - __( 'Add New Plugin', 'jetpack-mu-wpcom' ), - 'manage_options', // Roughly means "is a site admin" - // Don't have a plugin-install.php page on Simple sites yet - 'https://' . $domain . '/wp-admin/plugin-install.php' + esc_attr__( 'Scheduled Updates', 'jetpack-mu-wpcom' ), + __( 'Scheduled Updates', 'jetpack-mu-wpcom' ), + 'update_plugins', + esc_url( "https://wordpress.com/plugins/scheduled-updates/$domain" ), + null ); } } - - if ( $found_plugin_menu ) { - - add_submenu_page( - 'plugins.php', - __( 'Plugin Marketplace', 'jetpack-mu-wpcom' ), - __( 'Plugin Marketplace', 'jetpack-mu-wpcom' ), - 'manage_options', // Roughly means "is a site admin" - 'https://wordpress.com/plugins/' . $domain, - null - ); - } } add_action( 'admin_menu', 'wpcom_add_plugins_menu' ); From 545fb6e38502480fd0091f5253d611c8ddb0f8e0 Mon Sep 17 00:00:00 2001 From: mmtr <1233880+mmtr@users.noreply.github.com> Date: Wed, 29 May 2024 11:35:15 +0200 Subject: [PATCH 4/5] Use shorter menu name --- .../src/features/wpcom-site-menu/wpcom-site-menu.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php index 8ee6ae991feec..8c80349f1ba3d 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php @@ -457,8 +457,10 @@ function wpcom_add_plugins_menu() { $domain = wp_parse_url( home_url(), PHP_URL_HOST ); add_submenu_page( 'plugins.php', - __( 'Plugins Marketplace', 'jetpack-mu-wpcom' ), - __( 'Plugins Marketplace', 'jetpack-mu-wpcom' ), + /* translators: Name of the Plugins submenu that links to the Plugins Marketplace */ + __( 'Marketplace', 'jetpack-mu-wpcom' ), + /* translators: Name of the Plugins submenu that links to the Plugins Marketplace */ + __( 'Marketplace', 'jetpack-mu-wpcom' ), 'manage_options', // Roughly means "is a site admin" 'https://wordpress.com/plugins/' . $domain, null From 9116b30639d44a70d4bb31d8babbd406370b86ae Mon Sep 17 00:00:00 2001 From: mmtr <1233880+mmtr@users.noreply.github.com> Date: Wed, 29 May 2024 13:18:33 +0200 Subject: [PATCH 5/5] Register "Add New Plugin" submenu --- .../src/features/wpcom-site-menu/wpcom-site-menu.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php index 8c80349f1ba3d..e40b9eb499dd4 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php @@ -452,6 +452,17 @@ function wpcom_add_plugins_menu() { 'dashicons-admin-plugins', 65 ); + + if ( function_exists( 'wpcom_plugins_display_marketplace' ) ) { + add_submenu_page( + 'plugins.php', + __( 'Add New Plugin', 'jetpack-mu-wpcom' ), + __( 'Add New Plugin', 'jetpack-mu-wpcom' ), + 'manage_options', // Roughly means "is a site admin" + 'wpcom-install-plugin', + 'wpcom_plugins_display_marketplace' + ); + } } $domain = wp_parse_url( home_url(), PHP_URL_HOST );