钩子文档

plugins_api

💡 云策文档标注

概述

plugins_api 过滤器用于拦截和修改 WordPress.org 插件安装 API 的响应。通过返回非 false 值,可以绕过默认的 API 请求,自定义返回数据。

关键要点

  • 过滤器名称:plugins_api,用于处理插件安装 API 请求的响应。
  • 参数:$result(默认 false,可返回对象或数组)、$action(请求类型,如 'query_plugins' 或 'plugin_information')、$args(API 参数对象)。
  • 返回值:根据 $action 类型,必须返回对象(用于 'query_plugins' 或 'plugin_information')或数组(用于 'hot_tags')。
  • 相关函数:plugins_api() 用于从 WordPress.org 插件 API 检索信息。
  • 版本历史:自 WordPress 2.7.0 引入。

📄 原文内容

Filters the response for the current WordPress.org Plugin Installation API request.

Description

Returning a non-false value will effectively short-circuit the WordPress.org API request.

If $action is ‘query_plugins’ or ‘plugin_information’, an object MUST be passed.
If $action is ‘hot_tags’, an array should be passed.

Parameters

$resultfalse|object|array
The result object or array. Default false.
$actionstring
The type of information being requested from the Plugin Installation API.
$argsobject
Plugin API arguments.

Source

$res = apply_filters( 'plugins_api', false, $action, $args );

Changelog

Version Description
2.7.0 Introduced.