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

432 lines 10.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
11 class Hints {
12
13 const INFO = 'info';
14 const SUCCESS = 'success';
15 const WARNING = 'warning';
16 const DANGER = 'danger';
17
18 const DEFINED = 'defined';
19 const NOT_DEFINED = 'not_defined';
20 const DISMISSED = 'dismissed';
21 const CAPABILITY = 'capability';
22 const PLUGIN_INSTALLED = 'plugin_installed';
23 const PLUGIN_ACTIVE = 'plugin_active';
24 const NOT_HAS_OPTION = 'not_has_option';
25
26 /**
27 * Get_notice_types
28 *
29 * @return string[]
30 */
31 public static function get_notice_types(): array {
32 return [
33 self::INFO,
34 self::SUCCESS,
35 self::WARNING,
36 self::DANGER,
37 ];
38 }
39
40 /**
41 * Get_hints
42 *
43 * @param $hint_key
44 *
45 * @return array|string[]|\string[][]
46 */
47 public static function get_hints( $hint_key = null ): array {
48 $hints = [
49 'image-optimization-once' => [
50 self::DISMISSED => 'image-optimization-once',
51 self::CAPABILITY => 'install_plugins',
52 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
53 ],
54 'image-optimization-once-media-modal' => [
55 self::DISMISSED => 'image-optimization-once-media-modal',
56 self::CAPABILITY => 'install_plugins',
57 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
58 ],
59 'image-optimization' => [
60 self::DISMISSED => 'image_optimizer_hint',
61 self::CAPABILITY => 'install_plugins',
62 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
63 ],
64 'image-optimization-connect' => [
65 self::DISMISSED => 'image_optimizer_hint',
66 self::CAPABILITY => 'manage_options',
67 self::NOT_DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
68 self::NOT_HAS_OPTION => 'image_optimizer_access_token',
69 ],
70 'image-optimization-media-modal' => [
71 self::DISMISSED => 'image-optimization-media-modal',
72 self::CAPABILITY => 'install_plugins',
73 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
74 ],
75 ];
76 if ( ! $hint_key ) {
77 return $hints;
78 }
79
80 return $hints[ $hint_key ] ?? [];
81 }
82
83 /**
84 * Get_notice_icon
85 *
86 * @return string
87 */
88 public static function get_notice_icon(): string {
89 return '<div class="elementor-control-notice-icon">
90 <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
91 <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"/>
92 </svg>
93 </div>';
94 }
95
96 /**
97 * Get_notice_template
98 *
99 * Print or Retrieve the notice template.
100 *
101 * @param array $notice
102 * @param bool $return
103 *
104 * @return string|void
105 */
106 public static function get_notice_template( array $notice, bool $return = false ) {
107 $default_settings = [
108 'type' => 'info',
109 'icon' => false,
110 'heading' => '',
111 'content' => '',
112 'dismissible' => false,
113 'button_text' => '',
114 'button_event' => '',
115 'button_data' => [],
116 'display' => false,
117 ];
118 $notice_settings = array_merge( $default_settings, $notice );
119
120 if ( empty( $notice_settings['heading'] ) && empty( $notice_settings['content'] ) ) {
121 return '';
122 }
123
124 if ( ! in_array( $notice_settings['type'], self::get_notice_types(), true ) ) {
125 $notice_settings['type'] = 'info';
126 }
127
128 $icon = '';
129 $heading = '';
130 $content = '';
131 $dismissible = '';
132 $button = '';
133
134 if ( $notice_settings['icon'] ) {
135 $icon = self::get_notice_icon();
136 }
137
138 if ( ! empty( $notice_settings['heading'] ) ) {
139 $heading = '<div class="elementor-control-notice-main-heading">' . $notice_settings['heading'] . '</div>';
140 }
141
142 if ( ! empty( $notice_settings['content'] ) ) {
143 $content = '<div class="elementor-control-notice-main-content">' . $notice_settings['content'] . '</div>';
144 }
145
146 if ( ! empty( $notice_settings['button_text'] ) ) {
147 $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( wp_json_encode( $notice_settings['button_data'] ) ) . '"' : '';
148 $button = '<div class="elementor-control-notice-main-actions">
149 <button type="button" class="e-btn e-' . $notice_settings['type'] . ' e-btn-1" data-event="' . $notice_settings['button_event'] . '"' . $button_settings . '>
150 ' . $notice_settings['button_text'] . '
151 </button>
152 </div>';
153 }
154
155 if ( $notice_settings['dismissible'] ) {
156 $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' ) . '">
157 <i class="eicon eicon-close" aria-hidden="true"></i>
158 </button>';
159 }
160
161 $notice_template = sprintf( '<div class="elementor-control-notice elementor-control-notice-type-%1$s" data-display="%7$s">
162 %2$s
163 <div class="elementor-control-notice-main">
164 %3$s
165 %4$s
166 %5$s
167 </div>
168 %6$s
169 </div>',
170 $notice_settings['type'],
171 $icon,
172 $heading,
173 $content,
174 $button,
175 $dismissible,
176 $notice_settings['display']
177 );
178
179 if ( $return ) {
180 return $notice_template;
181 }
182 echo wp_kses( $notice_template, self::get_notice_allowed_html() );
183 }
184
185 /**
186 * Get_plugin_install_url
187 *
188 * @param $plugin_slug
189 *
190 * @return string
191 */
192 public static function get_plugin_install_url( $plugin_slug ): string {
193 $action = 'install-plugin';
194 return wp_nonce_url(
195 add_query_arg(
196 [
197 'action' => $action,
198 'plugin' => $plugin_slug,
199 ],
200 admin_url( 'update.php' )
201 ),
202 $action . '_' . $plugin_slug
203 );
204 }
205
206 /**
207 * Get_plugin_activate_url
208 *
209 * @param $plugin_slug
210 *
211 * @return string
212 */
213 public static function get_plugin_activate_url( $plugin_slug ): string {
214 $path = "$plugin_slug/$plugin_slug.php";
215 return wp_nonce_url(
216 admin_url( 'plugins.php?action=activate&plugin=' . $path ),
217 'activate-plugin_' . $path
218 );
219 }
220
221 /**
222 * Is_dismissed
223 *
224 * @param $key
225 *
226 * @return bool
227 */
228 public static function is_dismissed( $key ): bool {
229 $dismissed = User::get_dismissed_editor_notices();
230 return in_array( $key, $dismissed, true );
231 }
232
233 /**
234 * Should_display_hint
235 *
236 * @param $hint_key
237 *
238 * @return bool
239 */
240 public static function should_display_hint( $hint_key ): bool {
241 $hint = self::get_hints( $hint_key );
242 if ( empty( $hint ) ) {
243 return false;
244 }
245
246 foreach ( $hint as $key => $value ) {
247 switch ( $key ) {
248 case self::DISMISSED:
249 if ( self::is_dismissed( $value ) ) {
250 return false;
251 }
252
253 break;
254
255 case self::CAPABILITY:
256 if ( ! current_user_can( $value ) ) {
257 return false;
258 }
259
260 break;
261
262 case self::DEFINED:
263 if ( defined( $value ) ) {
264 return false;
265 }
266
267 break;
268
269 case self::NOT_DEFINED:
270 if ( ! defined( $value ) ) {
271 return false;
272 }
273
274 break;
275
276 case self::PLUGIN_INSTALLED:
277 if ( ! self::is_plugin_installed( $value ) ) {
278 return false;
279 }
280
281 break;
282
283 case self::PLUGIN_ACTIVE:
284 if ( ! self::is_plugin_active( $value ) ) {
285 return false;
286 }
287
288 break;
289
290 case self::NOT_HAS_OPTION:
291 $option = get_option( $value );
292 if ( ! empty( $option ) ) {
293 return false;
294 }
295
296 break;
297 }
298 }
299 return true;
300 }
301
302 private static function is_conflict_plugin_installed(): bool {
303 if ( ! Utils::has_pro() ) {
304 return false;
305 }
306
307 $conflicting_plugins = [
308 'imagify/imagify.php',
309 'optimole-wp/optimole-wp.php',
310 'ewww-image-optimizer/ewww-image-optimizer.php',
311 'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
312 'kraken-image-optimizer/kraken.php',
313 'shortpixel-image-optimiser/wp-shortpixel.php',
314 'wp-smushit/wp-smush.php',
315 'wp-smush-pro/wp-smush.php',
316 'tiny-compress-images/tiny-compress-images.php',
317 ];
318
319 foreach ( $conflicting_plugins as $plugin ) {
320 if ( self::is_plugin_active( $plugin ) ) {
321 return true;
322 }
323 }
324
325 return false;
326 }
327
328 /**
329 * Is_plugin_installed
330 *
331 * @param $plugin
332 *
333 * @return bool
334 */
335 public static function is_plugin_installed( $plugin ): bool {
336 $plugins = get_plugins();
337 $plugin = self::ensure_plugin_folder( $plugin );
338 return ! empty( $plugins[ $plugin ] );
339 }
340
341 /**
342 * Is_plugin_active
343 *
344 * @param $plugin
345 *
346 * @return bool
347 */
348 public static function is_plugin_active( $plugin ): bool {
349 $plugin = self::ensure_plugin_folder( $plugin );
350 return is_plugin_active( $plugin );
351 }
352
353 /**
354 * Get_plugin_action_url
355 *
356 * @param $plugin
357 *
358 * @return string
359 */
360 public static function get_plugin_action_url( $plugin ): string {
361 if ( ! self::is_plugin_installed( $plugin ) ) {
362 return self::get_plugin_install_url( $plugin );
363 }
364
365 if ( ! self::is_plugin_active( $plugin ) ) {
366 return self::get_plugin_activate_url( $plugin );
367 }
368
369 return '';
370 }
371
372 /**
373 * Ensure_plugin_folder
374 *
375 * @param $plugin
376 *
377 * @return string
378 */
379 private static function ensure_plugin_folder( $plugin ): string {
380 if ( false === strpos( $plugin, '/' ) ) {
381 $plugin = $plugin . '/' . $plugin . '.php';
382 }
383 return $plugin;
384 }
385
386 /**
387 * Get_notice_allowed_html
388 *
389 * @return array[]
390 */
391 public static function get_notice_allowed_html(): array {
392 return [
393 'div' => [
394 'class' => [],
395 'data-display' => [],
396 ],
397 'svg' => [
398 'width' => [],
399 'height' => [],
400 'viewbox' => [],
401 'fill' => [],
402 'xmlns' => [],
403 ],
404 'path' => [
405 'd' => [],
406 'stroke' => [],
407 'stroke-width' => [],
408 'stroke-linecap' => [],
409 'stroke-linejoin' => [],
410 ],
411 'button' => [
412 'class' => [],
413 'data-event' => [],
414 'data-settings' => [],
415 'data-tooltip' => [],
416 ],
417 'i' => [
418 'class' => [],
419 'aria-hidden' => [],
420 ],
421 'span' => [
422 'class' => [],
423 ],
424 'a' => [
425 'href' => [],
426 'style' => [],
427 'target' => [],
428 ],
429 ];
430 }
431 }
432