PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.6
Elementor Website Builder – more than just a page builder v3.5.6
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 +102 -109 4.0.93.5.6 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 }
@@ -22,11 +21,8 @@
22 21
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 -
27 - const ELEMENTOR_ICONS_VERSION = '5.48.0';
28 -
29 25 /**
30 26 * Tabs.
31 27 *
32 28 * Holds the list of all the tabs.
@@ -39,47 +35,16 @@
39 35 private static $tabs;
40 36
41 37 private static $data_manager;
42 38
39 + private static $font_icon_svg_symbols = [];
40 +
43 41 private static function get_needs_upgrade_option() {
44 42 return get_option( 'elementor_' . self::NEEDS_UPDATE_OPTION, null );
45 43 }
46 44
47 45 /**
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
46 + * register styles
82 47 *
83 48 * Used to register all icon types stylesheets so they could be enqueued later by widgets
84 49 */
85 50 public function register_styles() {
@@ -93,9 +58,9 @@
93 58 }
94 59 $dependencies = [];
95 60 if ( ! empty( $icon_type['enqueue'] ) ) {
96 61 foreach ( (array) $icon_type['enqueue'] as $font_css_url ) {
97 - if ( ! in_array( $font_css_url, array_keys( $shared_styles ), true ) ) {
62 + if ( ! in_array( $font_css_url, array_keys( $shared_styles ) ) ) {
98 63 $style_handle = 'elementor-icons-shared-' . count( $shared_styles );
99 64 wp_register_style(
100 65 $style_handle,
101 66 $font_css_url,
@@ -178,9 +143,8 @@
178 143 }
179 144
180 145 /**
181 146 * Get Icon Manager Tabs
182 - *
183 147 * @return array
184 148 */
185 149 public static function get_icon_manager_tabs() {
186 150 if ( self::is_font_icon_inline_svg() && ! Plugin::$instance->editor->is_edit_mode() && ! Plugin::$instance->preview->is_preview_mode() ) {
@@ -199,13 +163,12 @@
199 163 * @param array $additional_tabs Additional icon manager tabs. Default is an empty array.
200 164 */
201 165 $additional_tabs = apply_filters( 'elementor/icons_manager/additional_tabs', $additional_tabs );
202 166
203 - return array_replace( self::$tabs, $additional_tabs );
167 + return array_merge( self::$tabs, $additional_tabs );
204 168 }
205 169
206 170 public static function enqueue_shim() {
207 - //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
208 171 wp_enqueue_script(
209 172 'font-awesome-4-shim',
210 173 self::get_fa_asset_url( 'v4-shims', 'js' ),
211 174 [],
@@ -230,9 +193,9 @@
230 193
231 194 private static function get_fa_asset_url( $filename, $ext_type = 'css', $add_suffix = true ) {
232 195 static $is_test_mode = null;
233 196 if ( null === $is_test_mode ) {
234 - $is_test_mode = Utils::is_script_debug() || Utils::is_elementor_tests();
197 + $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
235 198 }
236 199 $url = ELEMENTOR_ASSETS_URL . 'lib/font-awesome/' . $ext_type . '/' . $filename;
237 200 if ( ! $is_test_mode && $add_suffix ) {
238 201 $url .= '.min';
@@ -253,17 +216,39 @@
253 216
254 217 return array_values( array_merge( $tabs, self::get_icon_manager_tabs() ) );
255 218 }
256 219
220 + /**
221 + * is_font_awesome_inline
222 + *
223 + * @return bool
224 + */
257 225 private static function is_font_icon_inline_svg() {
258 226 return Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' );
259 227 }
260 228
261 229 /**
262 - * @deprecated 3.8.0
230 + * render_svg_symbols
231 + *
263 232 */
264 - public static function render_svg_symbols() {}
233 + public static function render_svg_symbols() {
234 + if ( ! self::$font_icon_svg_symbols ) {
235 + return;
236 + }
265 237
238 + $svg = '<svg xmlns="http://www.w3.org/2000/svg" id="e-font-icon-svg-symbols" style="display: none;">';
239 +
240 + foreach ( self::$font_icon_svg_symbols as $symbol_id => $symbol ) {
241 + $svg .= '<symbol id="' . $symbol_id . '" viewBox="0 0 ' . esc_attr( $symbol['width'] ) . ' ' . esc_attr( $symbol['height'] ) . '">';
242 + $svg .= '<path d="' . esc_attr( $symbol['path'] ) . '"></path>';
243 + $svg .= '</symbol>';
244 + }
245 +
246 + $svg .= '</svg>';
247 +
248 + Utils::print_unescaped_internal_string( $svg );
249 + }
250 +
266 251 public static function get_icon_svg_data( $icon ) {
267 252 return self::$data_manager->get_font_icon_svg_data( $icon );
268 253 }
269 254
@@ -268,9 +253,8 @@
268 253 }
269 254
270 255 /**
271 256 * Get font awesome svg.
272 - *
273 257 * @param $icon array [ 'value' => string, 'library' => string ]
274 258 *
275 259 * @return bool|mixed|string
276 260 */
@@ -281,8 +265,13 @@
281 265 if ( ! $icon_data['path'] ) {
282 266 return '';
283 267 }
284 268
269 + // Add the icon data to the symbols array for later use in page rendering process.
270 + if ( ! in_array( $icon_data['key'], self::$font_icon_svg_symbols, true ) ) {
271 + self::$font_icon_svg_symbols[ $icon_data['key'] ] = $icon_data;
272 + }
273 +
285 274 if ( ! empty( $attributes['class'] ) && ! is_array( $attributes['class'] ) ) {
286 275 $attributes['class'] = [ $attributes['class'] ];
287 276 }
288 277
@@ -287,16 +276,21 @@
287 276 }
288 277
289 278 $attributes['class'][] = self::FONT_ICON_SVG_CLASS_NAME;
290 279 $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 280
294 - return (
295 - '<svg ' . Utils::render_html_attributes( $attributes ) . '>' .
296 - '<path d="' . esc_attr( $icon_data['path'] ) . '"></path>' .
297 - '</svg>'
298 - );
281 + /**
282 + * If in edit mode inline the full svg, otherwise use the symbol.
283 + * Will be displayed only after page update or widget "blur".
284 + */
285 + if ( Plugin::$instance->editor->is_edit_mode() ) {
286 + return '<svg xmlns="http://www.w3.org/2000/svg" ' . Utils::render_html_attributes( $attributes ) . '
287 + viewBox="0 0 ' . esc_attr( $icon_data['width'] ) . ' ' . esc_attr( $icon_data['height'] ) . '">
288 + <path d="' . esc_attr( $icon_data['path'] ) . '"></path>
289 + </svg>';
290 + }
291 +
292 + return '<svg ' . Utils::render_html_attributes( $attributes ) . '><use xlink:href="#' . esc_attr( $icon_data['key'] ) . '" /></svg>';
299 293 }
300 294
301 295 public static function render_uploaded_svg_icon( $value ) {
302 296 if ( ! isset( $value['id'] ) ) {
@@ -329,12 +323,14 @@
329 323
330 324 if ( ! $content ) {
331 325 if ( empty( $attributes['class'] ) ) {
332 326 $attributes['class'] = $icon['value'];
333 - } elseif ( is_array( $attributes['class'] ) ) {
327 + } else {
328 + if ( is_array( $attributes['class'] ) ) {
334 329 $attributes['class'][] = $icon['value'];
335 - } else {
336 - $attributes['class'] .= ' ' . $icon['value'];
330 + } else {
331 + $attributes['class'] .= ' ' . $icon['value'];
332 + }
337 333 }
338 334 }
339 335
340 336 return '<' . $tag . ' ' . Utils::render_html_attributes( $attributes ) . '>' . $content . '</' . $tag . '>';
@@ -343,13 +339,12 @@
343 339 /**
344 340 * Render Icon
345 341 *
346 342 * Used to render Icon for \Elementor\Controls_Manager::ICONS
343 + * @param array $icon Icon Type, Icon value
344 + * @param array $attributes Icon HTML Attributes
345 + * @param string $tag Icon HTML tag, defaults to <i>
347 346 *
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 347 * @return mixed|string
353 348 */
354 349 public static function render_icon( $icon, $attributes = [], $tag = 'i' ) {
355 350 if ( empty( $icon['library'] ) ) {
@@ -355,10 +350,20 @@
355 350 if ( empty( $icon['library'] ) ) {
356 351 return false;
357 352 }
358 353
359 - $output = static::get_icon_html( $icon, $attributes, $tag );
354 + $output = '';
360 355
356 + /**
357 + * When the library value is svg it means that it's a SVG media attachment uploaded by the user.
358 + * Otherwise, it's the name of the font family that the icon belongs to.
359 + */
360 + if ( 'svg' === $icon['library'] ) {
361 + $output = self::render_uploaded_svg_icon( $icon['value'] );
362 + } else {
363 + $output = self::render_font_icon( $icon, $attributes, $tag );
364 + }
365 +
361 366 Utils::print_unescaped_internal_string( $output );
362 367
363 368 return true;
364 369 }
@@ -365,9 +370,9 @@
365 370
366 371 /**
367 372 * Font Awesome 4 to font Awesome 5 Value Migration
368 373 *
369 - * Used to convert string value of Icon control to array value of Icons control
374 + * used to convert string value of Icon control to array value of Icons control
370 375 * ex: 'fa fa-star' => [ 'value' => 'fas fa-star', 'library' => 'fa-solid' ]
371 376 *
372 377 * @param $value
373 378 *
@@ -381,9 +386,9 @@
381 386 'library' => '',
382 387 ];
383 388 }
384 389 if ( false === $migration_dictionary ) {
385 - $migration_dictionary = json_decode( Utils::file_get_contents( ELEMENTOR_ASSETS_PATH . 'lib/font-awesome/migration/mapping.js' ), true );
390 + $migration_dictionary = json_decode( file_get_contents( ELEMENTOR_ASSETS_PATH . 'lib/font-awesome/migration/mapping.js' ), true );
386 391 }
387 392 if ( isset( $migration_dictionary[ $value ] ) ) {
388 393 return $migration_dictionary[ $value ];
389 394 }
@@ -394,15 +399,14 @@
394 399 ];
395 400 }
396 401
397 402 /**
398 - * On_import_migration
403 + * on_import_migration
404 + * @param array $element settings array
405 + * @param string $old_control old control id
406 + * @param string $new_control new control id
407 + * @param bool $remove_old boolean weather to remove old control or not
399 408 *
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 409 * @return array
406 410 */
407 411 public static function on_import_migration( array $element, $old_control = '', $new_control = '', $remove_old = false ) {
408 412
@@ -422,9 +426,9 @@
422 426 }
423 427
424 428 $element['settings'][ $new_control ] = $new_value;
425 429
426 - // remove old value
430 + //remove old value
427 431 if ( $remove_old ) {
428 432 unset( $element['settings'][ $old_control ] );
429 433 }
430 434
@@ -430,8 +434,12 @@
430 434
431 435 return $element;
432 436 }
433 437
438 + /**
439 + * is_migration_allowed
440 + * @return bool
441 + */
434 442 public static function is_migration_allowed() {
435 443 static $migration_allowed = false;
436 444 if ( false === $migration_allowed ) {
437 445 $migration_allowed = null === self::get_needs_upgrade_option();
@@ -438,9 +446,9 @@
438 446
439 447 /**
440 448 * Is icon migration allowed.
441 449 *
442 - * Filters whether the icons migration allowed.
450 + * Filters whther the icons migration allowed.
443 451 *
444 452 * @param bool $migration_allowed Is icon migration is allowed.
445 453 */
446 454 $migration_allowed = apply_filters( 'elementor/icons_manager/migration_allowed', $migration_allowed );
@@ -450,10 +458,9 @@
450 458
451 459 /**
452 460 * Register_Admin Settings
453 461 *
454 - * Adds Font Awesome migration / update admin settings
455 - *
462 + * adds Font Awesome migration / update admin settings
456 463 * @param Settings $settings
457 464 */
458 465 public function register_admin_settings( Settings $settings ) {
459 466 $settings->add_field(
@@ -494,15 +501,14 @@
494 501 '</p>';
495 502 },
496 503 'fields' => [
497 504 [
498 - 'label' => esc_html__( 'Font Awesome Upgrade', 'elementor' ),
505 + 'label' => esc_html__( 'Font Awesome Upgrade', 'elementor' ),
499 506 'field_args' => [
500 507 'type' => 'raw_html',
501 - 'html' => sprintf( '<span data-action="%s" data-_nonce="%s" data-redirect-url="%s" class="button" id="elementor_upgrade_fa_button">%s</span>',
508 + 'html' => sprintf( '<span data-action="%s" data-_nonce="%s" class="button" id="elementor_upgrade_fa_button">%s</span>',
502 509 self::NEEDS_UPDATE_OPTION . '_upgrade',
503 510 wp_create_nonce( self::NEEDS_UPDATE_OPTION ),
504 - esc_url( $this->get_upgrade_redirect_url() ),
505 511 esc_html__( 'Upgrade To Font Awesome 5', 'elementor' )
506 512 ),
507 513 ],
508 514 ],
@@ -510,51 +516,20 @@
510 516 ] );
511 517 }
512 518
513 519 /**
514 - * Get redirect URL when upgrading font awesome.
515 - *
516 - * @return string
517 - */
518 - public function get_upgrade_redirect_url() {
519 -
520 - if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, '_wpnonce' ), 'tools-page-from-editor' ) ) {
521 - return '';
522 - }
523 -
524 - $document_id = ! empty( $_GET['redirect_to_document'] ) ? absint( $_GET['redirect_to_document'] ) : null;
525 -
526 - if ( ! $document_id ) {
527 - return '';
528 - }
529 -
530 - $document = Plugin::$instance->documents->get( $document_id );
531 -
532 - if ( ! $document ) {
533 - return '';
534 - }
535 -
536 - return $document->get_edit_url();
537 - }
538 -
539 - /**
540 520 * Ajax Upgrade to FontAwesome 5
541 521 */
542 522 public function ajax_upgrade_to_fa5() {
543 523 check_ajax_referer( self::NEEDS_UPDATE_OPTION, '_nonce' );
544 524
545 - if ( ! current_user_can( 'manage_options' ) ) {
546 - wp_send_json_error( 'Permission denied' );
547 - }
548 -
549 525 delete_option( 'elementor_' . self::NEEDS_UPDATE_OPTION );
550 526
551 - wp_send_json_success( [ 'message' => esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) ] );
527 + wp_send_json_success( [ 'message' => '<p>' . esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) . '</p>' ] );
552 528 }
553 529
554 530 /**
555 531 * Add Update Needed Flag
556 - *
557 532 * @param array $settings
558 533 *
559 534 * @return array;
560 535 */
@@ -570,9 +545,9 @@
570 545 $current_filter = current_filter();
571 546 $load_shim = get_option( self::LOAD_FA4_SHIM_OPTION_KEY, false );
572 547 if ( 'elementor/editor/after_enqueue_styles' === $current_filter ) {
573 548 self::enqueue_shim();
574 - } elseif ( 'yes' === $load_shim ) {
549 + } else if ( 'yes' === $load_shim ) {
575 550 self::enqueue_shim();
576 551 }
577 552 }
578 553 }
@@ -586,8 +561,24 @@
586 561 return [];
587 562 }
588 563
589 564 /**
565 + * @since 3.0.0
566 + * @deprecated 3.0.0
567 + */
568 + public function register_ajax_actions() {
569 + _deprecated_function( __METHOD__, '3.0.0' );
570 + }
571 +
572 + /**
573 + * @since 3.0.0.
574 + * @deprecated 3.0.0
575 + */
576 + public function ajax_enable_svg_uploads() {
577 + _deprecated_function( __METHOD__, '3.0.0' );
578 + }
579 +
580 + /**
590 581 * Icons Manager constructor
591 582 */
592 583 public function __construct() {
593 584 if ( is_admin() ) {
@@ -596,8 +587,10 @@
596 587 }
597 588
598 589 if ( self::is_font_icon_inline_svg() ) {
599 590 self::$data_manager = new Font_Icon_Svg_Data_Manager();
591 +
592 + add_action( 'wp_footer', [ $this, 'render_svg_symbols' ], 10 );
600 593 }
601 594
602 595 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_fontawesome_css' ] );
603 596 add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );