Allow download_url for lan addresses

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.

1 Answer
1

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);

Leave a Comment