Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/hostinge.../includes/Admin
File: Proxy.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Hostinger\Admin;
[2] Fix | Delete
[3] Fix | Delete
use Hostinger\Mcp\EventHandlerFactory;
[4] Fix | Delete
use Hostinger\WpHelper\Requests\Client;
[5] Fix | Delete
use Hostinger\WpHelper\Utils;
[6] Fix | Delete
use WP_Error;
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
class Proxy {
[11] Fix | Delete
[12] Fix | Delete
public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com';
[13] Fix | Delete
public const HOSTINGER_DEV_FREE_SUBDOMAIN_URL = 'hostingersite.dev';
[14] Fix | Delete
[15] Fix | Delete
[16] Fix | Delete
private Client $client;
[17] Fix | Delete
private Utils $utils;
[18] Fix | Delete
private string $rest_base;
[19] Fix | Delete
[20] Fix | Delete
public function __construct( Client $client, Utils $utils ) {
[21] Fix | Delete
$this->client = $client;
[22] Fix | Delete
$this->utils = $utils;
[23] Fix | Delete
$this->rest_base = '/api/v1/events/trigger';
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
public function trigger_event( string $event, array $params = array() ): array|WP_Error {
[27] Fix | Delete
if ( $this->is_free_subdomain() || ! $_SERVER['H_PLATFORM'] ) {
[28] Fix | Delete
return new WP_Error( 'domain-not_allowed', 'This domain is not eligible for triggering Hostinger events' );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
$args = array(
[32] Fix | Delete
'domain' => $this->remove_www( $this->utils->getHostInfo() ),
[33] Fix | Delete
'event' => array(
[34] Fix | Delete
'name' => $event,
[35] Fix | Delete
'params' => $params,
[36] Fix | Delete
),
[37] Fix | Delete
);
[38] Fix | Delete
[39] Fix | Delete
return $this->client->post( $this->rest_base, $args );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
private function is_free_subdomain(): bool {
[43] Fix | Delete
return str_contains( $this->utils->getHostInfo(), self::HOSTINGER_FREE_SUBDOMAIN_URL ) ||
[44] Fix | Delete
str_contains( $this->utils->getHostInfo(), self::HOSTINGER_DEV_FREE_SUBDOMAIN_URL );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
private function remove_www( string $url ): string {
[48] Fix | Delete
if ( str_starts_with( $url, 'www.' ) ) {
[49] Fix | Delete
return substr( $url, 4 );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
return $url;
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function