函数文档

wp_is_auto_update_forced_for_item()

💡 云策文档标注

概述

wp_is_auto_update_forced_for_item() 函数用于检查特定项目(主题或插件)是否被强制启用自动更新。它通过应用过滤器 auto_update_{$type} 来返回布尔值,指示更新是否被强制。

关键要点

  • 函数接受三个参数:$type(字符串,必须为 'theme' 或 'plugin')、$update(布尔值或 null,用于检测是否有钩子挂入过滤器)、$item(对象,更新项目)。
  • 返回布尔值:true 表示自动更新被强制,false 表示未被强制。
  • 内部实现基于 apply_filters() 调用,允许通过过滤器 auto_update_{$type} 自定义更新行为。
  • 此函数自 WordPress 5.6.0 版本引入,主要用于调试数据、站点健康检查和主题/插件列表准备等场景。

代码示例

function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
    /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    return apply_filters( "auto_update_{$type}", $update, $item );
}

📄 原文内容

Checks whether auto-updates are forced for an item.

Parameters

$typestringrequired
The type of update being checked: Either 'theme' or 'plugin'.
$updatebool|nullrequired
Whether to update. The value of null is internally used to detect whether nothing has hooked into this filter.
$itemobjectrequired
The update offer.

Return

bool True if auto-updates are forced for $item, false otherwise.

Source

function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
	/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
	return apply_filters( "auto_update_{$type}", $update, $item );
}

Hooks

apply_filters( “auto_update_{$type}”, bool|null $update, object $item )

Filters whether to automatically update core, a plugin, a theme, or a language.

Changelog

Version Description
5.6.0 Introduced.