use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
use Elementor\Core\Utils\Collection;
use Elementor\Core\Utils\Force_Locale;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Button\Atomic_Button;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Divider\Atomic_Divider;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Heading\Atomic_Heading;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Image\Atomic_Image;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Svg\Atomic_Svg;
use Elementor\Modules\NestedAccordion\Widgets\Nested_Accordion;
use Elementor\Modules\NestedElements\Module as NestedElementsModule;
use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
* Elementor widgets manager.
* Elementor widgets manager handler class is responsible for registering and
* initializing all the supported Elementor widgets.
* Holds the list of all the widget types.
private $_widget_types = null;
* Holds the list of all the Promoted widget types.
private array $promoted_widgets = [
NestedElementsModule::EXPERIMENT_NAME => [
* Initialize Elementor widgets manager. Include all the widgets files
* and register each Elementor and WordPress widget.
private function init_widgets() {
$build_widgets_filename = [
$this->_widget_types = [];
$this->register_promoted_widgets();
foreach ( $build_widgets_filename as $widget_filename ) {
include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
$class_name = str_replace( '-', '_', $widget_filename );
$class_name = __NAMESPACE__ . '\Widget_' . $class_name;
$this->register( new $class_name() );
$this->register_wp_widgets();
* After widgets registered.
* Fires after Elementor widgets are registered.
* @deprecated 3.5.0 Use `elementor/widgets/register` hook instead.
* @param Widgets_Manager $this The widgets manager.
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action(
'elementor/widgets/widgets_registered',
'elementor/widgets/register'
* After widgets registered.
* Fires after Elementor widgets are registered.
* @param Widgets_Manager $this The widgets manager.
do_action( 'elementor/widgets/register', $this );
* Register WordPress widgets.
* Add native WordPress widget to the list of registered widget types.
* Exclude the widgets that are in Elementor widgets black list. Theme and
* plugin authors can filter the black list.
private function register_wp_widgets() {
global $wp_widget_factory;
// Allow themes/plugins to filter out their widgets.
* Elementor widgets black list.
* Filters the widgets black list that won't be displayed in the panel.
* @param array $black_list A black list of widgets. Default is an empty array.
$black_list = apply_filters( 'elementor/widgets/black_list', $black_list );
foreach ( $wp_widget_factory->widgets as $widget_class => $widget_obj ) {
if ( in_array( $widget_class, $black_list ) ) {
$elementor_widget_class = __NAMESPACE__ . '\Widget_WordPress';
new $elementor_widget_class( [], [
'widget_name' => $widget_class,
* Require Elementor widget base class.
private function require_files() {
require ELEMENTOR_PATH . 'includes/base/widget-base.php';
private function pluck_default_controls( $controls ) {
return ( new Collection( $controls ) )
->reduce( function ( $controls_defaults, $control, $control_key ) {
if ( ! empty( $control['default'] ) ) {
$controls_defaults[ $control_key ]['default'] = $control['default'];
return $controls_defaults;
* Add a new widget type to the list of registered widget types.
* @deprecated 3.5.0 Use `register()` method instead.
* @param Widget_Base $widget Elementor widget.
* @return true True if the widget was registered.
public function register_widget_type( Widget_Base $widget ) {
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
return $this->register( $widget );
* Register a new widget type.
* @param \Elementor\Widget_Base $widget_instance Elementor Widget.
* @return bool True if the widget was registered.
public function register( Widget_Base $widget_instance ) {
if ( is_null( $this->_widget_types ) ) {
* Should widget be registered.
* @param bool $should_register Should widget be registered. Default is `true`.
* @param \Elementor\Widget_Base $widget_instance Widget instance.
$should_register = apply_filters( 'elementor/widgets/is_widget_enabled', true, $widget_instance );
if ( ! $should_register ) {
$this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
/** Register promoted widgets
* Since we cannot allow widgets to place themselves is a specific
* location on our widgets panel we need to use a hard coded solution for this.
private function register_promoted_widgets() {
foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
$this->register_promoted_active_widgets( $experiment_name, $classes );
* Unregister widget type.
* Removes widget type from the list of registered widget types.
* @deprecated 3.5.0 Use `unregister()` method instead.
* @param string $name Widget name.
* @return true True if the widget was unregistered, False otherwise.
public function unregister_widget_type( $name ) {
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
return $this->unregister( $name );
* Unregister widget type.
* Removes widget type from the list of registered widget types.
* @param string $name Widget name.
* @return boolean Whether the widget was unregistered.
public function unregister( $name ) {
if ( ! isset( $this->_widget_types[ $name ] ) ) {
unset( $this->_widget_types[ $name ] );
* Retrieve the registered widget types list.
* @param string $widget_name Optional. Widget name. Default is null.
* @return Widget_Base|Widget_Base[]|null Registered widget types.
public function get_widget_types( $widget_name = null ) {
if ( is_null( $this->_widget_types ) ) {
if ( null !== $widget_name ) {
return isset( $this->_widget_types[ $widget_name ] ) ? $this->_widget_types[ $widget_name ] : null;
return $this->_widget_types;
* Get widget types config.
* Retrieve all the registered widgets with config for each widgets.
* @return array Registered widget types with each widget config.
public function get_widget_types_config() {
foreach ( $this->get_widget_types() as $widget_key => $widget ) {
$config[ $widget_key ] = $widget->get_config();
* @throws \Exception If current user don't have permissions to edit the post.
public function ajax_get_widget_types_controls_config( array $data ) {
Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
wp_raise_memory_limit( 'admin' );
foreach ( $this->get_widget_types() as $widget_key => $widget ) {
if ( isset( $data['exclude'][ $widget_key ] ) ) {
$config[ $widget_key ] = [
'controls' => $widget->get_stack( false )['controls'],
'tabs_controls' => $widget->get_tabs_controls(),
public function ajax_get_widgets_default_value_translations( array $data = [] ) {
$locale = empty( $data['locale'] )
$force_locale = new Force_Locale( $locale );
$controls = ( new Collection( $this->get_widget_types() ) )
->map( function ( Widget_Base $widget ) {
$controls = $widget->get_stack( false )['controls'];
'controls' => $this->pluck_default_controls( $controls ),
->filter( function ( $widget ) {
return ! empty( $widget['controls'] );
$force_locale->restore();
* Ajax handler for Elementor render_widget.
* Fired by `wp_ajax_elementor_render_widget` action.
* @throws \Exception If current user don't have permissions to edit the post.
* @param array $request Ajax request.
* @type string $render The rendered HTML.
public function ajax_render_widget( $request ) {
$document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
// Override the global $post for the render.
'p' => $request['editor_post_id'],
$editor = Plugin::$instance->editor;
$is_edit_mode = $editor->is_edit_mode();
$editor->set_edit_mode( true );
Plugin::$instance->documents->switch_to_document( $document );
$render_html = $document->render_element( $request['data'] );
$editor->set_edit_mode( $is_edit_mode );
'render' => $render_html,
* Ajax get WordPress widget form.
* Ajax handler for Elementor editor get_wp_widget_form.
* Fired by `wp_ajax_elementor_editor_get_wp_widget_form` action.
* @param array $request Ajax request.
* @return bool|string Rendered widget form.
* @throws \Exception If current user don't have permissions to edit the post.
public function ajax_get_wp_widget_form( $request ) {
Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );