#14668 closed defect (bug) (worksforme)
Check for scheduled event to prevent duplicates
Reported by: | markparolisi | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0.1 |
Component: | Cron API | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
wp_schedule_event() checks if the interval (hourly, daily, etc) of the event is valid, but it does not check if the event is already scheduled.
A simple check of the cron array should return false if the event already exists.
This will prevent crippling DB queries resulting from endless duplication of scheduled events
Attachments (2)
Change History (8)
#1
@
14 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 3.1
- Severity changed from critical to normal
#3
@
14 years ago
jgadbois, that won't work, since $timestamp will be different most of the time.
The correct way is to use wp_next_scheduled(). See 14668.2.diff
#4
@
14 years ago
The problem with 14668.2.diff is that it doesn't allow scheduling non-regular intervals.
For example, if I want to schedule the same event to run twice daily, but on specific hours, I can currently do this:
if ( !wp_next_scheduled( 'my_event' ) ) { wp_schedule_event( strtotime( '10am' ), 'daily', 'my_event' ); wp_schedule_event( strtotime( '12am' ), 'daily', 'my_event' ); }
Note: See
TracTickets for help on using
tickets.
I agree that it's a good idea to prevent multiple recurring events with the same callback to be scheduled.