WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#34661 closed enhancement (invalid)

add filter to WP_Upgrader::install_package() to filter $this->result

Reported by: afragen Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Upgrade/Install Keywords: has-patch
Focuses: Cc:

Description

If a plugin or theme updates from a source outside of the .org repo the downloaded plugin/theme is often in a format that requires renaming so that it can be correctly moved to a corrected directory structure. As an example, GitHub downloads are in the format of user-my-plugin-name-hash.zip and when expanded have the format user-my-plugin-name-hash/my-plugin-name.php

From here the outside updater code must rename the directory and move the files or plugin or theme deactivation will be an issue. Currently there are 2 filters within the WP_Upgrader::install_package() that can be used to assist upgrader_source_selection and upgrader_post_install. Both of these have drawbacks.

upgrader_source_selection only allows to change the $source and while this is helpful, it does not allow for changing of any of the other destination parameters. upgrader_post_intall has a more convenient parameter in $hook_extra to aid in renaming of the directory structure but it's return value is either an error or an array and nothing happens with a non-error return value.

Manipulating these many of the destination parameters of $this->result is needed to allow for seamless renaming of these directories and to allow for these renamed values to be saved. It is the ability to save these values for use elsewhere that is the principal benefit of this proposed filter.

As an example, in order to update, move, and keep active the current theme the $source needs to be updated and saved. Though this can be currently achieved using upgrader_source_selection no other parameters can be saved. As #34617 explains, the version information for plugin updated via shiny updates returns an empty string if the destination_name of $this->result is not the updated destination name. Currently, there is no method of changing the destination name in the following line from wp_ajax_update_plugin()

$plugin_data = get_plugins( '/' . $result[ $plugin ]['destination_name'] );

This results in a cosmetic bug when updating via shiny updates, missing version information.

Adding this filter would allow for a simple consistent ability to manipulate any of the values of the destination in $this->result and have them saved for when they may be referenced elsewhere in code.

I'm not certain how this would effect #27365. This would supersede #34617.

Attachments (1)

34661.diff (862 bytes) - added by afragen 5 years ago.

Download all attachments as: .zip

Change History (8)

@afragen
5 years ago

#1 @afragen
5 years ago

#34617 was marked as a duplicate.

This ticket was mentioned in Slack in #core by afragen. View the logs.


5 years ago

#3 @afragen
5 years ago

  • Keywords has-patch added

#4 follow-up: @dd32
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #34617.

This is the wrong way to go about fixing this. See comment:25:ticket:34617

#5 in reply to: ↑ 4 @afragen
5 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Replying to dd32:

Duplicate of #34617.

This is the wrong way to go about fixing this. See comment:25:ticket:34617

This way really does provide for a solution to all circumstances.

  1. Ability to move files to correct location.
  2. Ability to discover destination_name for shiny updates.
  3. Ability to have better parameters for parsing download package name to the correct name.

Please reconsider. This is a more versatile solution to all of these issues.

Last edited 5 years ago by afragen (previous) (diff)

#6 @afragen
5 years ago

Sorry, we can close this.

#7 @afragen
5 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.