Opened 13 years ago
Closed 7 years ago
#18997 closed feature request (fixed)
Adding wp_unschedule_hook function
Reported by: | arena | Owned by: | chriscct7 |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | Cron API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Unschedule all previously scheduled cron job for a hook.
Can be usefull for plugins when deactivating to clean up the cron queue
The $hook parameter is required, so that the events can be identified.
@param string $hook Action hook, the execution of which will be unscheduled.
Attachments (6)
Change History (39)
#2
@
13 years ago
Isn't that what wp_clear_scheduled_hook() already does?
That clears by hook + args, It's common place to hook multiple "instances" of a job with varying parameters (ie. Post ID to process) to a single hook, there's no API to clear all events for that hook at present. I've seen this requested before, it might be on trac, or elsewhere, I'm not sure.
#4
@
13 years ago
- Keywords dev-feedback removed
dd32 is right :
"there's no API to clear all events for a hook at present"
i coded it myself for a plugin but think it ought to be in the API
#6
@
13 years ago
Patch seems to be okay although it will need to be cleaned up to meet WordPress coding standards.
#8
in reply to:
↑ 7
@
13 years ago
Replying to arena:
Done !
Just one more minor nitpick:
if ( empty( $crons[$timestamp] ) ) unset( $crons[$timestamp] );
We do if
's like that (line break in there) and with some extra spaces inside of the empty()
. :)
#11
@
13 years ago
Perhaps too clever, or slower, but instead of if ( empty ) unset();
, we could also hold off until before we call _set_cron_array() and then do $cron = array_filter( $cron );
That will clear out empty values.
#12
follow-up:
↓ 13
@
13 years ago
Nacin, your point is interesting.
May be this should be done once for all in
_set_cron_array()
simplifying all other functions calling _set_cron_array()
#13
in reply to:
↑ 12
@
13 years ago
Replying to arena:
Nacin, your point is interesting.
May be this should be done once for all in
_set_cron_array()
simplifying all other functions calling _set_cron_array()
since nacin tip, i reviewed the cron api and made some code changes :
- to have _get_cron_array closer to _set_cron_array when possible
- generalization of test empty( $crons ) after _get_cron_array()
- added a '$action' argument in function _set_cron_array()
patch is named #cron
#16
in reply to:
↑ 15
@
13 years ago
Replying to arena:
not fair, nacin opened 5 months ago ...
Cron had a few changes already in 3.4, specifically microtime locking. This however digs a bit deeper into the API and deserves a more thorough review. If we end up setting or getting the cron array out of order, we risk a bug or race condition. I think the patch will be great for 3.5.
#17
@
13 years ago
- Keywords needs-unit-tests added
I am fine with reviving #18997.patch for 3.4, but we will first need unit tests: http://unit-tests.trac.wordpress.org/browser/wp-testcase/test_cron.php.
#19
@
13 years ago
- Resolution maybelater deleted
- Status changed from closed to reopened
Please don't close valid tickets. Even if you no longer desire the feature, I'm sure others do. Thanks. :)
#20
@
10 years ago
18997.patch is a refreshed patch that improves some formatting, adds brackets, and uses the src
directory structure.
#21
@
10 years ago
- Keywords needs-unit-tests removed
18997-tests.patch introduces the test_unschedule_hook()
test.
#23
@
10 years ago
Had a problem today where I accidentally scheduled the function that adds the schedule.
Although I spotted and fixed the error, it was impossible to remove the hook without this function.
This case here outlines the same issue.
#25
@
9 years ago
What can be done to move this ticket forward ? I'm all for this.
I've tested @mordauk's patch & unit tests and both seem to work as expected.
Uploading refreshed patch - which includes both his original patch + the unit test - now just in case that's the issue. Props should go to @mordauk.
#26
@
9 years ago
@jrf not much needs to be done. I'm going to give it a quick run through, and then it will be milestoned for 4.5
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
9 years ago
#28
@
8 years ago
@chriscct7 are you able to give this a look? Otherwise I would suggest asking @SergeyBiryukov to take that look for you :)
#30
@
7 years ago
- Keywords has-unit-tests added; needs-testing removed
- Milestone changed from Future Release to 4.9
- Status changed from reviewing to accepted
Isn't that what
wp_clear_scheduled_hook()
already does?