plugins_api()

 

File: wp-admin/includes/plugin-install.php

function plugins_api( $action, $args = array() ) {
	// include an unmodified $wp_version
	include( ABSPATH . WPINC . '/version.php' );

	if ( is_array( $args ) ) {
		$args = (object) $args;
	}

	if ( 'query_plugins' == $action ) {
		if ( ! isset( $args->per_page ) ) {
			$args->per_page = 24;
		}
	}

	if ( ! isset( $args->locale ) ) {
		$args->locale = get_user_locale();
	}

	if ( ! isset( $args->wp_version ) ) {
		$args->wp_version = substr( $wp_version, 0, 3 ); // X.y
	}

	/**
	 * Filters the WordPress.org Plugin Installation API arguments.
	 *
	 * Important: An object MUST be returned to this filter.
	 *
	 * @since 2.7.0
	 *
	 * @param object $args   Plugin API arguments.
	 * @param string $action The type of information being requested from the Plugin Installation API.
	 */
	$args = apply_filters( 'plugins_api_args', $args, $action );

	/**
	 * Filters the response for the current WordPress.org Plugin Installation API request.
	 *
	 * Passing 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' or 'hot_categories', an array should be passed.
	 *
	 * @since 2.7.0
	 *
	 * @param false|object|array $result The result object or array. Default false.
	 * @param string             $action The type of information being requested from the Plugin Installation API.
	 * @param object             $args   Plugin API arguments.
	 */
	$res = apply_filters( 'plugins_api', false, $action, $args );

	if ( false === $res ) {

		$url = 'http://api.wordpress.org/plugins/info/1.2/';
		$url = add_query_arg(
			array(
				'action'  => $action,
				'request' => $args,
			),
			$url
		);

		$http_url = $url;
		if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
			$url = set_url_scheme( $url, 'https' );
		}

		$http_args = array(
			'timeout'    => 15,
			'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
		);
		$request   = wp_remote_get( $url, $http_args );

		if ( $ssl && is_wp_error( $request ) ) {
			trigger_error(
				sprintf(
					/* translators: %s: support forums URL */
					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
					__( 'https://wordpress.org/support/' )
				) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
				headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
			);
			$request = wp_remote_get( $http_url, $http_args );
		}

		if ( is_wp_error( $request ) ) {
			$res = new WP_Error(
				'plugins_api_failed',
				sprintf(
					/* translators: %s: support forums URL */
					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
					__( 'https://wordpress.org/support/' )
				),
				$request->get_error_message()
			);
		} else {
			$res = json_decode( wp_remote_retrieve_body( $request ), true );
			if ( is_array( $res ) ) {
				// Object casting is required in order to match the info/1.0 format.
				$res = (object) $res;
			} elseif ( null === $res ) {
				$res = new WP_Error(
					'plugins_api_failed',
					sprintf(
						/* translators: %s: support forums URL */
						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
						__( 'https://wordpress.org/support/' )
					),
					wp_remote_retrieve_body( $request )
				);
			}

			if ( isset( $res->error ) ) {
				$res = new WP_Error( 'plugins_api_failed', $res->error );
			}
		}
	} elseif ( ! is_wp_error( $res ) ) {
		$res->external = true;
	}

	/**
	 * Filters the Plugin Installation API response results.
	 *
	 * @since 2.7.0
	 *
	 * @param object|WP_Error $res    Response object or WP_Error.
	 * @param string          $action The type of information being requested from the Plugin Installation API.
	 * @param object          $args   Plugin API arguments.
	 */
	return apply_filters( 'plugins_api_result', $res, $action, $args );
}

参数:plugins_api( string $action, array|object $args = array() )

插件可以用三个过滤器覆盖插件API结果。假设这是针对插件的,插件可以扩展插件信息以提供更多选择。这非常强大,在覆盖过滤器时必须小心使用。

第一个过滤器‘插件_API_Args’用于args,并将操作作为第二个参数给出。‘插件的钩子_api_args’必须确保返回对象。

第二个过滤器‘插件API’允许插件完全覆盖wordpress.org插件安装API。如果$action是‘查询插件’或‘插件信息’,则必须传递对象。如果$action是‘Hot_Tags’或‘Hot_Categories’,则必须传递数组。

最后,第三个过滤器‘插件_API_Result’使筛选响应对象或数组成为可能,具体取决于$action类型。

每个操作支持的参数:

参数名 查询插件 插件信息 热标签 热类别
$蛞蝓 是的
佩尔佩奇 是的
$PAGE 是的
美元数 是的 是的
美元搜索 是的
美元标签 是的
撰稿人 是的
$用户 是的
$浏览 是的
区域设置 是的 是的
$installed_插件 是的
ISSSSL 是的 是的
$字段 是的 是的

