I'm hosting a wp site on my own server (at home) and I would like to use wp cli to import media from my own computer. On my computer, I have a web server and I asks to wp-cli to import media from "http://192.168.0.2/wpTemp/media.txt".

It fails! After investigations, it is due to the ip address which is not recognized as "safe" by download_url() => wp_safe_remote_get().

Is there a way to configure wp to allow only 192.168.0.2 ? and keep the protection for everything else. (I'll also need to know where to put the modification, I don't want to redo the modification after wp update).

Thank you for your time!

The code of the problem: https://developer.wordpress.org/reference/functions/wp_http_validate_url/ line 566 return false and marks the url as invalid.

  • Are you using the wp import command to import? According to the docs you should be providing a path to a WXR file, not a URL. – Jacob Peattie Jul 17 at 9:04
  • wp media import - documentation here last example is using url. I spend a lot of time to know the real problem. The error message says "You provided a non valid URL". If I activate my VPN on my own computer and use the vpn ip address it works. I used "wp eval" to call the proper function of wp code. – ObiWanKennedy Jul 17 at 9:07
  • Is the server you're running the command on and the server with the file the same server? – Jacob Peattie Jul 17 at 9:19

to allow this IP as safe, use this filter

add_filter("http_request_host_is_external", function ($is, $host, $url) {

    if ("192.168.0.2" === $host) {
        $is = TRUE;
    }


    return $is;

}, 10, 3);

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.