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

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