钩子文档

cron_request

💡 云策文档标注

概述

cron_request 是一个 WordPress 过滤器,用于修改 cron 请求的参数数组,包括 URL、密钥和请求参数等。它允许开发者在发送 cron HTTP 请求前自定义设置。

关键要点

  • 过滤器名称:cron_request
  • 参数:$cron_request_array(数组),包含 URL、key、args 等 cron 请求参数
  • 用途:调整 cron 请求的超时、阻塞、SSL 验证等行为
  • 相关函数:spawn_cron() 使用此过滤器发送非阻塞的 cron 请求

代码示例

$cron_request = apply_filters(
    'cron_request',
    array(
        'url'  => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
        'key'  => $doing_wp_cron,
        'args' => array(
            'timeout'   => 0.01,
            'blocking'  => false,
            'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
        ),
    ),
    $doing_wp_cron
);

注意事项

  • 从 WordPress 4.5.0 版本开始,添加了 $doing_wp_cron 参数
  • 默认超时为 0.01 秒,阻塞为 false,SSL 验证为 false
  • 此过滤器在 spawn_cron() 函数中被调用,用于异步 cron 执行

📄 原文内容

Filters the cron request arguments.

Parameters

$cron_request_arrayarray
An array of cron request URL arguments.
  • url string
    The cron request URL.
  • key string
    The Unix timestamp (UTC) of the cron lock with microseconds.
  • 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_cronstring
The Unix timestamp (UTC) of the cron lock with microseconds.

Source

$cron_request = apply_filters(
	'cron_request',
	array(
		'url'  => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
		'key'  => $doing_wp_cron,
		'args' => array(
			'timeout'   => 0.01,
			'blocking'  => false,
			/** This filter is documented in wp-includes/class-wp-http-streams.php */
			'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
		),
	),
	$doing_wp_cron
);

Changelog

VersionDescription
4.5.0The $doing_wp_cron parameter was added.
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.