plugin_row_meta
云策文档标注
概述
plugin_row_meta 是一个 WordPress 过滤器钩子,用于在插件列表页面中为每个插件添加额外的元数据链接。开发者可以通过此钩子自定义插件行下方的链接,如添加支持、文档或捐赠链接。
关键要点
- plugin_row_meta 过滤器允许修改插件在插件列表中的元数据数组,通常用于添加自定义链接。
- 该钩子接收四个参数:$plugin_meta(插件元数据数组)、$plugin_file(插件文件路径)、$plugin_data(插件数据数组)和 $status(插件状态)。
- 开发者应使用 add_filter 来挂接自定义函数,并确保函数返回修改后的 $plugin_meta 数组。
- 插件数据数组包含丰富信息,如版本、作者、URI、要求等,可用于条件逻辑。
代码示例
function prefix_append_support_and_faq_links( $links_array, $plugin_file_name, $plugin_data, $status ) {
if ( strpos( $plugin_file_name, basename(__FILE__) ) ) {
$links_array[] = 'FAQ';
$links_array[] = 'Support';
}
return $links_array;
}
add_filter( 'plugin_row_meta', 'prefix_append_support_and_faq_links', 10, 4 );注意事项
- 使用 strpos 或类似函数检查 $plugin_file 参数,以确保只针对特定插件添加链接。
- 可以通过 array_unshift 在数组开头添加链接,或使用 array_merge 合并新链接数组。
- 注意插件状态参数 $status 的可能值,如 'active'、'inactive' 等,可用于更精细的控制。
原文内容
Filters the array of row meta for each plugin in the Plugins list table.
Parameters
$plugin_metastring[]-
An array of the plugin’s metadata, including the version, author, author URI, and plugin URI.
$plugin_filestring-
Path to the plugin file relative to the plugins directory.
$plugin_dataarray-
An array of plugin data.
idstringPlugin ID, e.g.w.org/plugins/[plugin-name].slugstringPlugin slug.pluginstringPlugin basename.new_versionstringNew plugin version.urlstringPlugin URL.packagestringPlugin update package URL.iconsstring[]An array of plugin icon URLs.bannersstring[]An array of plugin banner URLs.banners_rtlstring[]An array of plugin RTL banner URLs.requiresstringThe version of WordPress which the plugin requires.testedstringThe version of WordPress the plugin is tested against.requires_phpstringThe version of PHP which the plugin requires.upgrade_noticestringThe upgrade notice for the new plugin version.update-supportedboolWhether the plugin supports updates.NamestringThe human-readable name of the plugin.PluginURIstringPlugin URI.VersionstringPlugin version.DescriptionstringPlugin description.AuthorstringPlugin author.AuthorURIstringPlugin author URI.TextDomainstringPlugin textdomain.DomainPathstringRelative path to the plugin’s .mo file(s).NetworkboolWhether the plugin can only be activated network-wide.RequiresWPstringThe version of WordPress which the plugin requires.RequiresPHPstringThe version of PHP which the plugin requires.UpdateURIstringID of the plugin for update purposes, should be a URI.TitlestringThe human-readable title of the plugin.AuthorNamestringPlugin author’s name.updateboolWhether there’s an available update. Default null.
$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
$plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 3 content
Mahdi Yazdani
/** * Filters the array of row meta for each/specific plugin in the Plugins list table. * Appends additional links below each/specific plugin on the plugins page. * * @access public * @param array $links_array An array of the plugin's metadata * @param string $plugin_file_name Path to the plugin file * @param array $plugin_data An array of plugin data * @param string $status Status of the plugin * @return array $links_array */ function prefix_append_support_and_faq_links( $links_array, $plugin_file_name, $plugin_data, $status ) { if ( strpos( $plugin_file_name, basename(__FILE__) ) ) { // You can still use `array_unshift()` to add links at the beginning. $links_array[] = '<a href="#">FAQ</a>'; $links_array[] = '<a href="#">Support</a>'; } return $links_array; } add_filter( 'plugin_row_meta', 'prefix_append_support_and_faq_links', 10, 4 );Skip to note 4 content
Steven Lin
Example Migrated from Codex:
Adds new links to the metadata array of the plugin.
add_filter( 'plugin_row_meta', 'custom_plugin_row_meta', 10, 2 ); function custom_plugin_row_meta( $plugin_meta, $plugin_file ) { if ( strpos( $plugin_file, 'plugin-file-name.php' ) !== false ) { $new_links = array( 'donate' => '<a href="donation_url" target="_blank">Donate</a>', 'doc' => '<a href="doc_url" target="_blank">Documentation</a>' ); $plugin_meta = array_merge( $plugin_meta, $new_links ); } return $plugin_meta; }