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

357 lines 8.9 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
10 class Hints {
11 const INFO = 'info';
12 const SUCCESS = 'success';
13 const WARNING = 'warning';
14 const DANGER = 'danger';
15
16 const DEFINED = 'defined';
17 const DISMISSED = 'dismissed';
18 const CAPABILITY = 'capability';
19 const PLUGIN_INSTALLED = 'plugin_installed';
20 const PLUGIN_ACTIVE = 'plugin_active';
21
22 /**
23 * get_notice_types
24 * @return string[]
25 */
26 public static function get_notice_types(): array {
27 return [
28 self::INFO,
29 self::SUCCESS,
30 self::WARNING,
31 self::DANGER,
32 ];
33 }
34
35 /**
36 * get_hints
37 *
38 * @param $hint_key
39 *
40 * @return array|string[]|\string[][]
41 */
42 public static function get_hints( $hint_key = null ): array {
43 $hints = [
44 'image-optimization-once' => [
45 self::DISMISSED => 'image-optimization-once',
46 self::CAPABILITY => 'install_plugins',
47 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
48 ],
49 'image-optimization-once-media-modal' => [
50 self::DISMISSED => 'image-optimization-once-media-modal',
51 self::CAPABILITY => 'install_plugins',
52 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
53 ],
54 'image-optimization' => [
55 self::DISMISSED => 'image_optimizer_hint',
56 self::CAPABILITY => 'install_plugins',
57 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
58 ],
59 'image-optimization-media-modal' => [
60 self::DISMISSED => 'image-optimization-media-modal',
61 self::CAPABILITY => 'install_plugins',
62 self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
63 ],
64 ];
65 if ( ! $hint_key ) {
66 return $hints;
67 }
68
69 return $hints[ $hint_key ] ?? [];
70 }
71
72 /**
73 * get_notice_icon
74 * @return string
75 */
76 public static function get_notice_icon(): string {
77 return '<div class="elementor-control-notice-icon">
78 <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
79 <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"/>
80 </svg>
81 </div>';
82 }
83
84 /**
85 * get_notice_template
86 *
87 * Print or Retrieve the notice template.
88 * @param array $notice
89 * @param bool $return
90 *
91 * @return string|void
92 */
93 public static function get_notice_template( array $notice, bool $return = false ) {
94 $default_settings = [
95 'type' => 'info',
96 'icon' => false,
97 'heading' => '',
98 'content' => '',
99 'dismissible' => false,
100 'button_text' => '',
101 'button_event' => '',
102 'button_data' => [],
103 'display' => false,
104 ];
105 $notice_settings = array_merge( $default_settings, $notice );
106
107 if ( empty( $notice_settings['heading'] ) && empty( $notice_settings['content'] ) ) {
108 return '';
109 }
110
111 if ( ! in_array( $notice_settings['type'], self::get_notice_types(), true ) ) {
112 $notice_settings['type'] = 'info';
113 }
114
115 $icon = '';
116 $heading = '';
117 $content = '';
118 $dismissible = '';
119 $button = '';
120
121 if ( $notice_settings['icon'] ) {
122 $icon = self::get_notice_icon();
123 }
124
125 if ( ! empty( $notice_settings['heading'] ) ) {
126 $heading = '<div class="elementor-control-notice-main-heading">' . $notice_settings['heading'] . '</div>';
127 }
128
129 if ( ! empty( $notice_settings['content'] ) ) {
130 $content = '<div class="elementor-control-notice-main-content">' . $notice_settings['content'] . '</div>';
131 }
132
133 if ( ! empty( $notice_settings['button_text'] ) ) {
134 $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( json_encode( $notice_settings['button_data'] ) ) . '"' : '';
135 $button = '<div class="elementor-control-notice-main-actions">
136 <button type="button" class="e-btn e-' . $notice_settings['type'] . ' e-btn-1" data-event="' . $notice_settings['button_event'] . '"' . $button_settings . '>
137 ' . $notice_settings['button_text'] . '
138 </button>
139 </div>';
140 }
141
142 if ( $notice_settings['dismissible'] ) {
143 $dismissible = '<button class="elementor-control-notice-dismiss tooltip-target" data-event="' . $notice_settings['dismissible'] . '" data-tooltip="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '">
144 <i class="eicon eicon-close" aria-hidden="true"></i>
145 <span class="elementor-screen-only">' . esc_html__( 'Don’t show again.', 'elementor' ) . '</span>
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 return admin_url( 'plugins.php' );
201 }
202
203 /**
204 * is_dismissed
205 * @param $key
206 *
207 * @return bool
208 */
209 public static function is_dismissed( $key ): bool {
210 $dismissed = User::get_dismissed_editor_notices();
211 return in_array( $key, $dismissed, true );
212 }
213
214 /**
215 * should_display_hint
216 * @param $hint_key
217 *
218 * @return bool
219 */
220 public static function should_display_hint( $hint_key ): bool {
221 $hint = self::get_hints( $hint_key );
222 if ( empty( $hint ) ) {
223 return false;
224 }
225
226 foreach ( $hint as $key => $value ) {
227 switch ( $key ) {
228 case self::DISMISSED:
229 if ( self::is_dismissed( $value ) ) {
230 return false;
231 }
232 break;
233 case self::CAPABILITY:
234 if ( ! current_user_can( $value ) ) {
235 return false;
236 }
237 break;
238 case self::DEFINED:
239 if ( defined( $value ) ) {
240 return false;
241 }
242 break;
243 case self::PLUGIN_INSTALLED:
244 if ( ! self::is_plugin_installed( $value ) ) {
245 return false;
246 }
247 break;
248 case self::PLUGIN_ACTIVE:
249 if ( ! self::is_plugin_active( $value ) ) {
250 return false;
251 }
252 break;
253 }
254 }
255 return true;
256 }
257
258 /**
259 * is_plugin_installed
260 * @param $plugin
261 *
262 * @return bool
263 */
264 public static function is_plugin_installed( $plugin ) : bool {
265 $plugins = get_plugins();
266 $plugin = self::ensure_plugin_folder( $plugin );
267 return ! empty( $plugins[ $plugin ] );
268 }
269
270 /**
271 * is_plugin_active
272 * @param $plugin
273 *
274 * @return bool
275 */
276 public static function is_plugin_active( $plugin ): bool {
277 $plugin = self::ensure_plugin_folder( $plugin );
278 return is_plugin_active( $plugin );
279 }
280
281 /**
282 * get_plugin_action_url
283 * @param $plugin
284 *
285 * @return string
286 */
287 public static function get_plugin_action_url( $plugin ): string {
288 if ( ! self::is_plugin_installed( $plugin ) ) {
289 return self::get_plugin_install_url( $plugin );
290 }
291
292 if ( ! self::is_plugin_active( $plugin ) ) {
293 return self::get_plugin_activate_url( $plugin );
294 }
295
296 return '';
297 }
298
299 /**
300 * ensure_plugin_folder
301 * @param $plugin
302 *
303 * @return string
304 */
305 private static function ensure_plugin_folder( $plugin ): string {
306 if ( false === strpos( $plugin, '/' ) ) {
307 $plugin = $plugin . '/' . $plugin . '.php';
308 }
309 return $plugin;
310 }
311
312 /**
313 * get_notice_allowed_html
314 * @return array[]
315 */
316 public static function get_notice_allowed_html(): array {
317 return [
318 'div' => [
319 'class' => [],
320 'data-display' => [],
321 ],
322 'svg' => [
323 'width' => [],
324 'height' => [],
325 'viewbox' => [],
326 'fill' => [],
327 'xmlns' => [],
328 ],
329 'path' => [
330 'd' => [],
331 'stroke' => [],
332 'stroke-width' => [],
333 'stroke-linecap' => [],
334 'stroke-linejoin' => [],
335 ],
336 'button' => [
337 'class' => [],
338 'data-event' => [],
339 'data-settings' => [],
340 'data-tooltip' => [],
341 ],
342 'i' => [
343 'class' => [],
344 'aria-hidden' => [],
345 ],
346 'span' => [
347 'class' => [],
348 ],
349 'a' => [
350 'href' => [],
351 'style' => [],
352 'target' => [],
353 ],
354 ];
355 }
356 }
357