| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
class Hostinger_Helper { |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* Check if plugin is active |
| 10 |
* |
| 11 |
* @since 1.0.0 |
| 12 |
* @access public |
| 13 |
*/ |
| 14 |
public static function is_plugin_active( $plugin_slug ): bool { |
| 15 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 16 |
foreach ( $active_plugins as $active_plugin ) { |
| 17 |
if ( strpos( $active_plugin, $plugin_slug . '.php' ) !== false ) { |
| 18 |
return true; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
return false; |
| 23 |
} |
| 24 |
|
| 25 |
public static function get_api_token(): string { |
| 26 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; |
| 27 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; |
| 28 |
|
| 29 |
$api_token = ''; |
| 30 |
$token_path = HOSTINGER_WP_TOKEN; |
| 31 |
$filesystem = new WP_Filesystem_Direct( true ); |
| 32 |
$token_file = $filesystem->get_contents( $token_path ); |
| 33 |
|
| 34 |
if ( file_exists( $token_path ) && ! empty( $token_file ) ) { |
| 35 |
$api_token = $token_file; |
| 36 |
} |
| 37 |
|
| 38 |
return $api_token; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* |
| 43 |
* Get the host info (domain, subdomain, subdirectory) |
| 44 |
* |
| 45 |
* @since 1.7.0 |
| 46 |
* @access public |
| 47 |
*/ |
| 48 |
|
| 49 |
public function get_host_info(): string { |
| 50 |
$host = sanitize_text_field( $_SERVER['HTTP_HOST'] ?? '' ); |
| 51 |
$site_url = get_site_url(); |
| 52 |
$site_url = preg_replace( '#^https?://#', '', $site_url ); |
| 53 |
|
| 54 |
if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) { |
| 55 |
if ( $site_url === $host ) { |
| 56 |
return $host; |
| 57 |
} else { |
| 58 |
return substr( $site_url, strlen( $host ) + 1 ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
return $host; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
$hostiner_helper = new Hostinger_Helper(); |
| 69 |
|