钩子文档

update_plugins_{$hostname}

💡 云策文档标注

概述

update_plugins_{$hostname} 是一个动态过滤器钩子,用于过滤特定插件主机名的更新响应。它允许开发者自定义插件更新数据,基于 Update URI 头字段中指定的主机名。

关键要点

  • 这是一个动态钩子,$hostname 部分对应 Update URI 头字段中的主机名。
  • 主要参数包括 $update(插件更新数据数组或 false)、$plugin_data(插件头信息)、$plugin_file(插件文件名)和 $locales(已安装的语言环境数组)。
  • 可用于修改插件更新细节,如版本、URL、包文件、自动更新设置等。
  • 在 WordPress 5.8.0 版本中引入。

代码示例

$update = apply_filters( "update_plugins_{$hostname}", false, $plugin_data, $plugin_file, $locales );

注意事项

  • 确保 $hostname 与插件 Update URI 头字段中的主机名匹配,否则钩子可能不会触发。
  • 参数 $update 可以是数组或 false,需根据上下文正确处理。
  • 翻译更新部分包含 language、version、updated 和 package 等字段,用于管理多语言支持。

📄 原文内容

Filters the update response for a given plugin hostname.

Description

The dynamic portion of the hook name, $hostname, refers to the hostname of the URI specified in the Update URI header field.

Parameters

$updatearray|false
The plugin update data with the latest details. Default false.
  • id string
    Optional. ID of the plugin for update purposes, should be a URI specified in the Update URI header field.
  • slug string
    Slug of the plugin.
  • version string
    The version of the plugin.
  • url string
    The URL for details of the plugin.
  • package string
    Optional. The update ZIP for the plugin.
  • tested string
    Optional. The version of WordPress the plugin is tested against.
  • requires_php string
    Optional. The version of PHP which the plugin requires.
  • autoupdate bool
    Optional. Whether the plugin should automatically update.
  • icons string[]
    Optional. Array of plugin icons.
  • banners string[]
    Optional. Array of plugin banners.
  • banners_rtl string[]
    Optional. Array of plugin RTL banners.
  • translations array
    Optional. List of translation updates for the plugin.
    • language string
      The language the translation update is for.
    • version string
      The version of the plugin this translation is for.
      This is not the version of the language file.
    • updated string
      The update timestamp of the translation file.
      Should be a date in the YYYY-MM-DD HH:MM:SS format.
    • package string
      The ZIP location containing the translation update.
    • autoupdate string
      Whether the translation should be automatically installed.
$plugin_dataarray
Plugin headers.
$plugin_filestring
Plugin filename.
$localesstring[]
Installed locales to look up translations for.

Source

$update = apply_filters( "update_plugins_{$hostname}", false, $plugin_data, $plugin_file, $locales );

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

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