PluginProbe
Hostinger Tools / 1.9.7
Hostinger Tools v1.9.7
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.7, at includes/class-hostinger-helper.php

115 lines 2.5 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 '/wp-admin/admin.php?page=hostinger&'
8 ];
9
10 /**
11 *
12 * Check if plugin is active
13 *
14 * @since 1.0.0
15 * @access public
16 */
17 public static function is_plugin_active( $plugin_slug ): bool {
18 $active_plugins = (array) get_option( 'active_plugins', array() );
19 foreach ( $active_plugins as $active_plugin ) {
20 if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) {
21 return true;
22 }
23 }
24
25 return false;
26 }
27
28 public static function get_api_token(): string {
29 $api_token = '';
30 $token_file = HOSTINGER_WP_TOKEN;
31
32 if ( file_exists( $token_file ) && ! empty( file_get_contents( $token_file ) ) ) {
33 $api_token = file_get_contents( $token_file );
34 }
35
36 return $api_token;
37 }
38
39 /**
40 *
41 * Get the host info (domain, subdomain, subdirectory)
42 *
43 * @since 1.7.0
44 * @access public
45 */
46
47 public function get_host_info(): string {
48 $host = $_SERVER['HTTP_HOST'] ?? '';
49 $site_url = get_site_url();
50 $site_url = preg_replace( '#^https?://#', '', $site_url );
51
52 if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) {
53 if ( $site_url === $host ) {
54 return $host;
55 } else {
56 return substr( $site_url, strlen( $host ) + 1 );
57 }
58 }
59
60 return $host;
61 }
62
63 public function is_preview_domain(): bool {
64 if ( function_exists( 'getallheaders' ) ) {
65 $headers = getallheaders();
66 }
67
68 if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) {
69 return true;
70 }
71
72 return false;
73 }
74
75 public function is_free_subdomain(): bool {
76 $site_url = preg_replace( '#^https?://#', '', get_site_url() );
77
78 return ! empty( $site_url ) && strpos( $site_url, self::HOSTINGER_FREE_SUBDOMAIN_URL ) !== false;
79 }
80
81 public function is_hostinger_admin_page(): bool {
82 $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
83
84 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
85 return false;
86 }
87
88 if ( isset( $current_uri ) && strpos( $current_uri, '/wp-json/' ) !== false ) {
89 return false;
90 }
91
92 if ( in_array( $current_uri, self::HOSTINGER_PAGE ) ) {
93 return true;
94 }
95
96 return false;
97
98 }
99
100 /**
101 *
102 * Error log
103 *
104 * @since 1.9.6
105 * @access public
106 */
107 public function error_log( string $message ): void {
108 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
109 error_log( print_r( $message, true ) );
110 }
111 }
112 }
113
114 $hostinger_helper = new Hostinger_Helper();
115