Skip to content

Stop loading font_icons.css in Elementor by using the custom widget icon class only#2742

Merged
Crabcyborg merged 5 commits into
masterfrom
fix/elementor-widget-icon-css
Jan 8, 2026
Merged

Stop loading font_icons.css in Elementor by using the custom widget icon class only#2742
Crabcyborg merged 5 commits into
masterfrom
fix/elementor-widget-icon-css

Conversation

@shervElmi
Copy link
Copy Markdown
Contributor

@shervElmi shervElmi commented Jan 8, 2026

This PR updates the Elementor widget get_icon() value to return only frm_logo_icon.

Demo

CleanShot 2026-01-08 at 20 24 32@2x

@shervElmi shervElmi self-assigned this Jan 8, 2026
@shervElmi shervElmi marked this pull request as ready for review January 8, 2026 17:23
@shervElmi shervElmi requested a review from Crabcyborg January 8, 2026 17:23
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 8, 2026

Walkthrough

Replaces an admin-only inline enqueue with a registered Elementor editor hook that calls a new public static method to inject inline CSS containing a 28×28 SVG data-URL for the Formidable widget icon in the Elementor editor; adds a docblock above the widget's get_icon method.

Changes

Cohort / File(s) Summary
Editor-style enqueue
classes/controllers/FrmElementorController.php
Removed admin-only anonymous enqueue callback; registered elementor/editor/after_enqueue_styles to call public static function enqueue_editor_styles() which builds a data-URL SVG and injects CSS targeting .elementor-element .icon .frm_logo_icon via wp_add_inline_style('elementor-editor', ...).
Widget docblock
classes/widgets/FrmElementorWidget.php
Added a docblock above get_icon(); no changes to method body or public signature.

Sequence Diagram(s)

(omitted — changes are limited to enqueue registration and inline CSS injection, not a multi-component control-flow requiring a sequence diagram)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Remove font icon SVG asset #2157 — Related changes handling icon assets and SVG/font transitions; both PRs touch how the Formidable icon is provided to Elementor.

Suggested reviewers

  • truongwp
  • Crabcyborg
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: removing font_icons.css dependency by using the custom frm_logo_icon class in the Elementor widget, which aligns with the code changes.
Description check ✅ Passed The description is related to the changeset, mentioning the update to the Elementor widget's get_icon() method and including a demo of the visual result.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d36984b and e3b9ed7.

📒 Files selected for processing (1)
  • classes/widgets/FrmElementorWidget.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: Cypress
🔇 Additional comments (1)
classes/widgets/FrmElementorWidget.php (1)

24-30: Docblock addition looks good.

The added docblock appropriately documents the method's purpose and return type. The implementation correctly delegates to FrmAppHelper::get_menu_icon_class(), which returns 'frmfont frm_logo_icon' as expected, matching the PR objectives for the icon class.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @classes/controllers/FrmElementorController.php:
- Around line 21-27: The docblock above the Elementor editor styles method
contains a placeholder @since x.x; update that tag to the actual release version
(e.g., replace x.x with 6.x.x or the correct version for this release) in the
FrmElementorController class so the method's PHPDoc reflects the real version
number.
🧹 Nitpick comments (1)
classes/controllers/FrmElementorController.php (1)

28-45: Implementation looks correct for inline SVG icon.

The approach of encoding the SVG logo via rawurlencode() and embedding it as a data URL in the CSS ::before pseudo-element is sound. The flexbox centering and the use of wp_add_inline_style() with the elementor-editor handle are appropriate for this use case.

🛡️ Optional: Add defensive error handling

Consider adding a check to ensure the SVG logo is generated successfully and the style handle exists:

 	public static function enqueue_editor_styles() {
-		$icon = rawurlencode( FrmAppHelper::svg_logo() );
+		$svg = FrmAppHelper::svg_logo();
+		if ( empty( $svg ) ) {
+			return;
+		}
+		
+		$icon = rawurlencode( $svg );
 		$css  = '
 		.elementor-element .icon .frm_logo_icon {
 			display: flex;
 			align-items: center;
 			justify-content: center;
 		}
 		.elementor-element .icon .frm_logo_icon::before {
 			content: "";
 			display: block;
 			width: 28px;
 			height: 28px;
 			background: url("data:image/svg+xml,' . $icon . '") center / contain no-repeat;
 		}';
 
+		if ( ! wp_style_is( 'elementor-editor', 'registered' ) ) {
+			return;
+		}
+		
 		wp_add_inline_style( 'elementor-editor', $css );
 	}

