wp_unschedule_hook
函数
wp_unschedule_hook ( $hook, $wp_error = false )
- 参数
-
-
(string)
$hook
Action hook, the execution of which will be unscheduled.- Required: 是
-
(bool)
$wp_error
Optional. Whether to return a WP_Error on failure. Default false.- Required: 否
- Default: false
-
(string)
- 返回值
-
- (int|false|WP_Error) On success an integer indicating number of events unscheduled (0 indicates no events were registered on the hook), false or WP_Error if unscheduling fails.
- 定义位置
-
-
wp-includes/cron.php
, line 641
-
wp-includes/cron.php
- 引入
- 4.9.0
- 弃用
- –
取消连接到钩子的所有事件的时间表。
在停用插件以清理cron队列时,可能会很有用。
警告:这个函数可能会返回布尔值FALSE,但也可能会返回一个非布尔值,该值会被评估为FALSE。关于向布尔值转换的信息请参见{@link PHP documentation}。使用`===`操作符来测试此函数的返回值。
function wp_unschedule_hook( $hook, $wp_error = false ) { /** * Filter to preflight or hijack clearing all events attached to the hook. * * Returning a non-null value will short-circuit the normal unscheduling * process, causing the function to return the filtered value instead. * * For plugins replacing wp-cron, return the number of events successfully * unscheduled (zero if no events were registered with the hook) or false * if unscheduling one or more events fails. * * @since 5.1.0 * @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned. * * @param null|int|false|WP_Error $pre Value to return instead. Default null to continue unscheduling the hook. * @param string $hook Action hook, the execution of which will be unscheduled. * @param bool $wp_error Whether to return a WP_Error on failure. */ $pre = apply_filters( 'pre_unschedule_hook', null, $hook, $wp_error ); if ( null !== $pre ) { if ( $wp_error && false === $pre ) { return new WP_Error( 'pre_unschedule_hook_false', __( 'A plugin prevented the hook from being cleared.' ) ); } if ( ! $wp_error && is_wp_error( $pre ) ) { return false; } return $pre; } $crons = _get_cron_array(); if ( empty( $crons ) ) { return 0; } $results = array(); foreach ( $crons as $timestamp => $args ) { if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) { $results[] = count( $crons[ $timestamp ][ $hook ] ); } unset( $crons[ $timestamp ][ $hook ] ); if ( empty( $crons[ $timestamp ] ) ) { unset( $crons[ $timestamp ] ); } } /* * If the results are empty (zero events to unschedule), no attempt * to update the cron array is required. */ if ( empty( $results ) ) { return 0; } $set = _set_cron_array( $crons, $wp_error ); if ( true === $set ) { return array_sum( $results ); } return $set; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。