admin管理员组文章数量:1122832
I have a PHP(Laravel) application that pushes data to WooCommerce through the WooCommerce REST API, everything works except for images. I was able to pin this down to wp_safe_remote_get()
and $args['reject_unsafe_urls']
.
I had found a way around this, but I cannot recall where I found it. I seem to remember a hook in functions.php that turned off this feature. It wasn't recommended, but it is the only recourse.
Can anyone help me out? Or does anyone have another solution? I'm only pushing URLs from an application I made from the same server.
Code Example from External Application
$this->woocommerce->post('products', ['product' => $book_data_array])
where $this->woocommerce
is an instance of the WooCommerce API.
and $book_data_array
is an array of data. For an example of the data arra, see: '.html#create-a-product'
The only thing that doesn't work is images coming from the same server, which is a WordPress issue and has been confirmed as much by a WooCommerce dev. WordPress doesn't allow downloads from the same origin without an override.
I have a PHP(Laravel) application that pushes data to WooCommerce through the WooCommerce REST API, everything works except for images. I was able to pin this down to wp_safe_remote_get()
and $args['reject_unsafe_urls']
.
I had found a way around this, but I cannot recall where I found it. I seem to remember a hook in functions.php that turned off this feature. It wasn't recommended, but it is the only recourse.
Can anyone help me out? Or does anyone have another solution? I'm only pushing URLs from an application I made from the same server.
Code Example from External Application
$this->woocommerce->post('products', ['product' => $book_data_array])
where $this->woocommerce
is an instance of the WooCommerce API.
and $book_data_array
is an array of data. For an example of the data arra, see: 'http://woocommerce.github.io/woocommerce-rest-api-docs/wp-api-v1.html#create-a-product'
The only thing that doesn't work is images coming from the same server, which is a WordPress issue and has been confirmed as much by a WooCommerce dev. WordPress doesn't allow downloads from the same origin without an override.
Share Improve this question edited May 4, 2017 at 13:08 nobrandheroes asked May 4, 2017 at 12:13 nobrandheroesnobrandheroes 1136 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 1A safer way to archive the same result, since WP 5.1, is to use http_request_reject_unsafe_urls
filter:
function performize_turn_off_reject_unsafe_urls($ret, $url)
{
//here you can use regex or anything you want to check the url
if ($url==='https://urltowhitelist')
$ret = false;
return $ret;
}
add_filter( 'http_request_reject_unsafe_urls', 'performize_turn_off_reject_unsafe_urls', 10, 2 );
Also, http_request_args
use 2 parameters so if you want to use http_request_args
you can do it in this way:
function turn_off_reject_unsafe_urls($args, $url) {
if ($url === 'https://urltowhitelist')
$args['reject_unsafe_urls'] = false;
return $args;
}
add_filter( 'http_request_args', 'turn_off_reject_unsafe_urls', 10, 2);
This is the fix I found.
function turn_off_reject_unsafe_urls($args) {
$args['reject_unsafe_urls'] = false;
return $args;
}
add_filter( 'http_request_args', 'turn_off_reject_unsafe_urls');
本文标签: imagesBypass wpsaferemoteget()
版权声明:本文标题:images - Bypass wp_safe_remote_get()? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310683a1934467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_safe_remote_get
being called? By API I assume you mean the REST API? – Tom J Nowell ♦ Commented May 4, 2017 at 12:15wp_safe_remote_get
is being called wherever WordPress calls it, I'm not calling it anywhere specifically. My assumption is the WooCommerce REST API is using the native WordPress REST API. I do mean REST API. You assumed correctly. – nobrandheroes Commented May 4, 2017 at 12:23wp_safe_remote_get
to filter out URLs coming from the same server. – nobrandheroes Commented May 4, 2017 at 12:46