YahnisElsts/wp-update-server

Get API Response

Opened this issue · 1 comments

Hi there,

awesome plugin! Is it possible to get the API results after calling the URL? I tried var dumping the class but there is no info about the original response request.

I need that to show the customer an error that the updater API may return (like no plugin found / license not valid).

There are several ways you could do that. One option would be to use the $prefix_request_metadata_http_result-$slug filter. For example:

$updateChecker->addFilter('request_metadata_http_result', function($httpResponse) {
    //Do something with $httpResponse here. It's the value returned by wp_remote_get().
    //Remember to return the response.
    return $httpResponse;
});

The actual filter name changed depending on the plugin/theme, so I'm using the addFilter() method for convenience. If necessary, you do something like this instead:

add_filter('puc_request_metadata_http_result-myplugin', 'my_callback_function');

Alternatively, the $prefix_request_info_result-$slug filter is also an option. It is called after the plugin metadata has already been parsed.

$updateChecker->addFilter('request_info_result', function($pluginInfo, $httpResponse) {
    //$pluginInfo is an object that pretty much maps directly to the contents of the API response.
    return $pluginInfo;
}, 10, 2);