Выполняет HTTP-запрос к серверу методом HEAD, что означает, что будут возвращены только заголовки ответа сервера.
Функция является частью WordPress HTTP API, про него у меня есть отдельный урок.
wp_remote_head( $url, $args = array() )
К примеру давайте попробуем получить заголовки моего сайта.
$request = wp_remote_head( 'https://misha.agency' ); print_r( $request ); /* Array ( [headers] => Requests_Utility_CaseInsensitiveDictionary Object ( [data:protected] => Array ( [server] => nginx-reuseport/1.21.1 [date] => Sat, 12 Feb 2022 05:05:58 GMT [content-type] => text/html; charset=UTF-8 [content-length] => 6406 [x-powered-by] => PHP/7.3.31 [vary] => Accept-Encoding,Cookie [cache-control] => max-age=3, must-revalidate [content-encoding] => gzip [last-modified] => Sat, 12 Feb 2022 04:57:21 GMT ) ) [body] => [response] => Array ( [code] => 200 [message] => OK ) [cookies] => Array ( ) [filename] => [http_response] => WP_HTTP_Requests_Response Object ( [response:protected] => Requests_Response Object ( [body] => [raw] => HTTP/1.1 200 OK Server: nginx-reuseport/1.21.1 Date: Sat, 12 Feb 2022 05:05:58 GMT Content-Type: text/html; charset=UTF-8 Content-Length: 6406 Connection: close X-Powered-By: PHP/7.3.31 Vary: Accept-Encoding,Cookie Cache-Control: max-age=3, must-revalidate Content-Encoding: gzip Last-Modified: Sat, 12 Feb 2022 04:57:21 GMT [headers] => Requests_Response_Headers Object ( [data:protected] => Array ( [server] => Array ( [0] => nginx-reuseport/1.21.1 ) [date] => Array ( [0] => Sat, 12 Feb 2022 05:05:58 GMT ) [content-type] => Array ( [0] => text/html; charset=UTF-8 ) [content-length] => Array ( [0] => 6406 ) [x-powered-by] => Array ( [0] => PHP/7.3.31 ) [vary] => Array ( [0] => Accept-Encoding,Cookie ) [cache-control] => Array ( [0] => max-age=3, must-revalidate ) [content-encoding] => Array ( [0] => gzip ) [last-modified] => Array ( [0] => Sat, 12 Feb 2022 04:57:21 GMT ) ) ) [status_code] => 200 [protocol_version] => 1.1 [success] => 1 [redirects] => 0 [url] => https://misha.agency/ [history] => Array ( ) [cookies] => Requests_Cookie_Jar Object ( [cookies:protected] => Array ( ) ) ) [filename:protected] => [data] => [headers] => [status] => ) ) */
При использовании функции wp_remote_head()
тело ответа body
всегда будет пустым.
Чтобы оставить комментарий, пожалуйста, зарегистрируйтесь или войдите.