Skip to content

Feat: Add refreshWidgets() API for dynamic widget list updates [ED-23311]#35156

Draft
Omerisra6 wants to merge 4 commits intoelementor:mainfrom
Omerisra6:feature/ED-23311-dynamic-widgets-api
Draft

Feat: Add refreshWidgets() API for dynamic widget list updates [ED-23311]#35156
Omerisra6 wants to merge 4 commits intoelementor:mainfrom
Omerisra6:feature/ED-23311-dynamic-widgets-api

Conversation

@Omerisra6
Copy link
Copy Markdown
Contributor

@Omerisra6 Omerisra6 commented Mar 16, 2026

Summary

Adds a public elementor.refreshWidgets() API that lets third-party code (e.g. Angie) dynamically register new widgets on the server side and then refresh the editor's widget list without a full page reload.

  • New PHP AJAX endpoint refresh_widgets_config that returns the complete widget + category configuration (including controls with defaults).
  • New JS async refreshWidgets() method on the editor instance that fetches the updated config, replaces widgetsCache, updates panel categories, refreshes the panel route, and reloads the preview iframe.
  • Guards the elements panel against missing preset widgets that may no longer exist after a refresh.

Jira

https://elementor.atlassian.net/browse/ED-23311

Usage Example

// 1. Register your widget on the server (e.g. via AJAX or WP hook)
//    — make sure the widget class is registered with Elementor's widget manager.

// 2. From the browser console or your JS code, refresh the editor widget list:
await elementor.refreshWidgets();

// That's it — the panel will show the updated widget list,
// and the preview iframe will reload to pick up new widget assets (CSS/JS).

What happens under the hood

  1. An AJAX request fetches the full widget config (title, icon, categories, controls with defaults, etc.) and all panel categories.
  2. widgetsCache is cleared and rebuilt with the fresh data.
  3. Panel categories are updated.
  4. Global CSS is re-rendered.
  5. The elementor/widgets/refreshed hook fires (for any listeners).
  6. The panel route is refreshed so the Elements tab re-renders.
  7. The preview iframe reloads so newly registered widget assets (CSS/JS) are enqueued.

Test plan

  • Open the editor, register a new widget server-side (e.g. via mu-plugin or Angie snippet)
  • Run await elementor.refreshWidgets() in the browser console
  • Verify the new widget appears in the panel under the correct category
  • Drag the new widget onto the canvas — verify it renders correctly with default control values
  • Verify existing widgets still work normally after the refresh
  • Verify no JS errors in console during and after refresh

…23311]

Add a standard API (`elementor.refreshWidgets()`) that allows refreshing
the editor widget list at runtime without a page reload. This enables
third-party developers and extensions (e.g., Angie AI) to dynamically
register or update widgets and have them appear in the editor immediately.

Changes:
- New PHP AJAX endpoint `refresh_widgets_config` that returns full widget
  configs (title, icon, categories, keywords, controls) plus categories
- New JS method `refreshWidgets()` on EditorBase that fetches fresh data,
  replaces widgetsCache atomically, updates categories, and refreshes
  panel + preview
- Fires `elementor/widgets/refreshed` hook for extensibility
- Returns a Promise for reliable success/failure handling

Made-with: Cursor
@Omerisra6 Omerisra6 marked this pull request as draft March 16, 2026 13:39
Skip element presets whose originalWidget is not found in widgetsCache
instead of crashing with a TypeError. This is a pre-existing edge case
that surfaces when widgets are dynamically refreshed or when a preset
references a widget that failed to register.

Made-with: Cursor
…311]

Widget_Base::get_initial_config() conditionally includes controls only
when the controls stack is already initialized. During AJAX requests the
stack is not yet initialized, so get_config() returned widget metadata
without controls. Explicitly call get_stack(false) to force initialization.

Made-with: Cursor
@Omerisra6 Omerisra6 force-pushed the feature/ED-23311-dynamic-widgets-api branch from 1babc8e to c4ac1bf Compare March 18, 2026 13:21
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.

1 participant