PluginProbe
Hello Plus / 1.6.2
Hello Plus v1.6.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.6.2, at includes/utils.php

219 lines 5.9 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 public static function elementor(): ?\Elementor\Plugin {
14 return class_exists( '\Elementor\Plugin' ) ? \Elementor\Plugin::instance() : null;
15 }
16
17 public static function has_pro(): bool {
18 return defined( 'ELEMENTOR_PRO_VERSION' );
19 }
20
21 public static function are_we_on_elementor_domains(): bool {
22 $current_domain = filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL );
23 $allowed_domains = [
24 'elementor.com',
25 'elementor.red',
26 ];
27
28 foreach ( $allowed_domains as $domain ) {
29 if ( str_ends_with( $current_domain, $domain ) ) {
30 return true;
31 }
32 }
33 return false;
34 }
35
36 public static function has_hello_biz(): bool {
37 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
38 return true;
39 }
40
41 if ( self::are_we_on_elementor_domains() ) {
42 return true;
43 }
44
45 return defined( 'EHP_THEME_SLUG' );
46 }
47
48 public static function has_hello_elementor_theme(): bool {
49 return defined( 'EHP_THEME_SLUG' ) && ( 'hello-elementor' === EHP_THEME_SLUG );
50 }
51
52 public static function is_elementor_active(): bool {
53 static $elementor_active = null;
54 if ( is_null( $elementor_active ) ) {
55 $elementor_active = defined( 'ELEMENTOR_VERSION' );
56 }
57
58 return $elementor_active;
59 }
60
61 public static function is_elementor_installed(): bool {
62 static $elementor_installed = null;
63 if ( is_null( $elementor_installed ) ) {
64 $elementor_installed = file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' );
65 }
66
67 return $elementor_installed;
68 }
69
70 public static function get_current_post_id(): int {
71 if ( self::elementor() && isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
72 return self::elementor()->documents->get_current()->get_main_id();
73 }
74
75 return get_the_ID();
76 }
77
78 public static function get_update_elementor_message(): string {
79 return sprintf(
80 /* translators: %s: Elementor version number. */
81 __( 'Elementor plugin version needs to be at least %s for Hello Plus to Work. Please update.', 'hello-plus' ),
82 HELLOPLUS_MIN_ELEMENTOR_VERSION,
83 );
84 }
85
86 public static function get_client_ip(): string {
87 $server_ip_keys = [
88 'HTTP_CLIENT_IP',
89 'HTTP_X_FORWARDED_FOR',
90 'HTTP_X_FORWARDED',
91 'HTTP_X_CLUSTER_CLIENT_IP',
92 'HTTP_FORWARDED_FOR',
93 'HTTP_FORWARDED',
94 'REMOTE_ADDR',
95 ];
96
97 foreach ( $server_ip_keys as $key ) {
98 $value = filter_input( INPUT_SERVER, $key, FILTER_VALIDATE_IP );
99
100 if ( $value ) {
101 return $value;
102 }
103 }
104
105 return '127.0.0.1';
106 }
107
108 public static function ends_with( $full_string, $end_string ): bool {
109 $len = strlen( $end_string );
110 if ( 0 === $len ) {
111 return true;
112 }
113
114 return ( substr( $full_string, -$len ) === $end_string );
115 }
116
117 public static function get_theme_slug(): string {
118 if ( defined( 'EHP_THEME_SLUG' ) ) {
119 return EHP_THEME_SLUG;
120 }
121
122 return 'hello-plus';
123 }
124
125 public static function get_theme_admin_home(): string {
126 if ( defined( 'EHP_THEME_SLUG' ) ) {
127 return add_query_arg( [ 'page' => EHP_THEME_SLUG ], self_admin_url( 'edit.php' ) );
128 }
129
130 return self_admin_url();
131 }
132
133 public static function is_preview_for_document( $post_id ): bool {
134 $preview_id = filter_input( INPUT_GET, 'preview_id', FILTER_VALIDATE_INT );
135 $preview = filter_input( INPUT_GET, 'preview', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
136
137 return 'true' === $preview && (int) $post_id === (int) $preview_id;
138 }
139
140 public static function is_installed_elementor_version_supported(): bool {
141 $plugin_file = WP_PLUGIN_DIR . '/elementor/elementor.php';
142
143 if ( ! file_exists( $plugin_file ) ) {
144 return true;
145 }
146
147 require_once ABSPATH . 'wp-admin/includes/plugin.php';
148
149 $plugin_data = get_plugin_data( $plugin_file );
150 $plugin_version = $plugin_data['Version'];
151
152 return self::is_elementor_version_supported( $plugin_version );
153 }
154
155 public static function is_active_elementor_version_supported(): bool {
156 return self::is_elementor_version_supported( ELEMENTOR_VERSION );
157 }
158
159 public static function is_elementor_version_supported( string $version ): bool {
160 return version_compare( $version, HELLOPLUS_MIN_ELEMENTOR_VERSION, 'ge' );
161 }
162
163 public static function plugin_title(): string {
164 return __( 'Hello+', 'hello-plus' );
165 }
166
167 public static function are_submissions_enabled(): bool {
168 return static::has_pro() &&
169 class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
170 class_exists( '\ElementorPro\License\API' ) &&
171 class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
172 self::is_licence_has_feature_compatible(
173 \ElementorPro\Modules\Forms\Submissions\Component::NAME
174 );
175 }
176
177 private static function is_licence_has_feature_compatible( $feature ) {
178 $method = new \ReflectionMethod(
179 \ElementorPro\License\API::class, 'is_licence_has_feature'
180 );
181 $num_params = $method->getNumberOfParameters();
182
183 if ( $num_params > 1 ) {
184 return \ElementorPro\License\API::is_licence_has_feature(
185 $feature,
186 \ElementorPro\License\API::BC_VALIDATION_CALLBACK
187 );
188 } else {
189 return \ElementorPro\License\API::is_licence_has_feature(
190 $feature
191 );
192 }
193 }
194
195 public static function get_widgets_depends(): array {
196 return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes', 'helloplus-column-structure' ];
197 }
198
199 public static function maybe_has_pro_location_docs( string $location = '' ): array {
200 if ( ! self::has_pro() ) {
201 return [];
202 }
203 $theme_builder_module = \ElementorPro\Modules\ThemeBuilder\Module::instance();
204 $conditions_manager = $theme_builder_module->get_conditions_manager();
205
206 return $conditions_manager->get_documents_for_location( $location );
207 }
208
209 public static function get_pro_part( string $part = '' ) {
210 if ( ! self::has_pro() ) {
211 return false;
212 }
213
214 $pro_part = self::maybe_has_pro_location_docs( $part );
215 $first_pro_part_id = array_key_first( $pro_part );
216 return ! empty( $first_pro_part_id ) ? $first_pro_part_id : false;
217 }
218 }
219