Skip to content

Instantly share code, notes, and snippets.

@saas786
Created September 7, 2017 06:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saas786/a567363477df7e28b0c1df6295cadf75 to your computer and use it in GitHub Desktop.
Save saas786/a567363477df7e28b0c1df6295cadf75 to your computer and use it in GitHub Desktop.
WordPress annoying issue, while working locally using http api you keep getting "A valid URL was not provided", or using functions such as "wp_safe_remote_request,wp_safe_remote_get or wp_safe_remote_post" and you are unable to request local website and you are not sure why its not working, because same code work on live.
<?php
/**
* Plugin Name: Allow localhost http requests.
* Plugin URI: https://gist.github.com/saas786/a567363477df7e28b0c1df6295cadf75/
* Description: Note: Please don't use it on live website. If you are working locally, sometimes you get errors such as "A valid URL was not provided" or such, specially when you are interacting with website which is also hosted locally, so it becomes annoying at times to find the cause, and most of the time its wp_safe_remote_request, wp_safe_remote_get or wp_safe_remote_post functions who are the culprit. So this plugin is a quick fix.
* Author: saas786
* Version: 0.1
*/
add_filter( 'http_request_host_is_external', 'wplr_http_request_host_is_external' );
function wplr_http_request_host_is_external(){
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment