Opened 11 years ago
Closed 4 years ago
#25266 closed enhancement (wontfix)
wp_unschedule_event should apply filter to changes
Reported by: | _ck_ | Owned by: | chriscct7 |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Cron API | Keywords: | has-patch |
Focuses: | Cc: |
Description
wp_unschedule_event needs to announce removal of events, just like wp_schedule_event does through a filter
I would suggest allowing the filter to cancel the unschedule as a bonus.
ie.
function wp_unschedule_event( $timestamp, $hook, $args = array() ) { $crons = _get_cron_array(); $key = md5(serialize($args)); $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'args' => $args ); if ( apply_filters('unschedule_event', $event) ) unset( $crons[$timestamp][$hook][$key] ); if ( empty($crons[$timestamp][$hook]) ) unset( $crons[$timestamp][$hook] ); if ( empty($crons[$timestamp]) ) unset( $crons[$timestamp] ); _set_cron_array( $crons ); }
Optionally, consider if the filter returns false and there is no unset, the database should not be rewritten.
Attachments (1)
Change History (8)
#2
@
10 years ago
I would really like to see this happen. It is not possible to replace the cron system through a plugin without consistent filters/actions across all of the event functions.
#4
@
9 years ago
- Keywords has-patch added; needs-patch removed
Patch adds a filter hook so we can hook into wp_unschedule_event before retrieving, removing, and updating the scheduled hooks. I left out the check to determine if we should write to the database because it's a cheap operation and probably not absolutely necessary. If people feel it should be there I'll add it in the future.
#7
follow-up:
↓ 8
@
6 years ago
This is now possible with the changes introduced in WordPress 5.1, please refer to the dev note on the Make WordPress Core P2.
#8
in reply to:
↑ 7
@
4 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from reviewing to closed
Replying to peterwilsoncc:
This is now possible with the changes introduced in WordPress 5.1, please refer to the dev note on the Make WordPress Core P2.
Closing this off given the filters introduced in WP 5.1 making it possible.
It may have changed in the years since this ticket was opened but update_option()
does not update the database if the option is unchanged and the cron functions now provide meaningful return values.
It makes sense that both wp_schedule_event() and wp_unschedule_event() have consistent filters.