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

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