├── elementor-custom-element.php └── my-widget.php /elementor-custom-element.php: -------------------------------------------------------------------------------- 1 | widgets_manager ) ) { 57 | if ( method_exists( $elementor->widgets_manager, 'register_widget_type' ) ) { 58 | 59 | $widget_file = 'plugins/elementor/my-widget.php'; 60 | $template_file = locate_template( $widget_file ); 61 | if ( $template_file && is_readable( $template_file ) ) { 62 | require_once $template_file; 63 | Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Elementor\Widget_My_Custom_Elementor_Thing() ); 64 | 65 | } 66 | } 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | ElementorCustomElement::get_instance()->init(); 75 | -------------------------------------------------------------------------------- /my-widget.php: -------------------------------------------------------------------------------- 1 | start_controls_section( 24 | 'section_my_custom', 25 | [ 26 | 'label' => esc_html__( 'Blog Posts', 'elementor' ), 27 | ] 28 | ); 29 | 30 | 31 | $this->add_control( 32 | 'some_text', 33 | [ 34 | 'label' => __( 'Text', 'elementor-custom-element' ), 35 | 'type' => Controls_Manager::TEXT, 36 | 'default' => '', 37 | 'title' => __( 'Enter some text', 'elementor-custom-element' ), 38 | ] 39 | ); 40 | 41 | $this->add_control( 42 | 'posts_per_page', 43 | [ 44 | 'label' => __( 'Number of Posts', 'elementor-custom-element' ), 45 | 'type' => Controls_Manager::SELECT, 46 | 'default' => 5, 47 | 'options' => [ 48 | 1 => __( 'One', 'elementor-custom-element' ), 49 | 2 => __( 'Two', 'elementor-custom-element' ), 50 | 5 => __( 'Five', 'elementor-custom-element' ), 51 | 10 => __( 'Ten', 'elementor-custom-element' ), 52 | ] 53 | ] 54 | ); 55 | 56 | $this->end_controls_section(); 57 | 58 | } 59 | 60 | protected function render( $instance = [] ) { 61 | 62 | // get our input from the widget settings. 63 | 64 | $custom_text = ! empty( $instance['some_text'] ) ? $instance['some_text'] : ' (no text was entered ) '; 65 | $post_count = ! empty( $instance['posts_per_page'] ) ? (int)$instance['posts_per_page'] : 5; 66 | 67 | ?> 68 | 69 |
My text was:
71 |