PluginProbe
Hello Plus / 1.7.4
Hello Plus v1.7.4
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
← All changes | includes/utils.php +111 -15 1.2.01.7.4 View file →
@@ -9,14 +9,10 @@
9 9 * class Utils
10 10 **/
11 11 class Utils {
12 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;
13 + public static function elementor(): ?\Elementor\Plugin {
14 + return class_exists( '\Elementor\Plugin' ) ? \Elementor\Plugin::instance() : null;
19 15 }
20 16
21 17 public static function has_pro(): bool {
22 18 return defined( 'ELEMENTOR_PRO_VERSION' );
@@ -28,17 +24,25 @@
28 24 'elementor.com',
29 25 'elementor.red',
30 26 ];
31 27
28 + $is_elementor_domain = false;
29 +
32 30 foreach ( $allowed_domains as $domain ) {
33 31 if ( str_ends_with( $current_domain, $domain ) ) {
34 - return true;
32 + $is_elementor_domain = true;
33 + break;
35 34 }
36 35 }
37 - return false;
36 +
37 + return $is_elementor_domain;
38 38 }
39 39
40 40 public static function has_hello_biz(): bool {
41 + if ( defined( 'WP_TESTS_DOMAIN' ) ) {
42 + return true;
43 + }
44 +
41 45 if ( self::are_we_on_elementor_domains() ) {
42 46 return true;
43 47 }
44 48
@@ -44,26 +48,32 @@
44 48
45 49 return defined( 'EHP_THEME_SLUG' );
46 50 }
47 51
52 + public static function has_hello_elementor_theme(): bool {
53 + return defined( 'EHP_THEME_SLUG' ) && ( 'hello-elementor' === EHP_THEME_SLUG );
54 + }
55 +
48 56 public static function is_elementor_active(): bool {
49 - if ( null === self::$elementor_active ) {
50 - self::$elementor_active = defined( 'ELEMENTOR_VERSION' );
57 + static $elementor_active = null;
58 + if ( is_null( $elementor_active ) ) {
59 + $elementor_active = defined( 'ELEMENTOR_VERSION' );
51 60 }
52 61
53 - return self::$elementor_active;
62 + return $elementor_active;
54 63 }
55 64
56 65 public static function is_elementor_installed(): bool {
57 - if ( null === self::$elementor_installed ) {
58 - self::$elementor_installed = file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' );
66 + static $elementor_installed = null;
67 + if ( is_null( $elementor_installed ) ) {
68 + $elementor_installed = file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' );
59 69 }
60 70
61 - return self::$elementor_installed;
71 + return $elementor_installed;
62 72 }
63 73
64 74 public static function get_current_post_id(): int {
65 - if ( isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
75 + if ( self::elementor() && isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
66 76 return self::elementor()->documents->get_current()->get_main_id();
67 77 }
68 78
69 79 return get_the_ID();
@@ -151,6 +161,92 @@
151 161 }
152 162
153 163 public static function is_elementor_version_supported( string $version ): bool {
154 164 return version_compare( $version, HELLOPLUS_MIN_ELEMENTOR_VERSION, 'ge' );
165 + }
166 +
167 + public static function plugin_title(): string {
168 + return __( 'Hello+', 'hello-plus' );
169 + }
170 +
171 + public static function are_submissions_enabled(): bool {
172 + return static::has_pro() &&
173 + class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
174 + class_exists( '\ElementorPro\License\API' ) &&
175 + class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
176 + self::is_licence_has_feature_compatible(
177 + \ElementorPro\Modules\Forms\Submissions\Component::NAME
178 + );
179 + }
180 +
181 + private static function is_licence_has_feature_compatible( $feature ) {
182 + $method = new \ReflectionMethod(
183 + \ElementorPro\License\API::class, 'is_licence_has_feature'
184 + );
185 + $num_params = $method->getNumberOfParameters();
186 +
187 + if ( $num_params > 1 ) {
188 + return \ElementorPro\License\API::is_licence_has_feature(
189 + $feature,
190 + \ElementorPro\License\API::BC_VALIDATION_CALLBACK
191 + );
192 + } else {
193 + return \ElementorPro\License\API::is_licence_has_feature(
194 + $feature
195 + );
196 + }
197 + }
198 +
199 + public static function get_widgets_depends(): array {
200 + return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes', 'helloplus-column-structure' ];
201 + }
202 +
203 + public static function maybe_has_pro_location_docs( string $location = '' ): array {
204 + if ( ! self::has_pro() ) {
205 + return [];
206 + }
207 + $theme_builder_module = \ElementorPro\Modules\ThemeBuilder\Module::instance();
208 + $conditions_manager = $theme_builder_module->get_conditions_manager();
209 +
210 + return $conditions_manager->get_documents_for_location( $location );
211 + }
212 +
213 + public static function get_pro_part( string $part = '' ) {
214 + if ( ! self::has_pro() ) {
215 + return false;
216 + }
217 +
218 + $pro_part = self::maybe_has_pro_location_docs( $part );
219 + $first_pro_part_id = array_key_first( $pro_part );
220 + return ! empty( $first_pro_part_id ) ? $first_pro_part_id : false;
221 + }
222 +
223 + public static function is_test_environment(): bool {
224 +
225 + if ( defined( 'WP_TESTS_DOMAIN' ) ) {
226 + return true;
227 + }
228 +
229 + if ( getenv( 'TEST_PARALLEL_INDEX' ) !== false ) {
230 + return true;
231 + }
232 +
233 + $wp_env = getenv( 'WP_ENV' );
234 + if ( $wp_env && in_array( strtolower( $wp_env ), [ 'test', 'testing', 'playwright' ], true ) ) {
235 + return true;
236 + }
237 +
238 + if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) || defined( 'WP_PHPUNIT__TESTS_CONFIG' ) ) {
239 + return true;
240 + }
241 +
242 + if (
243 + defined( 'WP_DEBUG' ) &&
244 + defined( 'WP_DEBUG_LOG' ) &&
245 + filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL ) === 'localhost:8888'
246 + ) {
247 + return true;
248 + }
249 +
250 + return false;
155 251 }
156 252 }