Opened 10 years ago
Closed 8 years ago
#27444 closed enhancement (fixed)
delete widget action hook
Reported by: | afercia | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Widgets | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Just a proposal to have a new action to hook in when deleting a widget.
For example, many themes or plugins provide widgets that fetch data from external sources and then store the response in a transient.
When users delete the widget, the transient won't be deleted and will live forever in the database because it won't be requested again.
Currently, the only way I've found to delete that transient, would be checking if POST 'delete_widget' isset and true and then checking POST 'widget-id'. Same checks are already used in the core but having a specific action to use would be much more clean.
Then, it would be a matter of a few lines of code to add an action to your widget constructor and write a new small method in your widget class to delete the transient. Basically it's something similar to what you're already doing to flush the wp_cache of the default Recent Posts widget.
Besides this specific scenario, there might be lots of things developers would like to do after deleting a widget and this would be very handy.
Attached proposal is just an example, for sure can be improved (maybe pass the widget-id as argument?) and extended. Hope you get the idea. Please consider I'm an absolute beginner with the WP core. Be nice :)
Attachments (2)
Change History (11)
#5
in reply to:
↑ description
@
10 years ago
thx John, Sergey,
When users delete the widget, the transient won't be deleted
and will live forever in the databasebecause it won't be requested again.
Actually, if expired it will be deleted just on database upgrade (#20316)
Sounds sensible. Definitely needs some contextual parameters passed to the action too, such as
$id_base
and$sidebar_id
.