PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-beta1
Elementor Website Builder – more than just a page builder v3.33.0-beta1
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.33.0-beta1, at core/utils/hints.php

517 lines 13.3 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 use Elementor\Core\Admin\Admin_Notices;
11
12 class Hints {
13
14 const INFO = 'info';
15 const SUCCESS = 'success';
16 const WARNING = 'warning';
17 const DANGER = 'danger';
18
19 const DEFINED = 'defined';
20 const NOT_DEFINED = 'not_defined';
21 const DISMISSED = 'dismissed';
22 const CAPABILITY = 'capability';
23 const PLUGIN_INSTALLED = 'plugin_installed';
24 const PLUGIN_ACTIVE = 'plugin_active';
25 const NOT_HAS_OPTION = 'not_has_option';
26
27 const INSTALL = 'install';
28 const ACTIVATE = 'activate';
29 const CONNECT = 'connect';
30 const CUSTOMIZE = 'customize';
31
32 /**
33 * Get_notice_types
34 *
35 * @return string[]
36 */
37 public static function get_notice_types(): array {
38 return [
39 self::INFO,
40 self::SUCCESS,
41 self::WARNING,
42 self::DANGER,
43 ];
44 }
45
46 /**
47 * Get_hints
48 *
49 * @param $hint_key
50 *
51 * @return array|string[]|\string[][]
52 */
53 public static function get_hints( $hint_key = null ): array {
54 $hints = [
55 'image-optimization-once' => [
56 self::DISMISSED => 'image-optimization-once',
57 self::CAPABILITY => 'install_plugins',
58 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
59 ],
60 'image-optimization-once-media-modal' => [
61 self::DISMISSED => 'image-optimization-once-media-modal',
62 self::CAPABILITY => 'install_plugins',
63 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
64 ],
65 'image-optimization' => [
66 self::DISMISSED => 'image_optimizer_hint',
67 self::CAPABILITY => 'install_plugins',
68 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
69 ],
70 'image-optimization-connect' => [
71 self::DISMISSED => 'image_optimizer_hint',
72 self::CAPABILITY => 'manage_options',
73 self::NOT_DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
74 self::NOT_HAS_OPTION => 'image_optimizer_access_token',
75 ],
76 'image-optimization-media-modal' => [
77 self::DISMISSED => 'image-optimization-media-modal',
78 self::CAPABILITY => 'install_plugins',
79 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
80 ],
81 'ally_heading_notice' => [
82 self::DISMISSED => 'ally_heading_notice',
83 self::CAPABILITY => 'install_plugins',
84 self::NOT_HAS_OPTION => 'ea11y_access_token',
85 ],
86 ];
87 if ( ! $hint_key ) {
88 return $hints;
89 }
90
91 return $hints[ $hint_key ] ?? [];
92 }
93
94 /**
95 * Get_notice_icon
96 *
97 * @return string
98 */
99 public static function get_notice_icon(): string {
100 return '<div class="elementor-control-notice-icon">
101 <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
102 <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"/>
103 </svg>
104 </div>';
105 }
106
107 /**
108 * Get_notice_template
109 *
110 * Print or Retrieve the notice template.
111 *
112 * @param array $notice
113 * @param bool $should_return
114 *
115 * @return string|void
116 */
117 public static function get_notice_template( array $notice, bool $should_return = false ) {
118 $default_settings = [
119 'type' => 'info',
120 'icon' => false,
121 'heading' => '',
122 'content' => '',
123 'dismissible' => false,
124 'button_text' => '',
125 'button_event' => '',
126 'button_data' => [],
127 'display' => false,
128 ];
129 $notice_settings = array_merge( $default_settings, $notice );
130
131 if ( empty( $notice_settings['heading'] ) && empty( $notice_settings['content'] ) ) {
132 return '';
133 }
134
135 if ( ! in_array( $notice_settings['type'], self::get_notice_types(), true ) ) {
136 $notice_settings['type'] = 'info';
137 }
138
139 $icon = '';
140 $heading = '';
141 $content = '';
142 $dismissible = '';
143 $button = '';
144
145 if ( $notice_settings['icon'] ) {
146 $icon = self::get_notice_icon();
147 }
148
149 if ( ! empty( $notice_settings['heading'] ) ) {
150 $heading = '<div class="elementor-control-notice-main-heading">' . $notice_settings['heading'] . '</div>';
151 }
152
153 if ( ! empty( $notice_settings['content'] ) ) {
154 $content = '<div class="elementor-control-notice-main-content">' . $notice_settings['content'] . '</div>';
155 }
156
157 if ( ! empty( $notice_settings['button_text'] ) ) {
158 $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( wp_json_encode( $notice_settings['button_data'] ) ) . '"' : '';
159 $button = '<div class="elementor-control-notice-main-actions">
160 <button type="button" class="e-btn e-' . $notice_settings['type'] . ' e-btn-1" data-event="' . $notice_settings['button_event'] . '"' . $button_settings . '>
161 ' . $notice_settings['button_text'] . '
162 </button>
163 </div>';
164 }
165
166 if ( $notice_settings['dismissible'] ) {
167 $dismissible = '<button class="elementor-control-notice-dismiss tooltip-target" data-event="' . $notice_settings['dismissible'] . '" data-tooltip="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '" aria-label="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '">
168 <i class="eicon eicon-close" aria-hidden="true"></i>
169 </button>';
170 }
171
172 $notice_template = sprintf( '<div class="elementor-control-notice elementor-control-notice-type-%1$s" data-display="%7$s">
173 %2$s
174 <div class="elementor-control-notice-main">
175 %3$s
176 %4$s
177 %5$s
178 </div>
179 %6$s
180 </div>',
181 $notice_settings['type'],
182 $icon,
183 $heading,
184 $content,
185 $button,
186 $dismissible,
187 $notice_settings['display']
188 );
189
190 if ( $should_return ) {
191 return $notice_template;
192 }
193 echo wp_kses( $notice_template, self::get_notice_allowed_html() );
194 }
195
196 /**
197 * Get_plugin_install_url
198 *
199 * @param $plugin_slug
200 *
201 * @return string
202 */
203 public static function get_plugin_install_url( $plugin_slug ): string {
204 $action = 'install-plugin';
205 return wp_nonce_url(
206 add_query_arg(
207 [
208 'action' => $action,
209 'plugin' => $plugin_slug,
210 ],
211 admin_url( 'update.php' )
212 ),
213 $action . '_' . $plugin_slug
214 );
215 }
216
217 /**
218 * Get_plugin_activate_url
219 *
220 * @param $plugin_slug
221 *
222 * @return string
223 */
224 public static function get_plugin_activate_url( $plugin_slug ): string {
225 $path = "$plugin_slug/$plugin_slug.php";
226 return wp_nonce_url(
227 admin_url( 'plugins.php?action=activate&plugin=' . $path ),
228 'activate-plugin_' . $path
229 );
230 }
231
232 /**
233 * Is_dismissed
234 *
235 * @param $key
236 *
237 * @return bool
238 */
239 public static function is_dismissed( $key ): bool {
240 $dismissed = User::get_dismissed_editor_notices();
241 return in_array( $key, $dismissed, true );
242 }
243
244 /**
245 * Should_display_hint
246 *
247 * @param $hint_key
248 *
249 * @return bool
250 */
251 public static function should_display_hint( $hint_key ): bool {
252 $hint = self::get_hints( $hint_key );
253 if ( empty( $hint ) ) {
254 return false;
255 }
256
257 foreach ( $hint as $key => $value ) {
258 switch ( $key ) {
259 case self::DISMISSED:
260 if ( self::is_dismissed( $value ) ) {
261 return false;
262 }
263
264 break;
265
266 case self::CAPABILITY:
267 if ( ! current_user_can( $value ) ) {
268 return false;
269 }
270
271 break;
272
273 case self::DEFINED:
274 if ( defined( $value ) ) {
275 return false;
276 }
277
278 break;
279
280 case self::NOT_DEFINED:
281 if ( ! defined( $value ) ) {
282 return false;
283 }
284
285 break;
286
287 case self::PLUGIN_INSTALLED:
288 if ( ! self::is_plugin_installed( $value ) ) {
289 return false;
290 }
291
292 break;
293
294 case self::PLUGIN_ACTIVE:
295 if ( ! self::is_plugin_active( $value ) ) {
296 return false;
297 }
298
299 break;
300
301 case self::NOT_HAS_OPTION:
302 $option = get_option( $value );
303 if ( ! empty( $option ) ) {
304 return false;
305 }
306
307 break;
308 }
309 }
310 return true;
311 }
312
313 private static function is_conflict_plugin_installed(): bool {
314 if ( ! Utils::has_pro() ) {
315 return false;
316 }
317
318 $conflicting_plugins = [
319 'imagify/imagify.php',
320 'optimole-wp/optimole-wp.php',
321 'ewww-image-optimizer/ewww-image-optimizer.php',
322 'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
323 'kraken-image-optimizer/kraken.php',
324 'shortpixel-image-optimiser/wp-shortpixel.php',
325 'wp-smushit/wp-smush.php',
326 'wp-smush-pro/wp-smush.php',
327 'tiny-compress-images/tiny-compress-images.php',
328 ];
329
330 foreach ( $conflicting_plugins as $plugin ) {
331 if ( self::is_plugin_active( $plugin ) ) {
332 return true;
333 }
334 }
335
336 return false;
337 }
338
339 /**
340 * Is_plugin_installed
341 *
342 * @param $plugin
343 *
344 * @return bool
345 */
346 public static function is_plugin_installed( $plugin ): bool {
347 if ( ! function_exists( 'get_plugins' ) ) {
348 require_once ABSPATH . 'wp-admin/includes/plugin.php';
349 }
350
351 $plugins = get_plugins();
352 $plugin = self::ensure_plugin_folder( $plugin );
353 return ! empty( $plugins[ $plugin ] );
354 }
355
356 /**
357 * Is_plugin_active
358 *
359 * @param $plugin
360 *
361 * @return bool
362 */
363 public static function is_plugin_active( $plugin ): bool {
364 $plugin = self::ensure_plugin_folder( $plugin );
365 return is_plugin_active( $plugin );
366 }
367
368 /**
369 * Get_plugin_action_url
370 *
371 * @param $plugin
372 *
373 * @return string
374 */
375 public static function get_plugin_action_url( $plugin ): string {
376 if ( ! self::is_plugin_installed( $plugin ) ) {
377 return self::get_plugin_install_url( $plugin );
378 }
379
380 if ( ! self::is_plugin_active( $plugin ) ) {
381 return self::get_plugin_activate_url( $plugin );
382 }
383
384 return '';
385 }
386
387 /**
388 * Ensure_plugin_folder
389 *
390 * @param $plugin
391 *
392 * @return string
393 */
394 private static function ensure_plugin_folder( $plugin ): string {
395 if ( false === strpos( $plugin, '/' ) ) {
396 $plugin = $plugin . '/' . $plugin . '.php';
397 }
398 return $plugin;
399 }
400
401 /**
402 * Get_notice_allowed_html
403 *
404 * @return array[]
405 */
406 public static function get_notice_allowed_html(): array {
407 return [
408 'div' => [
409 'class' => [],
410 'data-display' => [],
411 ],
412 'svg' => [
413 'width' => [],
414 'height' => [],
415 'viewbox' => [],
416 'fill' => [],
417 'xmlns' => [],
418 ],
419 'path' => [
420 'd' => [],
421 'stroke' => [],
422 'stroke-width' => [],
423 'stroke-linecap' => [],
424 'stroke-linejoin' => [],
425 ],
426 'button' => [
427 'class' => [],
428 'data-event' => [],
429 'data-settings' => [],
430 'data-tooltip' => [],
431 ],
432 'i' => [
433 'class' => [],
434 'aria-hidden' => [],
435 ],
436 'span' => [
437 'class' => [],
438 ],
439 'a' => [
440 'href' => [],
441 'style' => [],
442 'target' => [],
443 ],
444 ];
445 }
446
447 public static function is_plugin_connected( $option_prefix ): bool {
448 return ! empty( get_option( $option_prefix . '_access_token' ) );
449 }
450
451 private static function get_all_widget_content( $step ) {
452 $steps = [
453 self::INSTALL => esc_html__( 'Install Ally to add an accessibility widget visitors can use to navigate your site.', 'elementor' ),
454 self::ACTIVATE => esc_html__( 'Activate the Ally plugin to turn its accessibility features on across your site.', 'elementor' ),
455 self::CONNECT => esc_html__( "Connect the Ally plugin to your account to access all of it's accessibility features.", 'elementor' ),
456 self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ),
457 ];
458 return $steps[ $step ];
459 }
460
461 private static function get_all_widget_action_button( $step ) {
462 $steps = [
463 self::INSTALL => esc_html__( 'install Now', 'elementor' ),
464 self::ACTIVATE => esc_html__( 'Activate', 'elementor' ),
465 self::CONNECT => esc_html__( 'Connect', 'elementor' ),
466 self::CUSTOMIZE => esc_html__( 'Customize', 'elementor' ),
467 ];
468 return $steps[ $step ];
469 }
470
471 private static function get_all_widget_action_url( $step ) {
472 if ( in_array( $step, [ self::INSTALL, self::ACTIVATE ], true ) ) {
473 $campaign_data = [
474 'name' => 'elementor_ea11y_campaign',
475 'campaign' => 'acc-usability-widget-plg-ally',
476 'source' => 'editor-ally-widget',
477 'medium' => 'editor',
478 ];
479 return Admin_Notices::add_plg_campaign_data( self::get_plugin_action_url( 'pojo-accessibility' ), $campaign_data );
480 }
481 return self::CONNECT === $step ? admin_url( 'admin.php?page=accessibility-settings' ) : admin_url( 'admin.php?page=accessibility-settings#design' );
482 }
483
484 private static function get_ally_cta_button( $step ) {
485 return [
486 'text' => self::get_all_widget_action_button( $step ),
487 'url' => self::get_all_widget_action_url( $step ),
488 'classes' => [ 'elementor-button' ],
489 ];
490 }
491
492 public static function get_ally_action_data(): array {
493 $plugin_slug = 'pojo-accessibility';
494 $is_installed = self::is_plugin_installed( $plugin_slug );
495 $is_active = self::is_plugin_active( $plugin_slug );
496 $is_connected = self::is_plugin_connected( 'ea11y' );
497
498 if ( ! $is_installed ) {
499 $step = self::INSTALL;
500 } elseif ( ! $is_active ) {
501 $step = self::ACTIVATE;
502 } elseif ( ! $is_connected ) {
503 $step = self::CONNECT;
504 } else {
505 $step = self::CUSTOMIZE;
506 }
507
508 $data = [
509 'title' => __( 'Ally web accessibility', 'elementor' ),
510 'content' => self::get_all_widget_content( $step ),
511 'action_button' => self::get_ally_cta_button( $step ),
512 ];
513
514 return $data;
515 }
516 }
517