'locale']; $force_locale = new Force_Locale( $locale ); $force_locale->force(); $controls = ( new Collection( $this->get_widget_types() ) ) ->map( function ( Widget_Base $widget ) { $controls = $widget->get_stack( false )['controls']; return [ 'controls' => $this->pluck_default_controls( $controls ), ]; } ) ->filter( function ( $widget ) { return ! empty( $widget['controls'] ); } ) ->all(); $force_locale->restore(); return $controls; } /** * Ajax render widget. * * Ajax handler for Elementor render_widget. * * Fired by `wp_ajax_elementor_render_widget` action. * * @since 1.0.0 * @access public * * @throws \Exception If current user don't have permissions to edit the post. * * @param array $request Ajax request. * * @return array { * Rendered widget. * * @type string $render The rendered HTML. * } */ public function ajax_render_widget( $request ) { $document = Plugin::$instance->documents->get( $request['editor_post_id'] ); if ( ! $document->is_editable_by_current_user() ) { throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN ); } // Override the global $post for the render. query_posts( [ 'p' => $request['editor_post_id'], 'post_type' => 'any', ] ); $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 ); return [ '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. * * @since 1.0.0 * @access public * * @param array $request Ajax request. * * @return bool|string Rendered widget form. */ public function ajax_get_wp_widget_form( $request ) { if ( empty( $request['widget_type'] ) ) { return false; } if ( empty( $request['data'] ) ) { $request['data'] = []; } $element_data = [ 'id' => $request['id'], 'elType' => 'widget', 'widgetType' => $request['widget_type'], 'settings' => $request['data'], ]; /** * @var $widget_obj Widget_WordPress */ $widget_obj = Plugin::$instance->elements_manager->create_element_instance( $element_data ); if ( ! $widget_obj ) { return false; } return $widget_obj->get_form(); } /** * Render widgets content. * * Used to generate the widget templates on the editor using Underscore JS * template, for all the registered widget types. * * @since 1.0.0 * @access public */ public function render_widgets_content() { foreach ( $this->get_widget_types() as $widget ) { $widget->print_template(); } } /** * Get widgets frontend settings keys. * * Retrieve frontend controls settings keys for all the registered widget * types. * * @since 1.3.0 * @access public * * @return array Registered widget types with settings keys for each widget. */ public function get_widgets_frontend_settings_keys() { $keys = []; foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) { $widget_type_keys = $widget_type->get_frontend_settings_keys(); if ( $widget_type_keys ) { $keys[ $widget_type_name ] = $widget_type_keys; } } return $keys; } /** * Enqueue widgets scripts. * * Enqueue all the scripts defined as a dependency for each widget. * * @since 1.3.0 * @access public */ public function enqueue_widgets_scripts() { foreach ( $this->get_widget_types() as $widget ) { $widget->enqueue_scripts(); } } /** * Enqueue widgets styles * * Enqueue all the styles defined as a dependency for each widget * * @access public */ public function enqueue_widgets_styles() { foreach ( $this->get_widget_types() as $widget ) { $widget->enqueue_styles(); } } /** * Retrieve inline editing configuration. * * Returns general inline editing configurations like toolbar types etc. * * @access public * @since 1.8.0 * * @return array { * Inline editing configuration. * * @type array $toolbar { * Toolbar types and the actions each toolbar includes. * Note: Wysiwyg controls uses the advanced toolbar, textarea controls * uses the basic toolbar and text controls has no toolbar. * * @type array $basic Basic actions included in the edit tool. * @type array $advanced Advanced actions included in the edit tool. * } * } */ public function get_inline_editing_config() { $basic_tools = [ 'bold', 'underline', 'italic', ]; $advanced_tools = array_merge( $basic_tools, [ 'createlink', 'unlink', 'h1' => [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'pre', ], 'list' => [ 'insertOrderedList', 'insertUnorderedList', ], ] ); return [ 'toolbar' => [ 'basic' => $basic_tools, 'advanced' => $advanced_tools, ], ]; } /** * Widgets manager constructor. * * Initializing Elementor widgets manager. * * @since 1.0.0 * @access public */ public function __construct() { $this->require_files(); add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); } /** * Register ajax actions. * * Add new actions to handle data after an ajax requests returned. * * @since 2.0.0 * @access public * * @param Ajax $ajax_manager */ public function register_ajax_actions( Ajax $ajax_manager ) { $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] ); $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] ); $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] ); $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) { return $this->ajax_get_widgets_default_value_translations( $data ); } ); } }