YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.21k stars 403 forks source link

PUC on shared hosting #566

Closed hupe13 closed 5 months ago

hupe13 commented 5 months ago

My WordPress installations are on shared hosting. PUC works on one, but not on the other because of the limit. You need a token.

If you need a token and don't have one, every check to Github fails and you get an error: 403. puc-github-http-error Is it possible to check this and ask the user to configure a token? I have such a setting in my plugin, but how can I detect if the user needs a token to access Github?

Thank you very much.

YahnisElsts commented 5 months ago

There's not an easy way to do that. I think the best option might be to use the puc_api_error action and inspect the arguments to see if it's the kind of error that you care about. This action receives one to four arguments:

  1. A WP_Error instance describing the error. This could be a custom error, or an error object returned by wp_remote_get().
  2. The response array returned by wp_remote_get(). Will be null if wp_remote_get() returned a WP_Error. Can be omitted entirely if the error being reported is not an HTTP error. For example, puc_api_error is also triggered for some parsing errors.
  3. The requested API URL, if any.
  4. The plugin or theme slug. Use this to verify that the error is related to your plugin.

All arguments beyond the first one are optional. Note that even the last one (slug) can be omitted in certain cases.

hupe13 commented 5 months ago

The request is already done, I would like to detect the error 403. I searched puc_api_error in the issues and found this function and used it. Maybe the code is not optimal, but it works (I hope).

YahnisElsts commented 5 months ago

FYI, if the HTTP response is available, you might be able to get the code easier by using wp_remote_retrieve_response_code().

hupe13 commented 5 months ago

Cool! Thank you very much! You should write add_action( 'puc_api_error', .... ) in the documentation.