PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 4.2.0, at core/utils/hints.php

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