Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 36 additions & 2 deletions projects/plugins/beta/src/class-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Copy Markdown
Contributor

@tbradsha tbradsha May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantics comment...it's an action, not a filter:
https://developer.wordpress.org/reference/hooks/deleted_plugin/

Suggested change
add_filter( 'deleted_plugin', array( $this, 'maybe_delete_dev_plugin_too' ), 10, 2 );
add_action( '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' ) );
Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -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 ) );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused me: the plugin is deleted, but then we're going to grab the plugin info? Turns out it's pulling from a cache that persists after the plugin itself is deleted.

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() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what if the $wp_filesystem is non-functional now?

if ( $wp_filesystem->is_dir( $working_dir ) ) {
$wp_filesystem->delete( $working_dir, true );
}
}

/**
* Filter: WordPress.org Plugins API results.
*
Expand Down
Loading