PluginProbe
Hostinger Tools / 1.9.6
Hostinger Tools v1.9.6
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / class-hostinger-helper.php

class-hostinger-helper.php in Hostinger Tools 1.9.6, at includes/class-hostinger-helper.php

101 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Hostinger_Helper {
4 public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com';
5 public const HOSTINGER_PAGE = [
6 '/wp-admin/admin.php?page=hostinger'
7 ];
8
9 /**
10 *
11 * Check if plugin is active
12 *
13 * @since 1.0.0
14 * @access public
15 */
16 public static function is_plugin_active( $plugin_slug ): bool {
17 $active_plugins = (array) get_option( 'active_plugins', array() );
18 foreach ( $active_plugins as $active_plugin ) {
19 if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) {
20 return true;
21 }
22 }
23
24 return false;
25 }
26
27 public static function get_api_token(): string {
28 $api_token = '';
29 $token_file = HOSTINGER_WP_TOKEN;
30
31 if ( file_exists( $token_file ) && ! empty( file_get_contents( $token_file ) ) ) {
32 $api_token = file_get_contents( $token_file );
33 }
34
35 return $api_token;
36 }
37
38 /**
39 *
40 * Get the host info (domain, subdomain, subdirectory)
41 *
42 * @since 1.7.0
43 * @access public
44 */
45
46 public function get_host_info(): string {
47 $host = $_SERVER['HTTP_HOST'] ?? '';
48 $site_url = get_site_url();
49 $site_url = preg_replace( '#^https?://#', '', $site_url );
50
51 if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) {
52 if ( $site_url === $host ) {
53 return $host;
54 } else {
55 return substr( $site_url, strlen( $host ) + 1 );
56 }
57 }
58
59 return $host;
60 }
61
62 public function is_preview_domain(): bool {
63 if ( function_exists( 'getallheaders' ) ) {
64 $headers = getallheaders();
65 }
66
67 if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) {
68 return true;
69 }
70
71 return false;
72 }
73
74 public function is_free_subdomain(): bool {
75 $site_url = preg_replace( '#^https?://#', '', get_site_url() );
76
77 return ! empty( $site_url ) && strpos( $site_url, self::HOSTINGER_FREE_SUBDOMAIN_URL ) !== false;
78 }
79
80 public function is_hostinger_admin_page(): bool {
81 $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
82
83 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
84 return false;
85 }
86
87 if ( isset( $current_uri ) && strpos( $current_uri, '/wp-json/' ) !== false ) {
88 return false;
89 }
90
91 if ( in_array( $current_uri, self::HOSTINGER_PAGE ) ) {
92 return true;
93 }
94
95 return false;
96
97 }
98 }
99
100 $hostinger_helper = new Hostinger_Helper();
101