-
Notifications
You must be signed in to change notification settings - Fork 875
beta: Improve plugin page interaction #48490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ) ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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/