2

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.

3
  • 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. Commented Jul 17, 2018 at 9:04
  • 1
    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. Commented Jul 17, 2018 at 9:07
  • Is the server you're running the command on and the server with the file the same server? Commented Jul 17, 2018 at 9:19

1 Answer 1

3

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);
3
  • Where in the wp code shoud I put this code ? Commented Jul 17, 2018 at 9:26
  • 2
    I think that the better place for that is in a plugin codex.wordpress.org/Writing_a_Plugin
    – mmm
    Commented Jul 17, 2018 at 9:27
  • Thank you very much, it works. Shame! Shame! Why should I touch code in order to import content from another site? Grrrrrr Commented Apr 7, 2021 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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