PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.7
Elementor Website Builder – more than just a page builder v3.6.7
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 -80 4.0.73.6.7 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 *
@@ -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(
@@ -515,10 +522,9 @@
515 522 *
516 523 * @return string
517 524 */
518 525 public function get_upgrade_redirect_url() {
519 -
520 - if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, '_wpnonce' ), 'tools-page-from-editor' ) ) {
526 + if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'tools-page-from-editor' ) ) {
521 527 return '';
522 528 }
523 529
524 530 $document_id = ! empty( $_GET['redirect_to_document'] ) ? absint( $_GET['redirect_to_document'] ) : null;
@@ -541,12 +547,8 @@
541 547 */
542 548 public function ajax_upgrade_to_fa5() {
543 549 check_ajax_referer( self::NEEDS_UPDATE_OPTION, '_nonce' );
544 550
545 - if ( ! current_user_can( 'manage_options' ) ) {
546 - wp_send_json_error( 'Permission denied' );
547 - }
548 -
549 551 delete_option( 'elementor_' . self::NEEDS_UPDATE_OPTION );
550 552
551 553 wp_send_json_success( [ 'message' => esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) ] );
552 554 }
@@ -552,9 +554,8 @@
552 554 }
553 555
554 556 /**
555 557 * Add Update Needed Flag
556 - *
557 558 * @param array $settings
558 559 *
559 560 * @return array;
560 561 */
@@ -570,9 +571,9 @@
570 571 $current_filter = current_filter();
571 572 $load_shim = get_option( self::LOAD_FA4_SHIM_OPTION_KEY, false );
572 573 if ( 'elementor/editor/after_enqueue_styles' === $current_filter ) {
573 574 self::enqueue_shim();
574 - } elseif ( 'yes' === $load_shim ) {
575 + } else if ( 'yes' === $load_shim ) {
575 576 self::enqueue_shim();
576 577 }
577 578 }
578 579 }
@@ -596,8 +597,10 @@
596 597 }
597 598
598 599 if ( self::is_font_icon_inline_svg() ) {
599 600 self::$data_manager = new Font_Icon_Svg_Data_Manager();
601 +
602 + add_action( 'wp_footer', [ $this, 'render_svg_symbols' ], 10 );
600 603 }
601 604
602 605 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_fontawesome_css' ] );
603 606 add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );