elementor/includes/managers
Omer Israeli a47dbdff91
Feat: Add refreshWidgets() API for dynamic widget list updates [ED-23311] (#35156)
## 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

```js
// 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
2026-04-15 12:24:57 +00:00
..
controls.php Made String Translatable in controls.php (#35011) 2026-03-26 19:23:31 +00:00
elements.php Internal: Tweaks to atomic form behavior [ED-22577] (#35457) 2026-04-15 12:58:52 +02:00
icons.php Internal: Updated icons [ED-22695] (#34853) 2026-02-23 12:23:19 +01:00
image.php Internal: Fix more lint issues in template-library [ED-17700] (#29801) 2025-01-07 17:07:21 +02:00
skins.php Revert "autoloader: move more files to the autoloader" 2018-04-17 16:41:32 +03:00
widgets.php Feat: Add refreshWidgets() API for dynamic widget list updates [ED-23311] (#35156) 2026-04-15 12:24:57 +00:00
wordpress-widgets.php Internal: Use short array syntax in all PHP files [ED-15130] (#29301) 2024-11-17 14:32:02 +02:00