plugins_api()
最后更新于:2021-11-27 18:46:09
plugins_api( string$action, array|object$args=array())Retrieves plugin installer pages from the GeChiUI.org Plugins API.
参数
- $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 GeChiUI version. Default true. -
‘requires_php’
(bool) Whether to return the required PHP 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 gechiui.org repository. Default true. -
‘tags’
(bool) Whether to return the assigned tags. Default true. -
‘compatibility’
(bool) Whether to return the GeChiUI 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.
-
‘short_description’
Default value: array()
-
‘slug’
响应
(object|array|GC_Error) Response object or array on success, GC_Error on failure. See the function reference article for more information on the make-up of possible return values depending on the value of $action
.
源文件
文件: gc-admin/includes/plugin-install.php
function plugins_api( $action, $args = array() ) {
// Include an unmodified $gc_version.
require ABSPATH . GCINC . '/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->gc_version ) ) {
$args->gc_version = substr( $gc_version, 0, 3 ); // x.y
}
/**
* Filters the GeChiUI.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 GeChiUI.org Plugin Installation API request.
*
* Passing a non-false value will effectively short-circuit the GeChiUI.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.gechiui.org/plugins/info/1.2/';
$url = add_query_arg(
array(
'action' => $action,
'request' => $args,
),
$url
);
$http_url = $url;
$ssl = gc_http_supports( array( 'ssl' ) );
if ( $ssl ) {
$url = set_url_scheme( $url, 'https' );
}
$http_args = array(
'timeout' => 15,
'user-agent' => 'GeChiUI/' . $gc_version . '; ' . home_url( '/' ),
);
$request = gc_remote_get( $url, $http_args );
if ( $ssl && is_gc_error( $request ) ) {
if ( ! gc_is_json_request() ) {
trigger_error(
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with GeChiUI.org or this server’s configuration. If you continue to have problems, please try the <a href="https://docs.gechiui.com/functions/plugins_api/%s">support forums</a>.' ),
__( 'https://gechiui.org/support/forums/' )
) . ' ' . __( '(GeChiUI could not establish a secure connection to GeChiUI.org. Please contact your server administrator.)' ),
headers_sent() || GC_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
}
$request = gc_remote_get( $http_url, $http_args );
}
if ( is_gc_error( $request ) ) {
$res = new GC_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with GeChiUI.org or this server’s configuration. If you continue to have problems, please try the <a href="https://docs.gechiui.com/functions/plugins_api/%s">support forums</a>.' ),
__( 'https://gechiui.org/support/forums/' )
),
$request->get_error_message()
);
} else {
$res = json_decode( gc_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 GC_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with GeChiUI.org or this server’s configuration. If you continue to have problems, please try the <a href="https://docs.gechiui.com/functions/plugins_api/%s">support forums</a>.' ),
__( 'https://gechiui.org/support/forums/' )
),
gc_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new GC_Error( 'plugins_api_failed', $res->error );
}
}
} elseif ( ! is_gc_error( $res ) ) {
$res->external = true;
}
/**
* Filters the Plugin Installation API response results.
*
* @since 2.7.0
*
* @param object|GC_Error $res Response object or GC_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 );
}
$fields = array( 'active_installs' => true, // rounded int 'added' => true, // date 'author' => true, // a href html 'author_block_count' => true, // int 'author_block_rating' => true, // int 'author_profile' => true, // url 'banners' => true, // array( [low], [high] ) 'compatibility' => false, // empty array? 'contributors' => true, // array( array( [profile], [avatar], [display_name] ) 'description' => false, // string 'donate_link' => true, // url 'download_link' => true, // url 'downloaded' => false, // int // 'group' => false, // n/a 'homepage' => true, // url 'icons' => false, // array( [1x] url, [2x] url ) 'last_updated' => true, // datetime 'name' => true, // string 'num_ratings' => true, // int 'rating' => true, // int 'ratings' => true, // array( [5..0] ) 'requires' => true, // version string 'requires_php' => true, // version string // 'reviews' => false, // n/a, part of 'sections' 'screenshots' => true, // array( array( [src], ) ) 'sections' => true, // array( [description], [installation], [changelog], [reviews], ...) 'short_description' => false, // string 'slug' => true, // string 'support_threads' => true, // int 'support_threads_resolved' => true, // int 'tags' => true, // array( ) 'tested' => true, // version string 'version' => true, // version string 'versions' => true, // array( [version] url ) );