PluginProbe
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.8
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.8
1.8.0 1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 All 59 releases
hostinger-reach / src / Api / Handlers / HostingApiHandler.php
HostingApiHandler.php
60 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger\Reach\Api\Handlers;
4
5 use Hostinger\WpHelper\Requests\Client;
6 use Hostinger\Reach\Functions;
7 use WP_REST_Response;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die;
11 }
12
13 class HostingApiHandler extends ApiHandler {
14
15 private Client $client;
16
17 public function __construct( Functions $functions, Client $client ) {
18 parent::__construct( $functions );
19 $this->client = $client;
20 }
21
22 public function get_domain_details_handler(): WP_REST_Response {
23 // For non Hostinger Users prevent request and just return an empty array.
24 if ( ! $this->get_functions()->is_hostinger_user() ) {
25 return $this->handle_response(
26 array(
27 'response' => array(
28 'code' => 200,
29 ),
30 'body' => wp_json_encode( array() ),
31 )
32 );
33 }
34
35 $siteurl = get_option( 'siteurl' );
36 $domain = apply_filters( 'hostinger_reach_domain', parse_url( $siteurl, PHP_URL_HOST ) );
37 $transient_key = 'hostinger_reach_domain_details_' . md5( $domain );
38 $disable_cache = apply_filters( 'hostinger_reach_disable_rest_cache', false );
39
40 if ( ! $disable_cache ) {
41 $cached_response = get_transient( $transient_key );
42 if ( $cached_response !== false ) {
43 return $this->handle_response( $cached_response );
44 }
45 }
46
47 $response = $this->client->get( '/v3/wordpress/domain-details', array( 'domain' => $domain ) );
48
49 if ( is_wp_error( $response ) ) {
50 return $this->handle_wp_error( $response );
51 }
52
53 if ( ! $disable_cache ) {
54 set_transient( $transient_key, $response, MINUTE_IN_SECONDS );
55 }
56
57 return $this->handle_response( $response );
58 }
59 }
60