WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#37512 closed defect (bug) (fixed)

Shiny Updates: Trigger a JS event when deleting/installing themes/plugins

Reported by: DavidAnderson Owned by: jorbin
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.6
Component: Upgrade/Install Keywords: has-patch commit
Focuses: javascript, administration Cc:

Description

In #37216, triggers were added to Shiny Updates to enable the existing functionality of our plugin to continue working with the changed theme update implementation. (Our plugin pops up a dialog, communicates with the back-end via AJAX to perform a backup of the site's themes, and then when the backup is complete hands back control so that the update proceeds).

Further testing has revealed another issue - the "Shiny Deletes" for plugins or themes don't work with our plugin active, and there's no way for us to hook in to make it work.

The cause is the lack of an analogous trigger on the deletion event (corresponding to the existing triggers on the update event).

The attached patch adds triggers upon plugin and theme deletion. It also adds triggers in the corresponding location upon plugin and theme install; we don't use that, but it ought to be there for completeness and to allow other plugin authors to hook in.

Attachments (5)

trigger-delete-and-install.diff (1.2 KB) - added by DavidAnderson 3 years ago.
Add triggers upon shiny deletes and installs corresponding to those already present for updates
trigger-update-delete-and-install2.diff (1.7 KB) - added by DavidAnderson 3 years ago.
V2: Pass the arguments of what the event is related to along
trigger-update-delete-and-install3.diff (2.1 KB) - added by DavidAnderson 3 years ago.
Version 3: Also provide a trigger for bulk updates
trigger-update-delete-and-install4.diff (2.1 KB) - added by DavidAnderson 3 years ago.
V4: Rename bulk action as requested
trigger-update-delete-and-install5.diff (2.1 KB) - added by DavidAnderson 3 years ago.
V5: Adjust to reflect fact that the bulk action handler can be invoked for themes as well as plugins

Download all attachments as: .zip

Change History (18)

@DavidAnderson
3 years ago

Add triggers upon shiny deletes and installs corresponding to those already present for updates

#2 @ocean90
3 years ago

  • Keywords has-patch added
  • Summary changed from WC 4.6 RC 1 - missing JS triggers in Shiny Updates / Deletes to Shiny Updates: Trigger a JS event when deleting/installing themes/plugins

Wouldn't it be helpful to know which plugin/theme was deleted/installed/updated?

@DavidAnderson
3 years ago

V2: Pass the arguments of what the event is related to along

#3 @DavidAnderson
3 years ago

You're right - we don't use that, but some consumers could find that handy. I've added that in the revised patch (including adding it to the theme and plugin updates triggers - the theme update trigger is new in WP 4.6, but the plugin update trigger exists since 4.2).

#4 @swissspidy
3 years ago

  • Milestone changed from Awaiting Review to 4.6

Yeah, passing the additional info makes sense. args contains the success and error callbacks though, not sure that's super helpful. Would it perhaps suffice to pass only the slug?

@DavidAnderson
3 years ago

Version 3: Also provide a trigger for bulk updates

#5 @DavidAnderson
3 years ago

After much more testing, I've just provided a third version that adds a further trigger for the bulk action, which previously did not trigger anything (this also broke our code - not sure why we didn't catch this in the earlier testing when beta 1 came out).

@swissspidy: I was thinking that by passing args, we passed everything, so it's more future-proofed against any changes in what arguments there might be. I don't feel strongly either way though (we don't actually use the parameter).

#6 @swissspidy
3 years ago

'wp-plugin-bulk-action-' + bulkAction should probably be 'wp-plugin-bulk-' + bulkAction (i.e. without the -action part), otherwise trigger-update-delete-and-install3.diff looks fine.

@DavidAnderson
3 years ago

V4: Rename bulk action as requested

#7 @ocean90
3 years ago

The bulk action handler is also used for themes. So maybe wp-' + type + '-bulk-' + bulkAction?

@DavidAnderson
3 years ago

V5: Adjust to reflect fact that the bulk action handler can be invoked for themes as well as plugins

#8 @ocean90
3 years ago

  • Keywords commit added

@DavidAnderson Thanks!

FYI: Attachments don't trigger notifications so you should always post an additional comment when uploading a patch.

#9 @ocean90
3 years ago

  • Owner set to jorbin
  • Status changed from new to reviewing

@jorbin Can you review trigger-update-delete-and-install5.diff please?

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


3 years ago

#11 @jorbin
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38175:

Upgrade/Install: Trigger additional JS events in shiny updates

Events for updating exist, but they lack context. This adds args so that plugins can detec t what plugin/theme is being installed. Additionally, events for bulk actions, deleting and that and install is starting didn't exist, so this adds them.

Fixes #37512.
Props DavidAnderson, and ocean90, swissspidy for review.

#12 @jorbin
3 years ago

In 38218:

Updates: Standardize JS Custom Event Names

Custom JS events are triggered on the document in order for plugins to have something to hook into. The standard began in #31819 is dash separated and begins with wp to signify the namespace, followed by the subject of our action ( "theme", "plugin", etc.) followed by the action and an optional indicator of status ( "install-success", "deleting" ).

This brings some of the theme hooks in line with the standard. As of now, all plugin actions in src/wp-admin/js/updates.js have an equal corresponding theme action.

Fixes #37598.
See #37512, #37216, #31819.
Props olarmarius, ocean90.

#13 @jorbin
3 years ago

In 38219:

Updates: Standardize JS Custom Event Names

Merges [38218] in to 4.6 branch.

Custom JS events are triggered on the document in order for plugins to have something to hook into. The standard began in #31819 is dash separated and begins with wp to signify the namespace, followed by the subject of our action ( "theme", "plugin", etc.) followed by the action and an optional indicator of status ( "install-success", "deleting" ).

This brings some of the theme hooks in line with the standard. As of now, all plugin actions in src/wp-admin/js/updates.js have an equal corresponding theme action.

Fixes #37598.
See #37512, #37216, #31819.
Props olarmarius, ocean90.

Note: See TracTickets for help on using tickets.