API action to perform: 'query_plugins', 'plugin_information', 'hot_tags' or 'hot_categories'.Array or object of arguments to serialize for the Plugin Info API.

  • “slug”
    (字符串)插件slug。
  • “每页”
    (int)每页插件数。默认值24。
  • “page”
    (int)当前页的编号。默认值1。
  • 'number'
    (int)要查询的标记或类别的数目。
  • “search”
    (字符串)一个搜索词。
  • “tag”
    (字符串)标记用于筛选插件。
  • 用于筛选插件的插件作者的“author”
    (string)用户名。
  • “user”
    (字符串)用户名,用于查询其收藏夹。
  • 'browse'
    (string)浏览视图:'popular'、'new'、'beta'、'recommended'。
  • “locale”
    (字符串)locale提供上下文相关的结果。默认值是get_locale()的值。
  • “installed_plugins”
    (字符串)安装了插件,以提供上下文相关的结果。
  • 'is_ssl'
    (bool)是否应使用https返回链接。默认为false。
  • 应返回或不应返回的字段的“字段”
    (数组)数组。简短描述“
    (bool)是否返回插件简短描述。默认为true。说明'
    (bool)是否返回插件完整说明。默认值为false。'部分的
    (bool)是否返回插件自述文件部分:描述、安装、常见问题解答、屏幕截图、其他注释和更改日志。默认值为false。'已测试“
    (bool)”是否返回“兼容上限”值。默认为true。需要'
    (bool)是否返回所需的WordPress版本。默认为true。评级“
    (bool)”是否返回评级百分比和总评级数。默认为true。评级“
    (bool)”是否返回每颗星的评级数(1-5)。默认为true。已下载'
    (bool)是否返回下载计数。默认为true。DownloadLink'
    (bool)是否返回包的下载链接。默认为true。上次更新的
    (bool)是否返回上次更新的日期。默认为true。添加了“
    (bool)”是否返回插件添加到wordpress.org存储库的日期。默认为true。标记“
    (bool)”是否返回分配的标记。默认为true。兼容性“
    (bool)是否返回WordPress兼容性列表。默认为true。主页“
    (bool)是否返回插件主页链接。默认为true。版本
    (bool)是否返回所有可用版本的列表。默认值为false。'捐赠链接
    (bool)是否返回捐赠链接。默认为true。评论
    (bool)是否返回插件评论。默认值为“假”。横幅的
    (bool)是否返回横幅图像链接。默认值为“假”。图标
    (bool)是否返回图标链接。默认值为“假”。active_installs'
    (bool)是否返回活动安装的数量。默认值为“假”。组“
    (bool)是否返回分配的组。默认值为“假”。投稿人
    (bool)是否返回投稿人列表。默认为false。

(对象数组wp_错误)响应对象或数组成功,wp_错误失败。有关根据$action的值组成可能的返回值的更多信息,请参阅函数参考文章。

$action

(string)
(Required)
API action to perform: 'query_plugins', 'plugin_information', 'hot_tags' or 'hot_categories'.

$args

(array|object)
(Optional)
Array or object of arguments to serialize for the Plugin Info API.

  • 'slug'
    (string) The plugin slug.
  • 'per_page'
    (int) Number of plugins per page. Default 24.
  • 'page'
    (int) Number of current page. Default 1.
  • 'number'
    (int) Number of tags or categories to be queried.
  • 'search'
    (string) A search term.
  • 'tag'
    (string) Tag to filter plugins.
  • 'author'
    (string) Username of an plugin author to filter plugins.
  • 'user'
    (string) Username to query for their favorites.
  • 'browse'
    (string) Browse view: 'popular', 'new', 'beta', 'recommended'.
  • 'locale'
    (string) Locale to provide context-sensitive results. Default is the value of get_locale().
  • 'installed_plugins'
    (string) Installed plugins to provide context-sensitive results.
  • 'is_ssl'
    (bool) Whether links should be returned with https or not. Default false.
  • 'fields'
    (array) Array of fields which should or should not be returned.
    • 'short_description'
      (bool) Whether to return the plugin short description. Default true.
    • 'description'
      (bool) Whether to return the plugin full description. Default false.
    • 'sections'
      (bool) Whether to return the plugin readme sections: description, installation, FAQ, screenshots, other notes, and changelog. Default false.
    • 'tested'
      (bool) Whether to return the 'Compatible up to' value. Default true.
    • 'requires'
      (bool) Whether to return the required WordPress version. Default true.
    • 'rating'
      (bool) Whether to return the rating in percent and total number of ratings. Default true.
    • 'ratings'
      (bool) Whether to return the number of rating for each star (1-5). Default true.
    • 'downloaded'
      (bool) Whether to return the download count. Default true.
    • 'downloadlink'
      (bool) Whether to return the download link for the package. Default true.
    • 'last_updated'
      (bool) Whether to return the date of the last update. Default true.
    • 'added'
      (bool) Whether to return the date when the plugin was added to the wordpress.org repository. Default true.
    • 'tags'
      (bool) Whether to return the assigned tags. Default true.
    • 'compatibility'
      (bool) Whether to return the WordPress compatibility list. Default true.
    • 'homepage'
      (bool) Whether to return the plugin homepage link. Default true.
    • 'versions'
      (bool) Whether to return the list of all available versions. Default false.
    • 'donate_link'
      (bool) Whether to return the donation link. Default true.
    • 'reviews'
      (bool) Whether to return the plugin reviews. Default false.
    • 'banners'
      (bool) Whether to return the banner images links. Default false.
    • 'icons'
      (bool) Whether to return the icon links. Default false.
    • 'active_installs'
      (bool) Whether to return the number of active installations. Default false.
    • 'group'
      (bool) Whether to return the assigned group. Default false.
    • 'contributors'
      (bool) Whether to return the list of contributors. Default false.

Default value: array()

{acontent3}

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

33.33% (2) 次Baidu访问
66.67% (4) 次Sogou访问
  • 蜘蛛:Baidu,2次,更新时间:2019-04-28 17:22:13
  • 蜘蛛:Sogou,4次,更新时间:2019-05-13 01:16:37

参与评论