Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
wp_get_http example
$response
=
wp_safe_remote_request
(
$url
,
$options
)
;
if
(
is_wp_error
(
$response
)
)
return
false;
$headers
=
wp_remote_retrieve_headers
(
$response
)
;
$headers
[
'response'
]
=
wp_remote_retrieve_response_code
(
$response
)
;
// WP_HTTP no longer follows redirects for HEAD requests.
if
(
'HEAD' ==
$options
[
'method'
]
&&
in_array
(
$headers
[
'response'
]
, array
(
301, 302
)
)
&&
isset
(
$headers
[
'location'
]
)
)
{
return
wp_get_http
(
$headers
[
'location'
]
,
$file_path
, ++
$red
)
;
}
if
(
false ==
$file_path
)
return
$headers
;
// GET request - write it to the supplied filename.
$out_fp
=
fopen
(
$file_path
, 'w'
)
;
if
(
!
$out_fp
)
return
$headers
;
fwrite
(
$out_fp
,
wp_remote_retrieve_body
(
$response
)
)
;