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

388 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 * @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' ) . '">
145 <i class="eicon eicon-close" aria-hidden="true"></i>
146 <span class="elementor-screen-only">' . esc_html__( 'Don’t show again.', 'elementor' ) . '</span>
147 </button>';
148 }
149
150 $notice_template = sprintf( '<div class="elementor-control-notice elementor-control-notice-type-%1$s" data-display="%7$s">
151 %2$s
152 <div class="elementor-control-notice-main">
153 %3$s
154 %4$s
155 %5$s
156 </div>
157 %6$s
158 </div>',
159 $notice_settings['type'],
160 $icon,
161 $heading,
162 $content,
163 $button,
164 $dismissible,
165 $notice_settings['display']
166 );
167
168 if ( $return ) {
169 return $notice_template;
170 }
171 echo wp_kses( $notice_template, self::get_notice_allowed_html() );
172 }
173
174 /**
175 * get_plugin_install_url
176 * @param $plugin_slug
177 *
178 * @return string
179 */
180 public static function get_plugin_install_url( $plugin_slug ): string {
181 $action = 'install-plugin';
182 return wp_nonce_url(
183 add_query_arg(
184 [
185 'action' => $action,
186 'plugin' => $plugin_slug,
187 ],
188 admin_url( 'update.php' )
189 ),
190 $action . '_' . $plugin_slug
191 );
192 }
193
194 /**
195 * get_plugin_activate_url
196 * @param $plugin_slug
197 *
198 * @return string
199 */
200 public static function get_plugin_activate_url( $plugin_slug ): string {
201 $path = "$plugin_slug/$plugin_slug.php";
202 return wp_nonce_url(
203 admin_url( 'plugins.php?action=activate&plugin=' . $path ),
204 'activate-plugin_' . $path
205 );
206 }
207
208 /**
209 * is_dismissed
210 * @param $key
211 *
212 * @return bool
213 */
214 public static function is_dismissed( $key ): bool {
215 $dismissed = User::get_dismissed_editor_notices();
216 return in_array( $key, $dismissed, true );
217 }
218
219 /**
220 * should_display_hint
221 * @param $hint_key
222 *
223 * @return bool
224 */
225 public static function should_display_hint( $hint_key ): bool {
226 $hint = self::get_hints( $hint_key );
227 if ( empty( $hint ) ) {
228 return false;
229 }
230
231 foreach ( $hint as $key => $value ) {
232 switch ( $key ) {
233 case self::DISMISSED:
234 if ( self::is_dismissed( $value ) ) {
235 return false;
236 }
237 break;
238 case self::CAPABILITY:
239 if ( ! current_user_can( $value ) ) {
240 return false;
241 }
242 break;
243 case self::DEFINED:
244 if ( defined( $value ) ) {
245 return false;
246 }
247 break;
248 case self::PLUGIN_INSTALLED:
249 if ( ! self::is_plugin_installed( $value ) ) {
250 return false;
251 }
252 break;
253 case self::PLUGIN_ACTIVE:
254 if ( ! self::is_plugin_active( $value ) ) {
255 return false;
256 }
257 break;
258 }
259 }
260 return true;
261 }
262
263 private static function is_conflict_plugin_installed(): bool {
264 if ( ! Utils::has_pro() ) {
265 return false;
266 }
267
268 $conflicting_plugins = [
269 'imagify/imagify.php',
270 'optimole-wp/optimole-wp.php',
271 'ewww-image-optimizer/ewww-image-optimizer.php',
272 'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
273 'kraken-image-optimizer/kraken.php',
274 'shortpixel-image-optimiser/wp-shortpixel.php',
275 'wp-smushit/wp-smush.php',
276 'wp-smush-pro/wp-smush.php',
277 'tiny-compress-images/tiny-compress-images.php',
278 ];
279
280 foreach ( $conflicting_plugins as $plugin ) {
281 if ( self::is_plugin_active( $plugin ) ) {
282 return true;
283 }
284 }
285
286 return false;
287 }
288
289 /**
290 * is_plugin_installed
291 * @param $plugin
292 *
293 * @return bool
294 */
295 public static function is_plugin_installed( $plugin ) : bool {
296 $plugins = get_plugins();
297 $plugin = self::ensure_plugin_folder( $plugin );
298 return ! empty( $plugins[ $plugin ] );
299 }
300
301 /**
302 * is_plugin_active
303 * @param $plugin
304 *
305 * @return bool
306 */
307 public static function is_plugin_active( $plugin ): bool {
308 $plugin = self::ensure_plugin_folder( $plugin );
309 return is_plugin_active( $plugin );
310 }
311
312 /**
313 * get_plugin_action_url
314 * @param $plugin
315 *
316 * @return string
317 */
318 public static function get_plugin_action_url( $plugin ): string {
319 if ( ! self::is_plugin_installed( $plugin ) ) {
320 return self::get_plugin_install_url( $plugin );
321 }
322
323 if ( ! self::is_plugin_active( $plugin ) ) {
324 return self::get_plugin_activate_url( $plugin );
325 }
326
327 return '';
328 }
329
330 /**
331 * ensure_plugin_folder
332 * @param $plugin
333 *
334 * @return string
335 */
336 private static function ensure_plugin_folder( $plugin ): string {
337 if ( false === strpos( $plugin, '/' ) ) {
338 $plugin = $plugin . '/' . $plugin . '.php';
339 }
340 return $plugin;
341 }
342
343 /**
344 * get_notice_allowed_html
345 * @return array[]
346 */
347 public static function get_notice_allowed_html(): array {
348 return [
349 'div' => [
350 'class' => [],
351 'data-display' => [],
352 ],
353 'svg' => [
354 'width' => [],
355 'height' => [],
356 'viewbox' => [],
357 'fill' => [],
358 'xmlns' => [],
359 ],
360 'path' => [
361 'd' => [],
362 'stroke' => [],
363 'stroke-width' => [],
364 'stroke-linecap' => [],
365 'stroke-linejoin' => [],
366 ],
367 'button' => [
368 'class' => [],
369 'data-event' => [],
370 'data-settings' => [],
371 'data-tooltip' => [],
372 ],
373 'i' => [
374 'class' => [],
375 'aria-hidden' => [],
376 ],
377 'span' => [
378 'class' => [],
379 ],
380 'a' => [
381 'href' => [],
382 'style' => [],
383 'target' => [],
384 ],
385 ];
386 }
387 }
388