#49961 closed enhancement (fixed)
Expose the reason for failures that occur within WP-Cron functions
Reported by: | johnbillion | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | 5.1 |
Component: | Cron API | Keywords: | has-patch has-unit-tests dev-feedback has-dev-note |
Focuses: | Cc: |
Description
Since WordPress 5.1, the various WP-Cron related functions (wp_schedule_event()
etc) now return meaningful return values, but this still doesn't expose the underlying reason for failure.
My WP Crontrol plugin regularly gets support requests from users who are managing cron events but getting a generic error message. It would be useful if core exposed the underlying problem so that anything that calls wp_schedule_event()
, wp_unschedule_event()
etc can provide a meaningful error message to the end user.
I see two potential approaches:
- Add an optional
$wp_error
parameter to these functions, similar towp_update_post()
,wp_set_comment_status()
etc, and return a meaningful error when one occurs. - Trigger an action containing the error details, similar to
http_api_debug
, which can be hooked into before calling the cron functions.
Change History (13)
This ticket was mentioned in PR #914 on WordPress/wordpress-develop by johnbillion.
4 years ago
#1
- Keywords has-patch has-unit-tests added
#2
@
4 years ago
- Keywords dev-feedback added; 2nd-opinion removed
- Milestone changed from Awaiting Review to 5.7
PR ready for review at https://github.com/WordPress/wordpress-develop/pull/914. One thing I'm particularly interested in hearing is if anybody thinks it will cause a problem for the various pre_*
filters to now potentially pass a WP_Error
object, when previously they only passed null|stdClass|false
.
TimothyBJacobs commented on PR #914:
4 years ago
#3
This is the nitiest of nits, but why no period on the error messages?
peterwilsoncc commented on PR #914:
4 years ago
#5
Thanks for the replies @johnbillion, this all looks good to me. Your reply about setting the array/updating option response makes sense.
#6
@
4 years ago
The changes to the pre_*
filters which means the $pre
value can be a WP_Error
after this change might have more of an impact than I thought. Looking through some plugin directory scans now.
#7
@
4 years ago
Okay false alarm. We're all good. Only WP-Optimize needs an update for its back-compat function.
pre_schedule_event
- https://wordpress.org/plugins/gdpress/ - no problem
pre_reschedule_event
- No plugins affected
pre_unschedule_event
- https://wordpress.org/plugins/wp-crontrol/ - no problem
pre_clear_scheduled_hook
- No plugins affected
pre_unschedule_hook
- https://wordpress.org/plugins/wp-optimize/ - Conditionally defines
wp_unschedule_hook()
if it doesn't exist. Will need to be updated with the new function signature.
In addition I checked Cavalcade, Cron Control, Action Scheduler, and WP Background Processing. Cavalcade will gracefully handle a WP_Error
in all the $pre
parameters with no change, and the others don't use the affected filters.
#8
@
4 years ago
- Owner set to johnbillion
- Resolution set to fixed
- Status changed from new to closed
In 50143:
Trac ticket: https://core.trac.wordpress.org/ticket/49961