Elementor Widget Compatible with WPML File

Hi, I read WPML article to build this file. https://wpml.org/documentation/plugins-compatibility/elementor/how-to-add-wpml-support-to-custom-elementor-widgets/#adding-wpml-translation-support
mail@pastecode.io avatar
unknown
php
3 years ago
3.1 kB
4
Indexable
Never
<?php
/**
 *  WPML Compatible
 *  ---------------
 */
if( ! class_exists( 'WOUI_WPML_Compatable' ) ){

    class WOUI_WPML_Compatable{

        /**
         *  Member Variable
         *  ---------------
         */
        private static $instance;

        /**
         *  Initiator
         *  ---------
         */
        public static function get_instance() {
          
            if ( ! isset( self::$instance ) ) {

                self::$instance = new self;
            }

            return  self::$instance;
        }

        public function __construct() {

        	add_action( 'init', function(){

        		add_filter( 'wpml_elementor_widgets_to_translate', [ $this, 'wpml_widgets_to_translate_filter' ] );

        	} );
        }

	    public static function wpml_widgets_to_translate_filter( $widgets ){

	        $widgets['weddingcity-feature-button'] = array(

	            'conditions'                =>  array( 'widgetType' => 'weddingcity-feature-button' ),

	            'integration-class' 		=> 	'WeddingDir_Feature_Widget_WPML_Support',

	            'fields'                    =>  array(

	                'btn_text'              =>  array(

	                                                'field'       =>  'btn_text',

	                                                'type'        =>  __( 'Featured Button: Title', 'woui-config' ),

	                                                'editor_type' =>  'LINE',
	                                            ),

	                'btn_link'              =>  array(

	                                                'field'       =>  'btn_link',

	                                                'type'        =>  __( 'Featured Button: Link', 'woui-config' ),

	                                                'editor_type' =>  'LINK',
	                                            ),
	            ),
	        );

	        $widgets[ 'weddingcity-sliders' ] = array(

	            'conditions'                =>  array( 'widgetType' => 'weddingcity-sliders' ),

	            'fields'                    =>  array(

	                'slider_title'          =>  array(

	                                                'field'       =>  'slider_title',

	                                                'type'        =>  __( 'Form: Title', 'woui-config' ),

	                                                'editor_type' =>  'LINE',
	                                            ),

	                'slider_description'    =>  array(

	                                                'field'       =>  'slider_description',

	                                                'type'        =>  __( 'Form: Description', 'woui-config' ),

	                                                'editor_type' =>  'LINE',
	                                            ),
	            ),
	        );

	        /**
	         *  Return WPML Compatible
	         *  ----------------------
	         */
	        return  $widgets;
	    }
    }

    /**
    *  Kicking this off by calling 'get_instance()' method
    */
    WOUI_WPML_Compatable::get_instance();
}