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. *