This adds resilience if FrmAppHelper::svg_logo() fails or if the Elementor editor stylesheet isn't registered for some reason.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 541d06d and 4c4b700.

📒 Files selected for processing (2)
  • classes/controllers/FrmElementorController.php
  • classes/widgets/FrmElementorWidget.php
🧰 Additional context used
🧬 Code graph analysis (1)
classes/controllers/FrmElementorController.php (1)
classes/helpers/FrmAppHelper.php (2)
  • FrmAppHelper (6-5045)
  • svg_logo (326-339)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Cypress
  • GitHub Check: Cypress
  • GitHub Check: Cypress
🔇 Additional comments (3)
classes/widgets/FrmElementorWidget.php (2)

24-26: LGTM! Documentation improvement.

The added docblock provides clarity on the method's purpose.


28-30: The hardcoded 'frm_logo_icon' class correctly matches the CSS selectors in FrmElementorController::enqueue_editor_styles().

The CSS targets .elementor-element .icon .frm_logo_icon at lines 31 and 36, aligning perfectly with the icon class returned by get_icon(). No legacy icon class methods remain in the codebase. The implementation is consistent.

classes/controllers/FrmElementorController.php (1)

18-19: LGTM! Proper hook for Elementor editor styles.

The elementor/editor/after_enqueue_styles hook is the appropriate place to add editor-specific styling, ensuring the styles are loaded only in the Elementor editor context.

Comment thread classes/controllers/FrmElementorController.php
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @classes/controllers/FrmElementorController.php:
- Line 24: Replace the placeholder "@since x.x" in the FrmElementorController
class docblock with the actual release version string; locate the docblock for
class FrmElementorController and update the @since tag to the correct version
number (for example "@since 1.2.0") so the documentation reflects the real
release version.
🧹 Nitpick comments (1)
classes/controllers/FrmElementorController.php (1)

28-44: Implementation looks good.

The approach of using rawurlencode() for the SVG data URL and injecting it via wp_add_inline_style() is valid. The CSS correctly targets the icon class returned by FrmElementorWidget::get_icon().

One optional consideration: base64 encoding is sometimes preferred for data URLs as it avoids potential edge cases with special characters in SVG content. However, the current approach should work correctly since rawurlencode() properly encodes the # characters in the color values.

♻️ Alternative using base64 encoding (optional)
 public static function enqueue_editor_styles() {
-	$icon = rawurlencode( FrmAppHelper::svg_logo() );
+	$icon = base64_encode( FrmAppHelper::svg_logo() );
 	$css  = '
 	.elementor-element .icon .frm_logo_icon {
 		display: flex;
 		align-items: center;
 		justify-content: center;
 	}
 	.elementor-element .icon .frm_logo_icon::before {
 		content: "";
 		display: block;
 		width: 28px;
 		height: 28px;
-		background: url("data:image/svg+xml,' . $icon . '") center / contain no-repeat;
+		background: url("data:image/svg+xml;base64,' . $icon . '") center / contain no-repeat;
 	}';

 	wp_add_inline_style( 'elementor-editor', $css );
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4b700 and d36984b.

📒 Files selected for processing (1)
  • classes/controllers/FrmElementorController.php
🧰 Additional context used
🧬 Code graph analysis (1)
classes/controllers/FrmElementorController.php (1)
classes/helpers/FrmAppHelper.php (2)
  • FrmAppHelper (6-5045)
  • svg_logo (326-339)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: Cypress
🔇 Additional comments (1)
classes/controllers/FrmElementorController.php (1)

18-19: LGTM!

The elementor/editor/after_enqueue_styles hook is the appropriate Elementor hook for injecting editor-specific CSS, and it's correctly registered after the widget is registered.

Comment thread classes/controllers/FrmElementorController.php
@Crabcyborg Crabcyborg added this to the 6.27 milestone Jan 8, 2026
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shervElmi!

This looks great!

🚀

@Crabcyborg Crabcyborg merged commit b9fffa4 into master Jan 8, 2026
16 checks passed
@Crabcyborg Crabcyborg deleted the fix/elementor-widget-icon-css branch January 8, 2026 18:05
stephywells pushed a commit that referenced this pull request Apr 4, 2026
Stop loading `font_icons.css` in Elementor by using the custom widget icon class only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants