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

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