Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a new widget? #56

Closed
nicolas92 opened this issue Jun 9, 2016 · 9 comments
Closed

How to add a new widget? #56

nicolas92 opened this issue Jun 9, 2016 · 9 comments
Assignees
Labels
question* [DEPRECATED] Indicates when an issue is used to ask a Question.

Comments

@nicolas92
Copy link

Hello, first of all, great plugin, I rated 5 stars :)
I would like to add a new widget, but I can not declare my file, I use the following code:

function new_widget() {
    
    $build_widgets_filename = [
        'widget1',
        'widget2',
    ];

    foreach ( $build_widgets_filename as $widget_filename ) {
        include( $this->plugin_path . 'includes/widgets/' . $widget_filename . '.php' );

        $class_name = ucwords( $widget_filename );
        $class_name = str_replace( '-', '_', $class_name );
    }

}
add_action( 'init', 'new_widget', 20 );

But this code does not work, can you help me?
Thank you a lot :)

@yehudah
Copy link

yehudah commented Jun 9, 2016

Hi,

We still don't have official API, but you can write a regular WordPress widget and he will be available in builder widgets.

@KingYes
Copy link
Member

KingYes commented Jun 9, 2016

@nicolas92 Fast example:

add_action( 'elementor/widgets/widgets_registered', function() {
    \Elementor\Plugin::instance()->widgets_manager->register_widget( 'WIDGET_CLASS' );
} );

Change the WIDGET_CLASS to your own class of the widget.

BTW, as @yehudah say, it's not official API to register widgets, so maybe it's can to change in later versions of the Elementor. But for now it's need to be work for you.

@KingYes KingYes added the question* [DEPRECATED] Indicates when an issue is used to ask a Question. label Jun 9, 2016
@nicolas92
Copy link
Author

Ah thin, I thought it was possible, prévoyer you do it in long time?
I think your plugin will cartoning, so many dévelloppeur will want to integrate their own widgets like visual composer.

@nicolas92
Copy link
Author

Thank you very much @KingYes, but it is not urgent, I'll wait for the official API, thank you :)

@KingYes
Copy link
Member

KingYes commented Jun 9, 2016

No problem :)
Thanks for your review and 5-stars 👍

@KingYes KingYes closed this as completed Jun 9, 2016
@KingYes KingYes self-assigned this Jun 9, 2016
@nicolas92
Copy link
Author

You deserved, amazing plugin :)

@jonathanbossenger
Copy link

jonathanbossenger commented Apr 16, 2018

@KingYes I hope you don't mind me commenting on this, but it would be helpful to get this added to the newly created developer portal - https://developers.elementor.com/creating-a-new-widget/

I've used

\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Class_Name_Widget() );

in case any stumbles across this.

@shangdev
Copy link

shangdev commented May 4, 2018

@jonathanbossenger Hello,when I created customize new widget,There are some Widget Controls not working, E.g: SLIDER/COLOR/SWITCHER,

Have you encountered this problem?

@vollyimnetz
Copy link

vollyimnetz commented Mar 8, 2020

I used the following code inside my functions.php to add an elementor-widget.

add_action( 'elementor/widgets/widgets_registered', function($elementorWidgetManager) {
	include_once __DIR__.'/path-to-my-widget-file.php';
	$elementorWidgetManager->register_widget_type( new MyCustomElementorWidget() );
});

By making the include of the code inside the action-hook, i can make sure elementor is installed, active and already loaded.

I support the request of @jonathanbossenger, it belongs something in the documentation how a new elementor widget can be registered correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question* [DEPRECATED] Indicates when an issue is used to ask a Question.
Projects
None yet
Development

No branches or pull requests

6 participants