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

542 lines 14.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\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 $plugin = self::ensure_plugin_folder( $plugin );
366 return is_plugin_active( $plugin );
367 }
368
369 /**
370 * Get_plugin_action_url
371 *
372 * @param $plugin
373 *
374 * @return string
375 */
376 public static function get_plugin_action_url( $plugin ): string {
377 if ( ! self::is_plugin_installed( $plugin ) ) {
378 return self::get_plugin_install_url( $plugin );
379 }
380
381 if ( ! self::is_plugin_active( $plugin ) ) {
382 return self::get_plugin_activate_url( $plugin );
383 }
384
385 return '';
386 }
387
388 /**
389 * Ensure_plugin_folder
390 *
391 * @param $plugin
392 *
393 * @return string
394 */
395 private static function ensure_plugin_folder( $plugin ): string {
396 if ( false === strpos( $plugin, '/' ) ) {
397 $plugin = $plugin . '/' . $plugin . '.php';
398 }
399 return $plugin;
400 }
401
402 /**
403 * Get_notice_allowed_html
404 *
405 * @return array[]
406 */
407 public static function get_notice_allowed_html(): array {
408 return [
409 'div' => [
410 'class' => [],
411 'data-display' => [],
412 ],
413 'svg' => [
414 'width' => [],
415 'height' => [],
416 'viewbox' => [],
417 'fill' => [],
418 'xmlns' => [],
419 ],
420 'path' => [
421 'd' => [],
422 'stroke' => [],
423 'stroke-width' => [],
424 'stroke-linecap' => [],
425 'stroke-linejoin' => [],
426 ],
427 'button' => [
428 'class' => [],
429 'data-event' => [],
430 'data-settings' => [],
431 'data-tooltip' => [],
432 ],
433 'i' => [
434 'class' => [],
435 'aria-hidden' => [],
436 ],
437 'span' => [
438 'class' => [],
439 ],
440 'a' => [
441 'href' => [],
442 'style' => [],
443 'target' => [],
444 ],
445 ];
446 }
447
448 public static function is_plugin_connected( $option_prefix ): bool {
449 return ! empty( get_option( $option_prefix . '_access_token' ) );
450 }
451
452 public static function is_plugin_connected_to_one_subscription(): bool {
453 return self::is_plugin_connected( 'elementor_one' );
454 }
455
456 private static function get_all_widget_content( $step, $one_subscription = false ) {
457 if ( $one_subscription ) {
458 $steps = [
459 self::INSTALL => esc_html__( 'Want to create an inclusive experience? Install Ally, included in ONE, and add an accessibility widget to your site.', 'elementor' ),
460 self::ACTIVATE => esc_html__( 'Your ONE subscription includes Ally. Activate it to place an accessibility widget on your site.', 'elementor' ),
461 self::CONNECT => esc_html__( "Connect the Ally plugin to your account to access all of it's accessibility features.", 'elementor' ),
462 self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ),
463 ];
464 } else {
465 $steps = [
466 self::INSTALL => esc_html__( 'Install Ally to add an accessibility widget visitors can use to navigate your site.', 'elementor' ),
467 self::ACTIVATE => esc_html__( 'Activate the Ally plugin to turn its accessibility features on across your site.', 'elementor' ),
468 self::CONNECT => esc_html__( "Connect the Ally plugin to your account to access all of it's accessibility features.", 'elementor' ),
469 self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ),
470 ];
471 }
472 return $steps[ $step ];
473 }
474
475 private static function get_all_widget_action_button( $step ) {
476 $steps = [
477 self::INSTALL => esc_html__( 'Install now', 'elementor' ),
478 self::ACTIVATE => esc_html__( 'Activate now', 'elementor' ),
479 self::CONNECT => esc_html__( 'Connect now', 'elementor' ),
480 self::CUSTOMIZE => esc_html__( 'Customize', 'elementor' ),
481 ];
482 return $steps[ $step ];
483 }
484
485 private static function get_all_widget_action_url( $step, $one_subscription = false ) {
486 if ( in_array( $step, [ self::INSTALL, self::ACTIVATE ], true ) ) {
487 $action = ( self::INSTALL === $step ? 'install' : 'activate' );
488 if ( $one_subscription ) {
489 $campaign_data = [
490 'name' => 'elementor_ea11y_campaign',
491 'campaign' => 'acc-usability-widget-plg-ally-one-' . $action,
492 'source' => 'editor-ally-widget-one-' . $action,
493 'medium' => 'editor-one',
494 ];
495 } else {
496 $campaign_data = [
497 'name' => 'elementor_ea11y_campaign',
498 'campaign' => 'acc-usability-widget-plg-ally',
499 'source' => 'editor-ally-widget',
500 'medium' => 'editor',
501 ];
502 }
503 return Admin_Notices::add_plg_campaign_data( self::get_plugin_action_url( 'pojo-accessibility' ), $campaign_data );
504 }
505 return self::CONNECT === $step ? admin_url( 'admin.php?page=accessibility-settings' ) : admin_url( 'admin.php?page=accessibility-settings#design' );
506 }
507
508 private static function get_ally_cta_button( $step, $one_subscription = false ) {
509 return [
510 'text' => self::get_all_widget_action_button( $step ),
511 'url' => self::get_all_widget_action_url( $step, $one_subscription ),
512 'classes' => [ 'elementor-button' ],
513 ];
514 }
515
516 public static function get_ally_action_data(): array {
517 $plugin_slug = 'pojo-accessibility';
518 $is_installed = self::is_plugin_installed( $plugin_slug );
519 $is_active = self::is_plugin_active( $plugin_slug );
520 $is_connected = self::is_plugin_connected( 'ea11y' );
521 $one_subscription = self::is_plugin_connected_to_one_subscription();
522
523 if ( ! $is_installed ) {
524 $step = self::INSTALL;
525 } elseif ( ! $is_active ) {
526 $step = self::ACTIVATE;
527 } elseif ( ! $is_connected ) {
528 $step = self::CONNECT;
529 } else {
530 $step = self::CUSTOMIZE;
531 }
532
533 $data = [
534 'title' => __( 'Ally web accessibility', 'elementor' ),
535 'content' => self::get_all_widget_content( $step, $one_subscription ),
536 'action_button' => self::get_ally_cta_button( $step, $one_subscription ),
537 ];
538
539 return $data;
540 }
541 }
542