Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private function add_actions() {
add_action( 'elementor/frontend/after_register_scripts', function() {
wp_register_script( 'hello-world', plugins_url( '/assets/js/hello-world.js', ELEMENTOR_HELLO_WORLD__FILE__ ), [ 'jquery' ], false, true );
} );
add_action( 'init', [ $this, 'add_wpml_support' ] );
}

/**
Expand All @@ -60,7 +61,7 @@ public function on_widgets_registered() {
* @access private
*/
private function includes() {
require __DIR__ . '/widgets/hello-world.php';
require_once __DIR__ . '/widgets/hello-world.php';
}

/**
Expand All @@ -73,6 +74,12 @@ private function includes() {
private function register_widget() {
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Hello_World() );
}

public function add_wpml_support() {
$this->includes();
$widget = new Hello_World();
$widget->add_wpml_support();
}
}

new Plugin();
19 changes: 19 additions & 0 deletions widgets/hello-world.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ protected function _content_template() {
</div>
<?php
}

public function add_wpml_support() {
add_filter( 'wpml_elementor_widgets_to_translate', [ $this, 'wpml_widgets_to_translate_filter' ] );
}

public function wpml_widgets_to_translate_filter( $widgets ) {
$widgets[ $this->get_name() ] = [
'conditions' => [ 'widgetType' => $this->get_name() ],
'fields' => [
[
'field' => 'title',
'type' => __( 'Hello World Title', 'hello-world' ),
'editor_type' => 'LINE'
],
],
];

return $widgets;
}
}