The cron_request WordPress PHP filter modifies the cron request arguments.
Usage
add_filter('cron_request', 'my_custom_cron_request', 10, 2); function my_custom_cron_request($cron_request_array, $doing_wp_cron) { // Your custom code here return $cron_request_array; }
Parameters
- $cron_request_array (array): An array of cron request URL arguments.
- url (string): The cron request URL.
- key (int): The 22 digit GMT microtime.
- args (array): An array of cron request arguments.
- timeout (int): The request timeout in seconds. Default .01 seconds.
- blocking (bool): Whether to set blocking for the request. Default false.
- sslverify (bool): Whether SSL should be verified for the request. Default false.
- $doing_wp_cron (string): The unix timestamp of the cron lock.
More information
See WordPress Developer Resources: cron_request
Examples
Change cron request timeout
Increase the cron request timeout to 5 seconds.
add_filter('cron_request', 'change_cron_request_timeout', 10, 2); function change_cron_request_timeout($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['timeout'] = 5; return $cron_request_array; }
Set SSL verification for cron requests
Enable SSL verification for cron requests.
add_filter('cron_request', 'set_cron_ssl_verification', 10, 2); function set_cron_ssl_verification($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['sslverify'] = true; return $cron_request_array; }
Set blocking for cron requests
Enable blocking for cron requests.
add_filter('cron_request', 'set_cron_blocking', 10, 2); function set_cron_blocking($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['blocking'] = true; return $cron_request_array; }
Change cron request URL
Modify the cron request URL to a custom URL.
add_filter('cron_request', 'change_cron_request_url', 10, 2); function change_cron_request_url($cron_request_array, $doing_wp_cron) { $cron_request_array['url'] = 'https://example.com/my-custom-cron-url'; return $cron_request_array; }
Add custom argument to cron request
Add a custom argument to the cron request args array.
add_filter('cron_request', 'add_custom_cron_argument', 10, 2); function add_custom_cron_argument($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['custom_arg'] = 'my_value'; return $cron_request_array; }Change cron request timeout
Increase the cron request timeout to 5 seconds.
add_filter('cron_request', 'change_cron_request_timeout', 10, 2); function change_cron_request_timeout($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['timeout'] = 5; return $cron_request_array; }
Set SSL verification for cron requests
Enable SSL verification for cron requests.
add_filter('cron_request', 'set_cron_ssl_verification', 10, 2); function set_cron_ssl_verification($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['sslverify'] = true; return $cron_request_array; }
Set blocking for cron requests
Enable blocking for cron requests.
add_filter('cron_request', 'set_cron_blocking', 10, 2); function set_cron_blocking($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['blocking'] = true; return $cron_request_array; }
Change cron request URL
Modify the cron request URL to a custom URL.
add_filter('cron_request', 'change_cron_request_url', 10, 2); function change_cron_request_url($cron_request_array, $doing_wp_cron) { $cron_request_array['url'] = 'https://example.com/my-custom-cron-url'; return $cron_request_array; }
Add custom argument to cron request
Add a custom argument to the cron request args array.
add_filter('cron_request', 'add_custom_cron_argument', 10, 2); function add_custom_cron_argument($cron_request_array, $doing_wp_cron) { $cron_request_array['args']['custom_arg'] = 'my_value'; return $cron_request_array; }