Skip to content

Allow WP_HTTP request in WordPress

How to allow important API calls using WP_HTTP requests so they are not blocked by “Smart Block” optimization mode in HTTP Requests Manager plugin? In this tutorial we are going to find important API calls, manually add the Allow rule to them then check if the custom rule works.

Recently while taking manual backup of my WordPress database to google drive I encountered an error. I use the UpdraftPlus plugin for backups. Backup error was showing “(Not finished)” message.

To solve the problem I needed to add an “Allow” rule in the HTTP Requests Manager plugin.

Allow important WP_HTTP request in WordPress

Video tutorial explaining how to allow important API calls.

https://youtu.be/F10ri38bpdU

Watch a video tutorial on YouTube.

Find Important WP_HTTP requests

Find important WP_HTTP requests (API calls) in logs.

Use HTTP Requests Manager plugin to find important WP_HTTP (API) calls.

  1. Navigate to “Tools”→ “HTTP requests manager” page from WordPress dashboard.
  2. Page opens and loads the latest records.
  3. Check for plugins for example UpdraftPlus plugin.  It takes backup of my WordPress website to Google Drive. We see that it’s blocked because of page timeout so we want to make sure that this request is always allowed and will never be blocked by “Smart block”.

“Smart block” mode is used to optimize WP_HTTP usage in WordPress websites. Learn more about “Smart block” optimization.

Now let’s look at how to always allow API calls.

Allow WP_HTTP request manually

Add Custom Rule to allow WP_HTTP request by plugin in Smart Block optimization mode.

HTTP Requests Manager plugin applies “Smart Block” rules to optimize WP_HTTP requests in WordPress website. As part of optimization some requests will be blocked on slow pages. We do not want important API calls to be blocked at all.

Lets add “Custom Rule” to always allow Updraftplus plugin API calls.

  1. Go to the “Settings” tab for adding custom rules to “smart block” mode.
  2. Click add new button and new form will open.
  3. Select “Plugin” → “Updraftplus” from dropdowns for the “What” field.
  4. On “Action” field select “Allow”
  5. Click the “Save Changes” button.

Allow WP_HTTP rule added to HTTP Requests Manager plugin

You can see the newly added custom rule to allow the UpdraftPlus plugin everywhere.

Alternatively you can add a rule for domain instead of plugin. This is useful when a plugin uses one API for storing backups and another API to load latest news. You can create a rule to allow an API that uploads backups to Google Drive and block other API that loads news from feedburner.

Check that new custom rule allows to store backups in Google Drive

We want to make sure that it works.

Click Backup Now button to test if allow rule works.

Navigate to the UpdraftPlus plugin page and click on the “Backup Now” button.

Select to backup database and send to remote storage (Google Drive) to see if it works.

On the opened window select “Include your database in the backup” and “Send this backup to remote storage” checkboxes.

Then click on the “Backup now” button.

This would take your database backup and send it to Google Drive which was initially setup with the plugin.

Before and After adding Allow rule for WP_HTTP request. Now backup sent to remote storage without problem.
After completing the backup new backup info will be added without any errors.

From the above screenshot you can see that before adding “allow” rule backup was not finished.

After adding “Allow” rule backup finished without any error.

Before and After adding Allow WP_HTTP rule, check log for request status. You will see that API call is allowed now.

Here is how it looks like in HTTP Request Manager after adding the “Allow” custom rule to “Smart Block” mode.

We can see that page time took 33 seconds and request time took more than 5 seconds. And this request by the UpdraftPlus plugin was not blocked.

FAQ

Are all WP_HTTP requests (API calls) allowed in WordPress by default?

Yes, all WP_HTTP requests also known as API calls are allowed by default in WordPress.

We may need to create a custom rule for allowing important API calls only if we are using HTTP Requests Manager plugin in “Smart block” operation mode.

Which operation mode of HTTP Request Manager will not block any requests?

Only Log HTTP Requests mode will not block any WP_HTTP requests.

“Only log HTTP requests” and “Only log HTTP requests (+ cron requests)” operation modes in HTTP Requests Manager plugin will not block or limit WP_HTTP requests. You can use them for debugging and analyzing requests without blocking.

On which pages in “Smart Block” mode WP_HTTP API calls are not limited?

Cron pages are not limited by page timeout. Because cron is designed to perform slow and regular tasks without affecting WordPress speed. Users do not wait until cron finishes. For this reason it is ok to have multiple WP_HTTP requests in cron jobs. Also page generation time limit is not applied on cron pages.

All WP_HTTP API calls inside cron jobs will not be blocked by “Smart block” operation mode.

How to debug WP_HTTP requests?

Install and activate HTTP requests manager plugin. In the “Settings” tab select operation mode. Default is “Smart block”. Switch to “Only log HTTP requests” mode If you do not want to block any requests.

Then wait a couple hours or days to add some logs to the report. Visit “Log” page to see recorded requests. Click on request to learn more, view request data, response data, time taken to complete request and time taken to generate page.

More detailed WP_HTTP requests debugging with examples can be viewed here.

Can I block useless API calls in the same way?

Yes, select “Action” → “Block” instead of “Allow”.

In some cases you may want to block some useless WP_HTTP requests in order to improve WordPress performance further. Check this tutorial for blocking individual WP_HTTP requests.

How to remove previously added allow rules in HTTP Requests Manager plugin?

Remove previously added Allow WP_HTTP request rule by clicking (x) button next to rule.

  1. Navigate to the “Settings” tab from the plugin page.
  2. Find a “Custom rule” that you want to remove.
  3. Click the “x” button at the end of the rule line.

Conclusion

“Smart block” mode in HTTP Requests Manager plugin is great for optimizing most WordPress websites WP_HTTP requests. It will work on 99% of websites without problem.

Some WordPress websites use important plugins for taking backups, sending mails, getting analytics, generating payment buttons that rely on external API calls. In order to make sure that those important API calls are never blocked you can create an “Allow” custom rule for them. Use a plugin or domain for precisely creating the “Allow” rule.

Manually allowing certain requests will optimize WP_HTTP usage and make sure that important API calls will always work.

Get free HTTP Requests Manager plugin for optimizing WP_HTTP usage in your WordPress website.

Leave a Reply

Your email address will not be published. Required fields are marked *