PluginProbe
Hello Plus / 1.5.2
Hello Plus v1.5.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / includes / utils.php

utils.php in Hello Plus 1.5.2, at includes/utils.php

180 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HelloPlus\Includes;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * class Utils
10 **/
11 class Utils {
12
13 private static ?bool $elementor_installed = null;
14
15 private static ?bool $elementor_active = null;
16
17 public static function elementor(): \Elementor\Plugin {
18 return \Elementor\Plugin::$instance;
19 }
20
21 public static function has_pro(): bool {
22 return defined( 'ELEMENTOR_PRO_VERSION' );
23 }
24
25 public static function are_we_on_elementor_domains(): bool {
26 $current_domain = filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL );
27 $allowed_domains = [
28 'elementor.com',
29 'elementor.red',
30 ];
31
32 foreach ( $allowed_domains as $domain ) {
33 if ( str_ends_with( $current_domain, $domain ) ) {
34 return true;
35 }
36 }
37 return false;
38 }
39
40 public static function has_hello_biz(): bool {
41 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
42 return true;
43 }
44
45 if ( self::are_we_on_elementor_domains() ) {
46 return true;
47 }
48
49 return defined( 'EHP_THEME_SLUG' );
50 }
51
52 public static function is_elementor_active(): bool {
53 if ( null === self::$elementor_active ) {
54 self::$elementor_active = defined( 'ELEMENTOR_VERSION' );
55 }
56
57 return self::$elementor_active;
58 }
59
60 public static function is_elementor_installed(): bool {
61 if ( null === self::$elementor_installed ) {
62 self::$elementor_installed = file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' );
63 }
64
65 return self::$elementor_installed;
66 }
67
68 public static function get_current_post_id(): int {
69 if ( isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
70 return self::elementor()->documents->get_current()->get_main_id();
71 }
72
73 return get_the_ID();
74 }
75
76 public static function get_update_elementor_message(): string {
77 return sprintf(
78 /* translators: %s: Elementor version number. */
79 __( 'Elementor plugin version needs to be at least %s for Hello Plus to Work. Please update.', 'hello-plus' ),
80 HELLOPLUS_MIN_ELEMENTOR_VERSION,
81 );
82 }
83
84 public static function get_client_ip(): string {
85 $server_ip_keys = [
86 'HTTP_CLIENT_IP',
87 'HTTP_X_FORWARDED_FOR',
88 'HTTP_X_FORWARDED',
89 'HTTP_X_CLUSTER_CLIENT_IP',
90 'HTTP_FORWARDED_FOR',
91 'HTTP_FORWARDED',
92 'REMOTE_ADDR',
93 ];
94
95 foreach ( $server_ip_keys as $key ) {
96 $value = filter_input( INPUT_SERVER, $key, FILTER_VALIDATE_IP );
97
98 if ( $value ) {
99 return $value;
100 }
101 }
102
103 return '127.0.0.1';
104 }
105
106 public static function ends_with( $full_string, $end_string ): bool {
107 $len = strlen( $end_string );
108 if ( 0 === $len ) {
109 return true;
110 }
111
112 return ( substr( $full_string, -$len ) === $end_string );
113 }
114
115 public static function get_theme_slug(): string {
116 if ( defined( 'EHP_THEME_SLUG' ) ) {
117 return EHP_THEME_SLUG;
118 }
119
120 return 'hello-plus';
121 }
122
123 public static function get_theme_admin_home(): string {
124 if ( defined( 'EHP_THEME_SLUG' ) ) {
125 return add_query_arg( [ 'page' => EHP_THEME_SLUG ], self_admin_url( 'edit.php' ) );
126 }
127
128 return self_admin_url();
129 }
130
131 public static function is_preview_for_document( $post_id ): bool {
132 $preview_id = filter_input( INPUT_GET, 'preview_id', FILTER_VALIDATE_INT );
133 $preview = filter_input( INPUT_GET, 'preview', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
134
135 return 'true' === $preview && (int) $post_id === (int) $preview_id;
136 }
137
138 public static function is_installed_elementor_version_supported(): bool {
139 $plugin_file = WP_PLUGIN_DIR . '/elementor/elementor.php';
140
141 if ( ! file_exists( $plugin_file ) ) {
142 return true;
143 }
144
145 require_once ABSPATH . 'wp-admin/includes/plugin.php';
146
147 $plugin_data = get_plugin_data( $plugin_file );
148 $plugin_version = $plugin_data['Version'];
149
150 return self::is_elementor_version_supported( $plugin_version );
151 }
152
153 public static function is_active_elementor_version_supported(): bool {
154 return self::is_elementor_version_supported( ELEMENTOR_VERSION );
155 }
156
157 public static function is_elementor_version_supported( string $version ): bool {
158 return version_compare( $version, HELLOPLUS_MIN_ELEMENTOR_VERSION, 'ge' );
159 }
160
161 public static function plugin_title(): string {
162 return __( 'Hello+', 'hello-plus' );
163 }
164
165 public static function are_submissions_enabled(): bool {
166 return static::has_pro() &&
167 class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
168 class_exists( '\ElementorPro\License\API' ) &&
169 class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
170 \ElementorPro\License\API::is_licence_has_feature(
171 \ElementorPro\Modules\Forms\Submissions\Component::NAME,
172 \ElementorPro\License\APi::BC_VALIDATION_CALLBACK
173 );
174 }
175
176 public static function get_widgets_depends(): array {
177 return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes' ];
178 }
179 }
180