PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.3
Elementor Website Builder – more than just a page builder v3.22.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / utils / hints.php

hints.php in Elementor Website Builder – more than just a page builder 3.22.3, at core/utils/hints.php

392 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace elementor\core\utils;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\User;
9 use Elementor\Utils;
10
11 class Hints {
12 const INFO = 'info';
13 const SUCCESS = 'success';
14 const WARNING = 'warning';
15 const DANGER = 'danger';
16
17 const DEFINED = 'defined';
18 const DISMISSED = 'dismissed';
19 const CAPABILITY = 'capability';
20 const PLUGIN_INSTALLED = 'plugin_installed';
21 const PLUGIN_ACTIVE = 'plugin_active';
22
23 /**
24 * get_notice_types
25 * @return string[]
26 */
27 public static function get_notice_types(): array {
28 return [
29 self::INFO,
30 self::SUCCESS,
31 self::WARNING,
32 self::DANGER,
33 ];
34 }
35
36 /**
37 * get_hints
38 *
39 * @param $hint_key
40 *
41 * @return array|string[]|\string[][]
42 */
43 public static function get_hints( $hint_key = null ): array {
44 $hints = [
45 'image-optimization-once' => [
46 self::DISMISSED => 'image-optimization-once',
47 self::CAPABILITY => 'install_plugins',
48 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
49 ],
50 'image-optimization-once-media-modal' => [
51 self::DISMISSED => 'image-optimization-once-media-modal',
52 self::CAPABILITY => 'install_plugins',
53 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
54 ],
55 'image-optimization' => [
56 self::DISMISSED => 'image_optimizer_hint',
57 self::CAPABILITY => 'install_plugins',
58 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
59 ],
60 'image-optimization-media-modal' => [
61 self::DISMISSED => 'image-optimization-media-modal',
62 self::CAPABILITY => 'install_plugins',
63 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
64 ],
65 ];
66 if ( ! $hint_key ) {
67 return $hints;
68 }
69
70 return $hints[ $hint_key ] ?? [];
71 }
72
73 /**
74 * get_notice_icon
75 * @return string
76 */
77 public static function get_notice_icon(): string {
78 return '<div class="elementor-control-notice-icon">
79 <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
80 <path d="M2.25 9H3M9 2.25V3M15 9H15.75M4.2 4.2L4.725 4.725M13.8 4.2L13.275 4.725M7.27496 12.75H10.725M6.75 12C6.12035 11.5278 5.65525 10.8694 5.42057 10.1181C5.1859 9.36687 5.19355 8.56082 5.44244 7.81415C5.69133 7.06748 6.16884 6.41804 6.80734 5.95784C7.44583 5.49764 8.21294 5.25 9 5.25C9.78706 5.25 10.5542 5.49764 11.1927 5.95784C11.8312 6.41804 12.3087 7.06748 12.5576 7.81415C12.8065 8.56082 12.8141 9.36687 12.5794 10.1181C12.3448 10.8694 11.8796 11.5278 11.25 12C10.9572 12.2899 10.7367 12.6446 10.6064 13.0355C10.4761 13.4264 10.4397 13.8424 10.5 14.25C10.5 14.6478 10.342 15.0294 10.0607 15.3107C9.77936 15.592 9.39782 15.75 9 15.75C8.60218 15.75 8.22064 15.592 7.93934 15.3107C7.65804 15.0294 7.5 14.6478 7.5 14.25C7.56034 13.8424 7.52389 13.4264 7.3936 13.0355C7.2633 12.6446 7.04282 12.2899 6.75 12Z" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
81 </svg>
82 </div>';
83 }
84
85 /**
86 * get_notice_template
87 *
88 * Print or Retrieve the notice template.
89 * @param array $notice
90 * @param bool $return
91 *
92 * @return string|void
93 */
94 public static function get_notice_template( array $notice, bool $return = false ) {
95 $default_settings = [
96 'type' => 'info',
97 'icon' => false,
98 'heading' => '',
99 'content' => '',
100 'dismissible' => false,
101 'button_text' => '',
102 'button_event' => '',
103 'button_data' => [],
104 'display' => false,
105 ];
106 $notice_settings = array_merge( $default_settings, $notice );
107
108 if ( empty( $notice_settings['heading'] ) && empty( $notice_settings['content'] ) ) {
109 return '';
110 }
111
112 if ( ! in_array( $notice_settings['type'], self::get_notice_types(), true ) ) {
113 $notice_settings['type'] = 'info';
114 }
115
116 $icon = '';
117 $heading = '';
118 $content = '';
119 $dismissible = '';
120 $button = '';
121
122 if ( $notice_settings['icon'] ) {
123 $icon = self::get_notice_icon();
124 }
125
126 if ( ! empty( $notice_settings['heading'] ) ) {
127 $heading = '<div class="elementor-control-notice-main-heading">' . $notice_settings['heading'] . '</div>';
128 }
129
130 if ( ! empty( $notice_settings['content'] ) ) {
131 $content = '<div class="elementor-control-notice-main-content">' . $notice_settings['content'] . '</div>';
132 }
133
134 if ( ! empty( $notice_settings['button_text'] ) ) {
135 $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( json_encode( $notice_settings['button_data'] ) ) . '"' : '';
136 $button = '<div class="elementor-control-notice-main-actions">
137 <button type="button" class="e-btn e-' . $notice_settings['type'] . ' e-btn-1" data-event="' . $notice_settings['button_event'] . '"' . $button_settings . '>
138 ' . $notice_settings['button_text'] . '
139 </button>
140 </div>';
141 }
142
143 if ( $notice_settings['dismissible'] ) {
144 $dismissible = '<button class="elementor-control-notice-dismiss tooltip-target" data-event="' . $notice_settings['dismissible'] . '" data-tooltip="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '">
145 <i class="eicon eicon-close" aria-hidden="true"></i>
146 <span class="elementor-screen-only">' . esc_html__( 'Don’t show again.', 'elementor' ) . '</span>
147 </button>';
148 }
149
150 $notice_template = sprintf( '<div class="elementor-control-notice elementor-control-notice-type-%1$s" data-display="%7$s">
151 %2$s
152 <div class="elementor-control-notice-main">
153 %3$s
154 %4$s
155 %5$s
156 </div>
157 %6$s
158 </div>',
159 $notice_settings['type'],
160 $icon,
161 $heading,
162 $content,
163 $button,
164 $dismissible,
165 $notice_settings['display']
166 );
167
168 if ( $return ) {
169 return $notice_template;
170 }
171 echo wp_kses( $notice_template, self::get_notice_allowed_html() );
172 }
173
174 /**
175 * get_plugin_install_url
176 * @param $plugin_slug
177 *
178 * @return string
179 */
180 public static function get_plugin_install_url( $plugin_slug ): string {
181 $action = 'install-plugin';
182 return wp_nonce_url(
183 add_query_arg(
184 [
185 'action' => $action,
186 'plugin' => $plugin_slug,
187 ],
188 admin_url( 'update.php' )
189 ),
190 $action . '_' . $plugin_slug
191 );
192 }
193
194 /**
195 * get_plugin_activate_url
196 * @param $plugin_slug
197 *
198 * @return string
199 */
200 public static function get_plugin_activate_url( $plugin_slug ): string {
201 $path = "$plugin_slug/$plugin_slug.php";
202 return wp_nonce_url(
203 admin_url( 'plugins.php?action=activate&plugin=' . $path ),
204 'activate-plugin_' . $path
205 );
206 }
207
208 /**
209 * is_dismissed
210 * @param $key
211 *
212 * @return bool
213 */
214 public static function is_dismissed( $key ): bool {
215 $dismissed = User::get_dismissed_editor_notices();
216 return in_array( $key, $dismissed, true );
217 }
218
219 /**
220 * should_display_hint
221 * @param $hint_key
222 *
223 * @return bool
224 */
225 public static function should_display_hint( $hint_key ): bool {
226 $hint = self::get_hints( $hint_key );
227 if ( empty( $hint ) ) {
228 return false;
229 }
230
231 if ( static::is_conflict_plugin_installed() ) {
232 return false;
233 }
234
235 foreach ( $hint as $key => $value ) {
236 switch ( $key ) {
237 case self::DISMISSED:
238 if ( self::is_dismissed( $value ) ) {
239 return false;
240 }
241 break;
242 case self::CAPABILITY:
243 if ( ! current_user_can( $value ) ) {
244 return false;
245 }
246 break;
247 case self::DEFINED:
248 if ( defined( $value ) ) {
249 return false;
250 }
251 break;
252 case self::PLUGIN_INSTALLED:
253 if ( ! self::is_plugin_installed( $value ) ) {
254 return false;
255 }
256 break;
257 case self::PLUGIN_ACTIVE:
258 if ( ! self::is_plugin_active( $value ) ) {
259 return false;
260 }
261 break;
262 }
263 }
264 return true;
265 }
266
267 private static function is_conflict_plugin_installed(): bool {
268 if ( ! Utils::has_pro() ) {
269 return false;
270 }
271
272 $conflicting_plugins = [
273 'imagify/imagify.php',
274 'optimole-wp/optimole-wp.php',
275 'ewww-image-optimizer/ewww-image-optimizer.php',
276 'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
277 'kraken-image-optimizer/kraken.php',
278 'shortpixel-image-optimiser/wp-shortpixel.php',
279 'wp-smushit/wp-smush.php',
280 'wp-smush-pro/wp-smush.php',
281 'tiny-compress-images/tiny-compress-images.php',
282 ];
283
284 foreach ( $conflicting_plugins as $plugin ) {
285 if ( self::is_plugin_active( $plugin ) ) {
286 return true;
287 }
288 }
289
290 return false;
291 }
292
293 /**
294 * is_plugin_installed
295 * @param $plugin
296 *
297 * @return bool
298 */
299 public static function is_plugin_installed( $plugin ) : bool {
300 $plugins = get_plugins();
301 $plugin = self::ensure_plugin_folder( $plugin );
302 return ! empty( $plugins[ $plugin ] );
303 }
304
305 /**
306 * is_plugin_active
307 * @param $plugin
308 *
309 * @return bool
310 */
311 public static function is_plugin_active( $plugin ): bool {
312 $plugin = self::ensure_plugin_folder( $plugin );
313 return is_plugin_active( $plugin );
314 }
315
316 /**
317 * get_plugin_action_url
318 * @param $plugin
319 *
320 * @return string
321 */
322 public static function get_plugin_action_url( $plugin ): string {
323 if ( ! self::is_plugin_installed( $plugin ) ) {
324 return self::get_plugin_install_url( $plugin );
325 }
326
327 if ( ! self::is_plugin_active( $plugin ) ) {
328 return self::get_plugin_activate_url( $plugin );
329 }
330
331 return '';
332 }
333
334 /**
335 * ensure_plugin_folder
336 * @param $plugin
337 *
338 * @return string
339 */
340 private static function ensure_plugin_folder( $plugin ): string {
341 if ( false === strpos( $plugin, '/' ) ) {
342 $plugin = $plugin . '/' . $plugin . '.php';
343 }
344 return $plugin;
345 }
346
347 /**
348 * get_notice_allowed_html
349 * @return array[]
350 */
351 public static function get_notice_allowed_html(): array {
352 return [
353 'div' => [
354 'class' => [],
355 'data-display' => [],
356 ],
357 'svg' => [
358 'width' => [],
359 'height' => [],
360 'viewbox' => [],
361 'fill' => [],
362 'xmlns' => [],
363 ],
364 'path' => [
365 'd' => [],
366 'stroke' => [],
367 'stroke-width' => [],
368 'stroke-linecap' => [],
369 'stroke-linejoin' => [],
370 ],
371 'button' => [
372 'class' => [],
373 'data-event' => [],
374 'data-settings' => [],
375 'data-tooltip' => [],
376 ],
377 'i' => [
378 'class' => [],
379 'aria-hidden' => [],
380 ],
381 'span' => [
382 'class' => [],
383 ],
384 'a' => [
385 'href' => [],
386 'style' => [],
387 'target' => [],
388 ],
389 ];
390 }
391 }
392