PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.2
Elementor Website Builder – more than just a page builder v3.7.2
4.3.0-beta3 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 All 452 releases
← All changes | includes/managers/icons.php +83 -77 4.1.0-dev33.7.2 View file →
@@ -2,9 +2,8 @@
2 2 namespace Elementor;
3 3
4 4 use Elementor\Core\Files\File_Types\Svg;
5 5 use Elementor\Core\Page_Assets\Data_Managers\Font_Icon_Svg\Manager as Font_Icon_Svg_Data_Manager;
6 -use Elementor\Utils;
7 6
8 7 if ( ! defined( 'ABSPATH' ) ) {
9 8 exit; // Exit if accessed directly.
10 9 }
@@ -23,9 +22,9 @@
23 22 const FONT_ICON_SVG_CLASS_NAME = 'e-font-icon-svg';
24 23
25 24 const LOAD_FA4_SHIM_OPTION_KEY = 'elementor_load_fa4_shim';
26 25
27 - const ELEMENTOR_ICONS_VERSION = '5.49.0';
26 + const ELEMENTOR_ICONS_VERSION = '5.16.0';
28 27
29 28 /**
30 29 * Tabs.
31 30 *
@@ -39,47 +38,16 @@
39 38 private static $tabs;
40 39
41 40 private static $data_manager;
42 41
42 + private static $font_icon_svg_symbols = [];
43 +
43 44 private static function get_needs_upgrade_option() {
44 45 return get_option( 'elementor_' . self::NEEDS_UPDATE_OPTION, null );
45 46 }
46 47
47 48 /**
48 - * @param array $icon
49 - * @param array $attributes
50 - * @param string $tag
51 - * @return bool|mixed|string
52 - */
53 - public static function try_get_icon_html( $icon, $attributes = [], $tag = 'i' ) {
54 - if ( empty( $icon['library'] ) ) {
55 - return '';
56 - }
57 -
58 - return static::get_icon_html( $icon, $attributes, $tag );
59 - }
60 -
61 - /**
62 - * @param array $icon
63 - * @param array $attributes
64 - * @param string $tag
65 - * @return bool|mixed|string
66 - */
67 - private static function get_icon_html( array $icon, array $attributes, $tag ) {
68 - /**
69 - * When the library value is svg it means that it's a SVG media attachment uploaded by the user.
70 - * Otherwise, it's the name of the font family that the icon belongs to.
71 - */
72 - if ( 'svg' === $icon['library'] ) {
73 - $output = self::render_uploaded_svg_icon( $icon['value'] );
74 - } else {
75 - $output = self::render_font_icon( $icon, $attributes, $tag );
76 - }
77 - return $output;
78 - }
79 -
80 - /**
81 - * Register styles
49 + * register styles
82 50 *
83 51 * Used to register all icon types stylesheets so they could be enqueued later by widgets
84 52 */
85 53 public function register_styles() {
@@ -93,9 +61,9 @@
93 61 }
94 62 $dependencies = [];
95 63 if ( ! empty( $icon_type['enqueue'] ) ) {
96 64 foreach ( (array) $icon_type['enqueue'] as $font_css_url ) {
97 - if ( ! in_array( $font_css_url, array_keys( $shared_styles ), true ) ) {
65 + if ( ! in_array( $font_css_url, array_keys( $shared_styles ) ) ) {
98 66 $style_handle = 'elementor-icons-shared-' . count( $shared_styles );
99 67 wp_register_style(
100 68 $style_handle,
101 69 $font_css_url,
@@ -178,9 +146,8 @@
178 146 }
179 147
180 148 /**
181 149 * Get Icon Manager Tabs
182 - *
183 150 * @return array
184 151 */
185 152 public static function get_icon_manager_tabs() {
186 153 if ( self::is_font_icon_inline_svg() && ! Plugin::$instance->editor->is_edit_mode() && ! Plugin::$instance->preview->is_preview_mode() ) {
@@ -203,9 +170,8 @@
203 170 return array_replace( self::$tabs, $additional_tabs );
204 171 }
205 172
206 173 public static function enqueue_shim() {
207 - //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
208 174 wp_enqueue_script(
209 175 'font-awesome-4-shim',
210 176 self::get_fa_asset_url( 'v4-shims', 'js' ),
211 177 [],
@@ -230,9 +196,9 @@
230 196
231 197 private static function get_fa_asset_url( $filename, $ext_type = 'css', $add_suffix = true ) {
232 198 static $is_test_mode = null;
233 199 if ( null === $is_test_mode ) {
234 - $is_test_mode = Utils::is_script_debug() || Utils::is_elementor_tests();
200 + $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
235 201 }
236 202 $url = ELEMENTOR_ASSETS_URL . 'lib/font-awesome/' . $ext_type . '/' . $filename;
237 203 if ( ! $is_test_mode && $add_suffix ) {
238 204 $url .= '.min';
@@ -253,17 +219,39 @@
253 219
254 220 return array_values( array_merge( $tabs, self::get_icon_manager_tabs() ) );
255 221 }
256 222
223 + /**
224 + * is_font_awesome_inline
225 + *
226 + * @return bool
227 + */
257 228 private static function is_font_icon_inline_svg() {
258 229 return Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' );
259 230 }
260 231
261 232 /**
262 - * @deprecated 3.8.0
233 + * render_svg_symbols
234 + *
263 235 */
264 - public static function render_svg_symbols() {}
236 + public static function render_svg_symbols() {
237 + if ( ! self::$font_icon_svg_symbols ) {
238 + return;
239 + }
265 240
241 + $svg = '<svg xmlns="http://www.w3.org/2000/svg" id="e-font-icon-svg-symbols" style="display: none;">';
242 +
243 + foreach ( self::$font_icon_svg_symbols as $symbol_id => $symbol ) {
244 + $svg .= '<symbol id="' . $symbol_id . '" viewBox="0 0 ' . esc_attr( $symbol['width'] ) . ' ' . esc_attr( $symbol['height'] ) . '">';
245 + $svg .= '<path d="' . esc_attr( $symbol['path'] ) . '"></path>';
246 + $svg .= '</symbol>';
247 + }
248 +
249 + $svg .= '</svg>';
250 +
251 + Utils::print_unescaped_internal_string( $svg );
252 + }
253 +
266 254 public static function get_icon_svg_data( $icon ) {
267 255 return self::$data_manager->get_font_icon_svg_data( $icon );
268 256 }
269 257
@@ -268,9 +256,8 @@
268 256 }
269 257
270 258 /**
271 259 * Get font awesome svg.
272 - *
273 260 * @param $icon array [ 'value' => string, 'library' => string ]
274 261 *
275 262 * @return bool|mixed|string
276 263 */
@@ -281,8 +268,13 @@
281 268 if ( ! $icon_data['path'] ) {
282 269 return '';
283 270 }
284 271
272 + // Add the icon data to the symbols array for later use in page rendering process.
273 + if ( ! in_array( $icon_data['key'], self::$font_icon_svg_symbols, true ) ) {
274 + self::$font_icon_svg_symbols[ $icon_data['key'] ] = $icon_data;
275 + }
276 +
285 277 if ( ! empty( $attributes['class'] ) && ! is_array( $attributes['class'] ) ) {
286 278 $attributes['class'] = [ $attributes['class'] ];
287 279 }
288 280
@@ -287,16 +279,21 @@
287 279 }
288 280
289 281 $attributes['class'][] = self::FONT_ICON_SVG_CLASS_NAME;
290 282 $attributes['class'][] = 'e-' . $icon_data['key'];
291 - $attributes['viewBox'] = '0 0 ' . $icon_data['width'] . ' ' . $icon_data['height'];
292 - $attributes['xmlns'] = 'http://www.w3.org/2000/svg';
293 283
294 - return (
295 - '<svg ' . Utils::render_html_attributes( $attributes ) . '>' .
296 - '<path d="' . esc_attr( $icon_data['path'] ) . '"></path>' .
297 - '</svg>'
298 - );
284 + /**
285 + * If in edit mode inline the full svg, otherwise use the symbol.
286 + * Will be displayed only after page update or widget "blur".
287 + */
288 + if ( Plugin::$instance->editor->is_edit_mode() ) {
289 + return '<svg xmlns="http://www.w3.org/2000/svg" ' . Utils::render_html_attributes( $attributes ) . '
290 + viewBox="0 0 ' . esc_attr( $icon_data['width'] ) . ' ' . esc_attr( $icon_data['height'] ) . '">
291 + <path d="' . esc_attr( $icon_data['path'] ) . '"></path>
292 + </svg>';
293 + }
294 +
295 + return '<svg ' . Utils::render_html_attributes( $attributes ) . '><use xlink:href="#' . esc_attr( $icon_data['key'] ) . '" /></svg>';
299 296 }
300 297
301 298 public static function render_uploaded_svg_icon( $value ) {
302 299 if ( ! isset( $value['id'] ) ) {
@@ -329,12 +326,14 @@
329 326
330 327 if ( ! $content ) {
331 328 if ( empty( $attributes['class'] ) ) {
332 329 $attributes['class'] = $icon['value'];
333 - } elseif ( is_array( $attributes['class'] ) ) {
330 + } else {
331 + if ( is_array( $attributes['class'] ) ) {
334 332 $attributes['class'][] = $icon['value'];
335 - } else {
336 - $attributes['class'] .= ' ' . $icon['value'];
333 + } else {
334 + $attributes['class'] .= ' ' . $icon['value'];
335 + }
337 336 }
338 337 }
339 338
340 339 return '<' . $tag . ' ' . Utils::render_html_attributes( $attributes ) . '>' . $content . '</' . $tag . '>';
@@ -343,13 +342,12 @@
343 342 /**
344 343 * Render Icon
345 344 *
346 345 * Used to render Icon for \Elementor\Controls_Manager::ICONS
346 + * @param array $icon Icon Type, Icon value
347 + * @param array $attributes Icon HTML Attributes
348 + * @param string $tag Icon HTML tag, defaults to <i>
347 349 *
348 - * @param array $icon Icon Type, Icon value.
349 - * @param array $attributes Icon HTML Attributes.
350 - * @param string $tag Icon HTML tag, defaults to <i>.
351 - *
352 350 * @return mixed|string
353 351 */
354 352 public static function render_icon( $icon, $attributes = [], $tag = 'i' ) {
355 353 if ( empty( $icon['library'] ) ) {
@@ -355,10 +353,20 @@
355 353 if ( empty( $icon['library'] ) ) {
356 354 return false;
357 355 }
358 356
359 - $output = static::get_icon_html( $icon, $attributes, $tag );
357 + $output = '';
360 358
359 + /**
360 + * When the library value is svg it means that it's a SVG media attachment uploaded by the user.
361 + * Otherwise, it's the name of the font family that the icon belongs to.
362 + */
363 + if ( 'svg' === $icon['library'] ) {
364 + $output = self::render_uploaded_svg_icon( $icon['value'] );
365 + } else {
366 + $output = self::render_font_icon( $icon, $attributes, $tag );
367 + }
368 +
361 369 Utils::print_unescaped_internal_string( $output );
362 370
363 371 return true;
364 372 }
@@ -365,9 +373,9 @@
365 373
366 374 /**
367 375 * Font Awesome 4 to font Awesome 5 Value Migration
368 376 *
369 - * Used to convert string value of Icon control to array value of Icons control
377 + * used to convert string value of Icon control to array value of Icons control
370 378 * ex: 'fa fa-star' => [ 'value' => 'fas fa-star', 'library' => 'fa-solid' ]
371 379 *
372 380 * @param $value
373 381 *
@@ -394,15 +402,14 @@
394 402 ];
395 403 }
396 404
397 405 /**
398 - * On_import_migration
406 + * on_import_migration
407 + * @param array $element settings array
408 + * @param string $old_control old control id
409 + * @param string $new_control new control id
410 + * @param bool $remove_old boolean weather to remove old control or not
399 411 *
400 - * @param array $element settings array.
401 - * @param string $old_control old control id.
402 - * @param string $new_control new control id.
403 - * @param bool $remove_old boolean whether to remove old control or not.
404 - *
405 412 * @return array
406 413 */
407 414 public static function on_import_migration( array $element, $old_control = '', $new_control = '', $remove_old = false ) {
408 415
@@ -422,9 +429,9 @@
422 429 }
423 430
424 431 $element['settings'][ $new_control ] = $new_value;
425 432
426 - // remove old value
433 + //remove old value
427 434 if ( $remove_old ) {
428 435 unset( $element['settings'][ $old_control ] );
429 436 }
430 437
@@ -430,8 +437,12 @@
430 437
431 438 return $element;
432 439 }
433 440
441 + /**
442 + * is_migration_allowed
443 + * @return bool
444 + */
434 445 public static function is_migration_allowed() {
435 446 static $migration_allowed = false;
436 447 if ( false === $migration_allowed ) {
437 448 $migration_allowed = null === self::get_needs_upgrade_option();
@@ -438,9 +449,9 @@
438 449
439 450 /**
440 451 * Is icon migration allowed.
441 452 *
442 - * Filters whether the icons migration allowed.
453 + * Filters whther the icons migration allowed.
443 454 *
444 455 * @param bool $migration_allowed Is icon migration is allowed.
445 456 */
446 457 $migration_allowed = apply_filters( 'elementor/icons_manager/migration_allowed', $migration_allowed );
@@ -450,10 +461,9 @@
450 461
451 462 /**
452 463 * Register_Admin Settings
453 464 *
454 - * Adds Font Awesome migration / update admin settings
455 - *
465 + * adds Font Awesome migration / update admin settings
456 466 * @param Settings $settings
457 467 */
458 468 public function register_admin_settings( Settings $settings ) {
459 469 $settings->add_field(
@@ -515,10 +525,9 @@
515 525 *
516 526 * @return string
517 527 */
518 528 public function get_upgrade_redirect_url() {
519 -
520 - if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, '_wpnonce' ), 'tools-page-from-editor' ) ) {
529 + if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'tools-page-from-editor' ) ) {
521 530 return '';
522 531 }
523 532
524 533 $document_id = ! empty( $_GET['redirect_to_document'] ) ? absint( $_GET['redirect_to_document'] ) : null;
@@ -541,12 +550,8 @@
541 550 */
542 551 public function ajax_upgrade_to_fa5() {
543 552 check_ajax_referer( self::NEEDS_UPDATE_OPTION, '_nonce' );
544 553
545 - if ( ! current_user_can( 'manage_options' ) ) {
546 - wp_send_json_error( 'Permission denied' );
547 - }
548 -
549 554 delete_option( 'elementor_' . self::NEEDS_UPDATE_OPTION );
550 555
551 556 wp_send_json_success( [ 'message' => esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) ] );
552 557 }
@@ -552,9 +557,8 @@
552 557 }
553 558
554 559 /**
555 560 * Add Update Needed Flag
556 - *
557 561 * @param array $settings
558 562 *
559 563 * @return array;
560 564 */
@@ -570,9 +574,9 @@
570 574 $current_filter = current_filter();
571 575 $load_shim = get_option( self::LOAD_FA4_SHIM_OPTION_KEY, false );
572 576 if ( 'elementor/editor/after_enqueue_styles' === $current_filter ) {
573 577 self::enqueue_shim();
574 - } elseif ( 'yes' === $load_shim ) {
578 + } else if ( 'yes' === $load_shim ) {
575 579 self::enqueue_shim();
576 580 }
577 581 }
578 582 }
@@ -596,8 +600,10 @@
596 600 }
597 601
598 602 if ( self::is_font_icon_inline_svg() ) {
599 603 self::$data_manager = new Font_Icon_Svg_Data_Manager();
604 +
605 + add_action( 'wp_footer', [ $this, 'render_svg_symbols' ], 10 );
600 606 }
601 607
602 608 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_fontawesome_css' ] );
603 609 add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );