Definition:
function plugins_api($action, $args = null) {}
Retrieve plugin installer pages from WordPress Plugins API.
It is possible for a plugin to override the Plugin API result with three filters. Assume this is for plugins, which can extend on the Plugin Info to offer more choices. This is very powerful and must be used with care, when overriding the filters.
Parameters
- string $action
- array|object $args: Optional. Arguments to serialize for the Plugin Info API.
Return values
returns:response object on success, WP_Error on failure.
Defined filters
- plugins_api_args
apply_filters('plugins_api_args', $args, $action)
- plugins_api
apply_filters('plugins_api', false, $action, $args)
- plugins_api_result
apply_filters('plugins_api_result', $res, $action, $args)
Source code
function plugins_api($action, $args = null) { if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) $args->per_page = 24; // Allows a plugin to override the WordPress.org API entirely. // Use the filter 'plugins_api_result' to mearly add results. // Please ensure that a object is returned from the following filters. $args = apply_filters('plugins_api_args', $args, $action); $res = apply_filters('plugins_api', false, $action, $args); if ( false === $res ) { $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) ); if ( is_wp_error($request) ) { $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() ); } else { $res = unserialize( wp_remote_retrieve_body( $request ) ); if ( false === $res ) $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) ); } } elseif ( !is_wp_error($res) ) { $res->external = true; } return apply_filters('plugins_api_result', $res, $action, $args); }
2511
No comments yet... Be the first to leave a reply!