### License Activation Usage Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/cli/license-activate.md An example of how to use the license activation command. ```bash wp elementor-pro license activate XXX ``` -------------------------------- ### Components and sub-components convention example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/js/components.md This example illustrates the convention for naming component and sub-component folders and files, using 'Document' and 'Elements' as an example. ```javascript export { default as ElementsComponent } from './elements/component.js'; ``` ```javascript import * as components from './'; export default class Component extends $e.modules.ComponentBase { getNamespace() { return 'document'; } registerAPI() { // Register sub components. Object.values( components ).forEach( ( ComponentClass ) => $e.components.register( new ComponentClass ) ); super.registerAPI(); } } export default class Component; ``` ```javascript export default class Component extends $e.modules.ComponentBase { getNamespace() { return 'elements'; } } export default class Component; ``` -------------------------------- ### Usage Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/cli/library-import-dir.md Example of how to use the `library import-dir` command to import templates from a specified directory. ```bash wp elementor library import-dir path/to/custom-templates/ ``` -------------------------------- ### Injecting Controls After Section Start Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/hooks/injecting-controls.md This example shows how to add a control after a section has started but before it has ended, within a specific element and section. ```php /** * @param \Elementor\Controls_Stack $element The element type. * @param array $args Section arguments. */ function inject_heading_controls( $element, $args ) { $element->add_control( 'custom_control', [ 'type' => \Elementor\Controls_Manager::NUMBER, 'label' => esc_html__( 'Custom Control', 'textdomain' ), ] ); } add_action( 'elementor/element/heading/section_title/before_section_start', 'inject_heading_controls', 10, 2 ); ``` -------------------------------- ### Global Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/editor-controls/global-style.md Example demonstrating how controls can inherit global styles for colors and typography. ```php $this->add_control( 'heading_color', [ 'label' => esc_html__( 'Heading Color', 'textdomain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .heading-class' => 'color: {{VALUE}}; ], 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY, ], ] ); $this->add_control( 'sub_heading_color', [ 'label' => esc_html__( 'Sub Heading Color', 'textdomain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sub-heading-class' => 'color: {{VALUE}}; ], 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_SECONDARY, ], ] ); $this->add_control( 'content_color', [ 'label' => esc_html__( 'Content Color', 'textdomain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .content-class' => 'color: {{VALUE}}; ], 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_TEXT, ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'heading_typography', 'selector' => '{{WRAPPER}} .heading-class', 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY, ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'sub_heading_typography', 'selector' => '{{WRAPPER}} .sub_heading-class', 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_SECONDARY, ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'content_typography', 'selector' => '{{WRAPPER}} .content-class', 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_TEXT, ], ] ); ``` -------------------------------- ### Elementor Init Hook Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/hooks/elementor-init.md A basic example of how to hook into the elementor/init action. ```php function my_plugin() { // ... } add_action( 'elementor/init', 'my_plugin' ); ``` -------------------------------- ### Injecting Controls Before Section Start Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/hooks/injecting-controls.md This example demonstrates how to add a new section and a control before the start of a specific section in an Elementor element. ```php /** * @param \Elementor\Controls_Stack $element The element type. * @param array $args Section arguments. */ function inject_heading_controls( $element, $args ) { $element->start_controls_section( 'custom_section', [ 'tab' => \Elementor\Controls_Manager::TAB_STYLE, 'label' => esc_html__( 'Custom Section', 'textdomain' ), ] ); $element->add_control( 'custom_control', [ 'type' => \Elementor\Controls_Manager::NUMBER, 'label' => esc_html__( 'Custom Control', 'textdomain' ), ] ); $element->end_controls_section(); } add_action( 'elementor/element/heading/section_title/before_section_start', 'inject_heading_controls', 10, 2 ); ``` -------------------------------- ### Example: Styled Page Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/data-structure/page-settings.md Shows a JSON example of a page with basic styling settings applied. ```json { "title": "Template Title", "type": "page", "version": "0.4", "page_settings": { "background_background": "classic", "background_color": "#FFFFFF", "margin": { "unit": "px", "top": "0", "right": "0", "bottom": "0", "left": "0", "isLinked": true }, "padding": { "unit": "px", "top": "0", "right": "10", "bottom": "0", "left": "10", "isLinked": false }, "scroll_snap": "yes" }, "content": [] } ``` -------------------------------- ### Example: Empty Page Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/data-structure/page-settings.md Provides a JSON example of an empty page that has no associated settings. ```json { "title": "About Page", "type": "page", "version": "0.4", "page_settings": [], "content": [] } ``` -------------------------------- ### Example of creating and registering a new component Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/js/components.md This example demonstrates how to create and register a new component, which can be run in the console and does not depend on anything else. ```javascript // Example of creating and registering a new component, available to run in the console and does not depend on anything else. class CustomComponent extends $e.modules.ComponentBase { getNamespace() { return 'custom-component'; } defaultCommands() { // Object of all the component commands. return { // 'example' command. example: ( args ) => { // Output command args to console. console.log( 'ExampleCommand: ', args ); // Return object as example. return { example: 'result from ExampleCommand', }; }, }; } } // Register the new component. $e.components.register( new CustomComponent() ); // Runs 'example' command from 'custom-component'. result = $e.run( 'custom-component/example', { property: 'value', } ); // Output command run result. console.log( 'e-components-eg-1-result: ', result ); ``` -------------------------------- ### Enqueue Method Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/controls/control-enqueue.md Example of how to register and enqueue styles and scripts for a custom Elementor control. ```php class Elementor_Test_Control extends \Elementor\Base_Control { protected function enqueue(): void { // Styles wp_register_style( 'control-style', plugins_url( 'assets/css/control-style.css', __FILE__ ) ); wp_enqueue_style( 'control-style' ); // Scripts wp_register_script( 'control-script', plugins_url( 'assets/js/control-script.js', __FILE__ ) ); wp_enqueue_script( 'control-script' ); } } ``` -------------------------------- ### Example Addon Main File Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/addons/load.md This example demonstrates the main plugin file for an Elementor addon, including loading its manager files after the 'plugins_loaded' hook. ```php $sendy_data, ] ); } /** * On export. * * Clears Sendy form settings/fields when exporting. * * @since 1.0.0 * @access public * @param array $element */ public function on_export( $element ): array { unset( $element['sendy_url'], $element['sendy_list'], $element['sendy_email_field'], $element['sendy_name_field'] ); return $element; } } ``` -------------------------------- ### Main Plugin File Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/addons/namespaces.md Example of the main plugin file (`elementor-test-addon.php`) that loads the addon's functionality and defines the main namespace. ```php add_control( 'unique-control-name', [ 'type' => \Elementor\Controls_Manager::TEXT, 'label' => esc_html__( 'Control Label', 'textdomain' ), 'description' => esc_html__( 'Short control description.', 'textdomain' ), ] ); ``` -------------------------------- ### Addon Code Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/addons/addon-example.md This PHP code demonstrates the structure of an Elementor addon, including initialization, widget registration, and control registration. ```php if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); $message = sprintf( /* translators: 1: Plugin name 2: PHP 3: Required PHP version */ esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'elementor-test-addon' ), '' . esc_html__( 'Elementor Test Addon', 'elementor-test-addon' ) . '', '' . esc_html__( 'PHP', 'elementor-test-addon' ) . '', self::MINIMUM_PHP_VERSION ); printf( '
%1$s
<# if ( '' === settings.title ) { return; } #>
{{ settings.title }}
start_controls_section( 'style_section', [ 'label' => esc_html__( 'Style', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'text_color', [ 'label' => esc_html__( 'Text Color', 'textdomain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .your-class' => 'color: {{VALUE}}', ], ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); ?>Hello World
Hello World
start_controls_section( 'content_section', [ 'label' => esc_html__( 'Content', 'elementor-oembed-widget' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'url', [ 'label' => esc_html__( 'URL to embed', 'elementor-oembed-widget' ), 'type' => \Elementor\Controls_Manager::TEXT, 'input_type' => 'url', 'placeholder' => esc_html__( 'https://your-link.com', 'elementor-oembed-widget' ), ] ); $this->end_controls_section(); } /** * Render oEmbed widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 1.0.0 * @access protected */ protected function render(): void { $settings = $this->get_settings_for_display(); if ( empty( $settings['url'] ) ) { return; } $html = wp_oembed_get( $settings['url'] ); ?> register( new \Elementor_Currency_Control() ); } add_action( 'elementor/controls/register', 'register_currency_control' ); /** * Register Currency Widget. * * Include widget file and register widget class. * * @since 1.0.0 * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager. * @return void */ function register_currency_widget( $widgets_manager ) { require_once( __DIR__ . '/widgets/currency-widget.php' ); $widgets_manager->register( new \Elementor_Currency_Widget() ); } add_action( 'elementor/widgets/register', 'register_currency_widget' ); ``` -------------------------------- ### Typography Control Example Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/editor-controls/group-control.md Example of adding a typography group control to style text elements in an Elementor widget. ```php class Elementor_Test_Widget extends \Elementor\Widget_Base { protected function register_controls(): void { $this->start_controls_section( 'style_section', [ 'label' => esc_html__( 'Style', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .title', ] ); $this->end_controls_section(); } } ``` -------------------------------- ### Example of Inline Editing with Different Toolbars Source: https://github.com/elementor/elementor-developers-docs/blob/master/src/widgets/rendering-inline-editing.md This example shows a full implementation with three controls: a title with no toolbar, a description with a basic toolbar, and content with an advanced toolbar, demonstrating inline editing capabilities. ```php start_controls_section( 'content_section', [ 'label' => esc_html__( 'Content', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'title', [ 'label' => esc_html__( 'Title', 'textdomain' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => esc_html__( 'Title', 'textdomain' ), ] ); $this->add_control( 'description', [ 'label' => esc_html__( 'Description', 'textdomain' ), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'default' => esc_html__( 'Description', 'textdomain' ), ] ); $this->add_control( 'content', [ 'label' => esc_html__( 'Content', 'textdomain' ), 'type' => \Elementor\Controls_Manager::WYSIWYG, 'default' => esc_html__( 'Content', 'textdomain' ), ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); $this->add_inline_editing_attributes( 'title', 'none' ); $this->add_inline_editing_attributes( 'description', 'basic' ); $this->add_inline_editing_attributes( 'content', 'advanced' ); ?>