Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#14668 closed defect (bug) (worksforme)

Check for scheduled event to prevent duplicates

Reported by: markparolisi's profile markparolisi Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: Cron API Keywords: has-patch needs-testing
Focuses: Cc:


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)

14668.diff (620 bytes) - added by jgadbois 13 years ago.
14668.2.diff (1.3 KB) - added by scribu 13 years ago.
check wp_next_scheduled()

Download all attachments as: .zip

Change History (8)

#1 @scribu
13 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 3.1
  • Severity changed from critical to normal

I agree that it's a good idea to prevent multiple recurring events with the same callback to be scheduled.

13 years ago

#2 @jgadbois
13 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

13 years ago

check wp_next_scheduled()

#3 @scribu
13 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 @scribu
13 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' );

#5 @scribu
13 years ago

  • Milestone 3.1 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

#6 @scribu
13 years ago

(In [16690]) Add note about wp_next_scheduled() in wp_schedule_event(). See #14668

Note: See TracTickets for help on using tickets.