Skip to content

Commit afa19fe

Browse files
committed
use additional_tabs instead
1 parent 4029f71 commit afa19fe

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

integrations/plugins/fontawesome-elementor-add-on/fontawesome-elementor-add-on.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,20 @@ function get_style_shorthands( $upload_dir, $fa_version ) {
282282
return $shorthands;
283283
}
284284

285-
function replace_font_awesome( $settings ) {
285+
function replace_font_awesome_native($settings) {
286+
// remove Free
287+
unset(
288+
$settings['fa-solid'],
289+
$settings['fa-regular'],
290+
$settings['fa-brands']
291+
);
292+
return $settings;
293+
}
294+
295+
// We have to add ours as "additional_tabs". Otherwise, their render_callback won't be used
296+
// on initial insertion, because of Elementor's logic in:
297+
// get_icon_manager_tabs()
298+
function replace_font_awesome_additional_tabs() {
286299
$upload_dir = get_upload_dir();
287300
$fa_version = FA_VERSION;
288301
$style_shorthands = get_style_shorthands( $upload_dir, $fa_version );
@@ -314,13 +327,8 @@ function replace_font_awesome( $settings ) {
314327
'render_callback' => 'render_font_awesome_svg_icon'
315328
];
316329
}
317-
// remove Free
318-
unset(
319-
$settings['fa-solid'],
320-
$settings['fa-regular'],
321-
$settings['fa-brands']
322-
);
323-
return array_merge( $icons, $settings );
330+
331+
return $icons;
324332
}
325333

326334
function shorthand_to_short_prefix_id_map() {
@@ -359,11 +367,14 @@ function unprefixed_icon_name($prefix, $prefixed_icon_name) {
359367

360368
// This render_callback seems to fire on the backend in the editor, loading a saved page with
361369
// with an icon. When initially inserting a new icon, it uses an `<i>` tag and relies on Webfont/CSS.
362-
// When the Elementor experiment for inline SVGs is enabled, it bypasses this render_callback
370+
// When the Elementor experiment for inline SVGs is enabled, and our icon tabs are added as "native" tabs,
371+
// then it bypasses this render_callback
363372
// and uses its internal Font Awesome data manager to look up the SVG objects and render them.
364373
// Of course, it won't have access to FA Pro styles and icons.
365-
// So, to make this work on both the backend and front end, that experiment must be disabled.
366-
// That can be done in Elementor -> Settings --> Experiments --> Inline Font Icons.
374+
// So, to make this work on both the backend and front end, either that experiment must be disabled,
375+
// or our icon tabs must be added as "additional_tabs".
376+
//
377+
// Disabling the experiment can be done in Elementor -> Settings --> Experiments --> Inline Font Icons.
367378
// Or by adding this filter--see below:
368379
//
369380
// add_action('elementor/experiments/default-features-registered', function($experiments_manager) {
@@ -442,7 +453,8 @@ function enqueue_fa_pro_css() {
442453
}
443454
}
444455

445-
add_filter( 'elementor/icons_manager/native', 'replace_font_awesome' );
456+
add_filter( 'elementor/icons_manager/native', 'replace_font_awesome_native' );
457+
add_filter( 'elementor/icons_manager/additional_tabs', 'replace_font_awesome_additional_tabs' );
446458
add_action( 'elementor/editor/after_enqueue_scripts', 'enqueue_fa_pro_css' );
447459
// If inline SVG rendering is working, then we don't need to enqueue the CSS on the frontend,
448460
// unless we want to also have the CSS loaded for the sake of compatibility with any <i> tags that might
@@ -483,7 +495,7 @@ function initialize_fontawesome_elementor_data_manager() {
483495

484496
add_action( 'activate_fontawesome-elementor-add-on/fontawesome-elementor-add-on.php', 'fontawesome_elementor_add_on_activate_plugin', -1 );
485497

486-
// uncomment this to force the experiment off
487-
add_action('elementor/experiments/default-features-registered', function($experiments_manager) {
488-
$experiments_manager->set_feature_default_state('e_font_icon_svg', 'inactive');
489-
});
498+
// Uncomment this to force the experiment off
499+
// add_action('elementor/experiments/default-features-registered', function($experiments_manager) {
500+
// $experiments_manager->set_feature_default_state('e_font_icon_svg', 'inactive');
501+
// });

0 commit comments

Comments
 (0)