钩子文档

after_plugin_row_{$plugin_file}

💡 云策文档标注

概述

after_plugin_row_{$plugin_file} 是一个 WordPress 动作钩子,在插件列表表格的每个特定行后触发,主要用于在插件管理页面添加自定义内容或警告信息。

关键要点

  • 钩子名称包含动态部分 $plugin_file,表示插件文件相对于 plugins 目录的路径。
  • 参数包括 $plugin_file(插件文件路径)、$plugin_data(插件数据数组)和 $status(插件状态过滤值)。
  • 可用于在插件更新时添加额外行,例如显示警告消息或升级详情。
  • 状态参数 $status 的可能值包括 'all'、'active'、'inactive' 等,从 WordPress 5.5.0 起新增 'auto-update-enabled' 和 'auto-update-disabled'。

注意事项

  • 钩子常用于插件更新场景,通过比较 $plugin_data['new_version'] 来检测是否需要显示警告。
  • 参数 $plugin_file 在钩子名称中已包含,可能略显冗余,但提供了额外访问方式。

📄 原文内容

Fires after each specific row in the Plugins list table.

Description

The dynamic portion of the hook name, $plugin_file, refers to the path to the plugin file, relative to the plugins directory.

Parameters

$plugin_filestring
Path to the plugin file relative to the plugins directory.
$plugin_dataarray
An array of plugin data. See get_plugin_data() and the ‘plugin_row_meta’ filter for the list of possible values.
$statusstring
Status filter currently applied to the plugin list.
Possible values are: 'all', 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'.

Source

do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );

Changelog

Version Description
5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled' to possible values for $status.
2.7.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    This an action on which the update link information is hooked. When a plugin is found to have an updated version, an additional row is added after the plugin entry (on the plugins.php admin page), enabling a user to view the update details as well as upgrade.

    Most users simply upgrade and hope for the best without necessarily looking at the details and this hook is a means to add a warning message on the upgrade link for example, asking a user to view the details in case a major code change may affect their setup.

    The parameters passed in the filter are,
    $plugin_file – this is a little redundant as the hook already has the file name in it
    $plugin_data – an array of plugin attributes which is useful to set some conditions, see below.
    $status – if the plugins page is being filtered (for example to show only the activated ones), by default it is set to all.

    You could compare your currently installed plugin version to the $plugin_data['new_version'] to determine if you need to show some warning message or something else.