Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#31307 closed enhancement (fixed)

cron_request filter should pass $doing_wp_cron as an argument to callbacks

Reported by: ericlewis's profile ericlewis Owned by: ericlewis's profile ericlewis
Milestone: 4.5 Priority: normal
Severity: normal Version:
Component: Cron API Keywords: has-patch
Focuses: Cc:

Description

The request made to the cron endpoint is filterable. doing_wp_cron is a timestamp created when the cron is spawned on a request, and embedded in the request sent to the cron endpoint. This is used on the cron endpoint to avoid multiple processes looping over the same events (see #17462).

I'm about to filter this request as I have a read-only datacenter, so I need to send the request to the writeable one.

Although I can grab the $doing_wp_cron value out of the 'key' in the cron_request array, that seems delicate. More elegantly we could pass the $doing_wp_cron value as an argument to the filter.

Attachments (3)

31307.diff (461 bytes) - added by ericlewis 9 years ago.
31307.2.diff (820 bytes) - added by ericlewis 9 years ago.
31307.3.diff (1.0 KB) - added by ericlewis 9 years ago.

Download all attachments as: .zip

Change History (13)

#1 follow-up: @F J Kaiser
9 years ago

Why is fetching the value from the key "delicate"? The key actually is ... key.

#2 in reply to: ↑ 1 @ericlewis
9 years ago

Replying to F J Kaiser:

Why is fetching the value from the key "delicate"? The key actually is ... key.

If a value is filterable then a developer should make no assumption about what the value they are filtering is, as a previous filter could've done anything it wants to the data.

Anything that's critical to the context should be passed along as arguments into the apply_filters() invocation.

#3 follow-up: @ericlewis
9 years ago

Can we add parameters to apply_filters() calls without breaking stuff?

#4 in reply to: ↑ 3 @DrewAPicture
9 years ago

Replying to ericlewis:

Can we add parameters to apply_filters() calls without breaking stuff?

We add new parameters all the time (with corresponding changelog entries). Due to the architecture of requiring explicit argument counts in add_filter|action(), adding additional args should have no effect on legacy code.

@ericlewis
9 years ago

#5 @ericlewis
9 years ago

  • Milestone changed from Awaiting Review to Future Release

#6 @ericlewis
9 years ago

  • Keywords has-patch added

@ericlewis
9 years ago

@ericlewis
9 years ago

#8 @ericlewis
9 years ago

attachment:31307.diff adds since hook docs.

#9 @ericlewis
9 years ago

  • Owner set to ericlewis
  • Resolution set to fixed
  • Status changed from new to closed

In 36228:

Cron: Add the cron lock timestamp to the 'cron_request' filter arguments.

Fixes #31307

#10 @SergeyBiryukov
9 years ago

  • Milestone changed from Future Release to 4.5
Note: See TracTickets for help on using tickets.