From 49d1c168ea5c862a6fb3e2efbd6b1621c49b32c7 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 4 May 2026 11:37:39 -0400 Subject: [PATCH] beta: Improve plugin page interaction Previously, when a -dev version is not active, it was always being hidden from the plugin page. This caused a few confusing interactions if there wasn't a non-dev version of the plugin also installed: you can't see it to delete it if you want to clean up your filesystem, and Core's plugin dependency feature might show a dependency from the hidden plugin. This PR changes it to only hide the -dev version if the non-dev version is also present. That causes another odd interaction: if you delete the non-dev version, then the dev version unexpectedly shows up. The sensible thing to do in that case is to delete the dev version when the non-dev version gets deleted; this PR hooks 'deleted_plugin' to do just that. --- ...te-beta-dont-hide-when-dev-is-only-version | 4 ++ ...-beta-dont-hide-when-dev-is-only-version#2 | 4 ++ projects/plugins/beta/src/class-hooks.php | 38 ++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version create mode 100644 projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version#2 diff --git a/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version b/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version new file mode 100644 index 000000000000..85d769240b16 --- /dev/null +++ b/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +When only a -dev version is installed (but not active), it will no longer be hidden in the plugins list. This allows for deleting the files via the plugin page, and for Core's plugin-dependency feature to not give confusing results. diff --git a/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version#2 b/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version#2 new file mode 100644 index 000000000000..57c6f5ee6378 --- /dev/null +++ b/projects/plugins/beta/changelog/update-beta-dont-hide-when-dev-is-only-version#2 @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +When the non-dev version of a plugin is deleted via the plugin page, the -dev version will be deleted as well. diff --git a/projects/plugins/beta/src/class-hooks.php b/projects/plugins/beta/src/class-hooks.php index 4b08142d320f..dc750c52e075 100644 --- a/projects/plugins/beta/src/class-hooks.php +++ b/projects/plugins/beta/src/class-hooks.php @@ -58,6 +58,8 @@ public function __construct() { add_filter( 'all_plugins', array( $this, 'update_all_plugins' ) ); + add_filter( 'deleted_plugin', array( $this, 'maybe_delete_dev_plugin_too' ), 10, 2 ); + add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 ); add_action( 'jetpack_beta_autoupdate_hourly_cron', array( self::class, 'run_autoupdate' ) ); @@ -207,7 +209,7 @@ public function remove_activate_link( $actions, $plugin_file ) { */ public function update_all_plugins( $plugins ) { foreach ( Plugin::get_plugin_file_map() as $nondev => $dev ) { - // WP.com requests away show regular plugin. + // WP.com requests always show regular plugin. if ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) { // Ensure that it reports the version it's using on account of the Jetpack Beta plugin to Calypso. if ( is_plugin_active( $dev ) ) { @@ -216,13 +218,45 @@ public function update_all_plugins( $plugins ) { unset( $plugins[ $dev ] ); } elseif ( is_plugin_active( $dev ) ) { unset( $plugins[ $nondev ] ); - } else { + } elseif ( isset( $plugins[ $dev ] ) && isset( $plugins[ $nondev ] ) ) { unset( $plugins[ $dev ] ); } } return $plugins; } + /** + * Action: Delete dev plugin when non-dev version is deleted. + * + * Handler for 'deleted_plugin' action. + * + * @param string $plugin_file Deleted plugin. + * @param bool $deleted Whether the deletion was successful. + */ + public function maybe_delete_dev_plugin_too( $plugin_file, $deleted ) { + if ( ! $deleted ) { + return; + } + $plugin = Plugin::get_plugin( dirname( $plugin_file ) ); + if ( ! $plugin ) { + return; + } + // If somehow the non-dev got deleted while the dev is active, don't delete the dev. + if ( $plugin->is_active( 'dev' ) ) { + return; + } + + // $wp_filesystem should already be functional thanks to Core just deleting the non-dev plugin. But check it just in case. + global $wp_filesystem; + if ( ! $wp_filesystem ) { + return; + } + $working_dir = dirname( $plugin->dev_plugin_path() ); + if ( $wp_filesystem->is_dir( $working_dir ) ) { + $wp_filesystem->delete( $working_dir, true ); + } + } + /** * Filter: WordPress.org Plugins API results. *