PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Framework / HttpTrait.php

HttpTrait.php in Packeta trunk, at src/Packetery/Module/Framework/HttpTrait.php

46 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trait HttpTrait.
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Framework;
11
12 use WP_Error;
13
14 /**
15 * Trait HttpTrait.
16 *
17 * @package Packetery
18 */
19 trait HttpTrait {
20 /**
21 * Performs an HTTP request using the GET method and returns its response.
22 *
23 * @param string $url URL to retrieve.
24 * @param array $args Optional. Request arguments. Default empty array. See WP_Http::request() for information on accepted arguments.
25 *
26 * @return array|WP_Error The response or WP_Error on failure.
27 */
28 public function remoteGet( string $url, array $args = [] ) {
29 return wp_remote_get( $url, $args );
30 }
31
32 /**
33 * Retrieves only the body from the raw response.
34 *
35 * @param array|WP_Error $response HTTP response.
36 * @return string The body of the response. Empty string if no body or incorrect parameter given.
37 */
38 public function remoteRetrieveBody( $response ): string {
39 return wp_remote_retrieve_body( $response );
40 }
41
42 public function safeRedirect( string $location ): bool {
43 return wp_safe_redirect( $location );
44 }
45 }
46