PluginProbe
Hello Plus / 1.4.0
Hello Plus v1.4.0
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 / trunk / includes / utils.php

utils.php in Hello Plus 1.4.0, at trunk/includes/utils.php

176 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 ( self::are_we_on_elementor_domains() ) {
42 return true;
43 }
44
45 return defined( 'EHP_THEME_SLUG' );
46 }
47
48 public static function is_elementor_active(): bool {
49 if ( null === self::$elementor_active ) {
50 self::$elementor_active = defined( 'ELEMENTOR_VERSION' );
51 }
52
53 return self::$elementor_active;
54 }
55
56 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' );
59 }
60
61 return self::$elementor_installed;
62 }
63
64 public static function get_current_post_id(): int {
65 if ( isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
66 return self::elementor()->documents->get_current()->get_main_id();
67 }
68
69 return get_the_ID();
70 }
71
72 public static function get_update_elementor_message(): string {
73 return sprintf(
74 /* translators: %s: Elementor version number. */
75 __( 'Elementor plugin version needs to be at least %s for Hello Plus to Work. Please update.', 'hello-plus' ),
76 HELLOPLUS_MIN_ELEMENTOR_VERSION,
77 );
78 }
79
80 public static function get_client_ip(): string {
81 $server_ip_keys = [
82 'HTTP_CLIENT_IP',
83 'HTTP_X_FORWARDED_FOR',
84 'HTTP_X_FORWARDED',
85 'HTTP_X_CLUSTER_CLIENT_IP',
86 'HTTP_FORWARDED_FOR',
87 'HTTP_FORWARDED',
88 'REMOTE_ADDR',
89 ];
90
91 foreach ( $server_ip_keys as $key ) {
92 $value = filter_input( INPUT_SERVER, $key, FILTER_VALIDATE_IP );
93
94 if ( $value ) {
95 return $value;
96 }
97 }
98
99 return '127.0.0.1';
100 }
101
102 public static function ends_with( $full_string, $end_string ): bool {
103 $len = strlen( $end_string );
104 if ( 0 === $len ) {
105 return true;
106 }
107
108 return ( substr( $full_string, -$len ) === $end_string );
109 }
110
111 public static function get_theme_slug(): string {
112 if ( defined( 'EHP_THEME_SLUG' ) ) {
113 return EHP_THEME_SLUG;
114 }
115
116 return 'hello-plus';
117 }
118
119 public static function get_theme_admin_home(): string {
120 if ( defined( 'EHP_THEME_SLUG' ) ) {
121 return add_query_arg( [ 'page' => EHP_THEME_SLUG ], self_admin_url( 'edit.php' ) );
122 }
123
124 return self_admin_url();
125 }
126
127 public static function is_preview_for_document( $post_id ): bool {
128 $preview_id = filter_input( INPUT_GET, 'preview_id', FILTER_VALIDATE_INT );
129 $preview = filter_input( INPUT_GET, 'preview', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
130
131 return 'true' === $preview && (int) $post_id === (int) $preview_id;
132 }
133
134 public static function is_installed_elementor_version_supported(): bool {
135 $plugin_file = WP_PLUGIN_DIR . '/elementor/elementor.php';
136
137 if ( ! file_exists( $plugin_file ) ) {
138 return true;
139 }
140
141 require_once ABSPATH . 'wp-admin/includes/plugin.php';
142
143 $plugin_data = get_plugin_data( $plugin_file );
144 $plugin_version = $plugin_data['Version'];
145
146 return self::is_elementor_version_supported( $plugin_version );
147 }
148
149 public static function is_active_elementor_version_supported(): bool {
150 return self::is_elementor_version_supported( ELEMENTOR_VERSION );
151 }
152
153 public static function is_elementor_version_supported( string $version ): bool {
154 return version_compare( $version, HELLOPLUS_MIN_ELEMENTOR_VERSION, 'ge' );
155 }
156
157 public static function plugin_title(): string {
158 return __( 'Hello+', 'hello-plus' );
159 }
160
161 public static function are_submissions_enabled(): bool {
162 return static::has_pro() &&
163 class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
164 class_exists( '\ElementorPro\License\API' ) &&
165 class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
166 \ElementorPro\License\API::is_licence_has_feature(
167 \ElementorPro\Modules\Forms\Submissions\Component::NAME,
168 \ElementorPro\License\APi::BC_VALIDATION_CALLBACK
169 );
170 }
171
172 public static function get_widgets_depends(): array {
173 return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes' ];
174 }
175 }
176