Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get API Response #92

Open
danielbarenkamp opened this issue Jan 9, 2021 · 1 comment
Open

Get API Response #92

danielbarenkamp opened this issue Jan 9, 2021 · 1 comment

Comments

@danielbarenkamp
Copy link

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).

@YahnisElsts
Copy link
Owner

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants