From 7f4e3cf63f9bbf7a1a03bfb9ee5557965a01b7d0 Mon Sep 17 00:00:00 2001 From: Arnel Borres Go Date: Wed, 29 May 2024 16:26:28 +0800 Subject: [PATCH] added initial files --- elementor-custom-search.php | 28 +++++ widget-ecs-custom-search.php | 218 +++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 elementor-custom-search.php create mode 100644 widget-ecs-custom-search.php diff --git a/elementor-custom-search.php b/elementor-custom-search.php new file mode 100644 index 0000000..2b92e40 --- /dev/null +++ b/elementor-custom-search.php @@ -0,0 +1,28 @@ +is_search && !is_admin() && $query->is_main_query()) { + $query->set('post_type', array('post', 'page', 'your_custom_post_type')); + } + return $query; +} +add_filter('pre_get_posts', 'ecs_include_custom_post_types_in_search'); + +function ecs_register_custom_search_widget($widgets_manager) +{ + require_once plugin_dir_path(__FILE__) . 'widget-ecs-custom-search.php'; + $widgets_manager->register(new \ECS_Custom_Search_Widget()); +} +add_action('elementor/widgets/widgets_registered', 'ecs_register_custom_search_widget'); diff --git a/widget-ecs-custom-search.php b/widget-ecs-custom-search.php new file mode 100644 index 0000000..4e9ff4c --- /dev/null +++ b/widget-ecs-custom-search.php @@ -0,0 +1,218 @@ +start_controls_section( + 'content_section', + [ + 'label' => __('Content', 'elementor-custom-search'), + 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, + ] + ); + + $this->add_control( + 'placeholder', + [ + 'label' => __('Placeholder', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::TEXT, + 'default' => __('Search...', 'elementor-custom-search'), + ] + ); + + $this->add_control( + 'button_text', + [ + 'label' => __('Button Text', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::TEXT, + 'default' => __('Search', 'elementor-custom-search'), + ] + ); + + $this->end_controls_section(); + + $this->start_controls_section( + 'style_section', + [ + 'label' => __('Style', 'elementor-custom-search'), + 'tab' => \Elementor\Controls_Manager::TAB_STYLE, + ] + ); + + $this->add_control( + 'input_background', + [ + 'label' => __('Input Background', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::COLOR, + 'selectors' => [ + '{{WRAPPER}} input[type="text"]' => 'background-color: {{VALUE}};', + ], + ] + ); + + $this->add_control( + 'input_text_color', + [ + 'label' => __('Input Text Color', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::COLOR, + 'selectors' => [ + '{{WRAPPER}} input[type="text"]' => 'color: {{VALUE}};', + ], + ] + ); + + $this->add_responsive_control( + 'input_padding', + [ + 'label' => __('Input Padding', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::DIMENSIONS, + 'size_units' => ['px', '%', 'em'], + 'selectors' => [ + '{{WRAPPER}} input[type="text"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', + ], + ] + ); + + $this->add_responsive_control( + 'input_border_radius', + [ + 'label' => __('Input Border Radius', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::DIMENSIONS, + 'size_units' => ['px', '%'], + 'selectors' => [ + '{{WRAPPER}} input[type="text"]' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', + ], + ] + ); + + $this->add_responsive_control( + 'input_font_size', + [ + 'label' => __('Input Font Size', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::SLIDER, + 'range' => [ + 'px' => [ + 'min' => 10, + 'max' => 50, + ], + ], + 'selectors' => [ + '{{WRAPPER}} input[type="text"]' => 'font-size: {{SIZE}}{{UNIT}};', + ], + ] + ); + + $this->add_control( + 'button_background', + [ + 'label' => __('Button Background', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::COLOR, + 'selectors' => [ + '{{WRAPPER}} button' => 'background-color: {{VALUE}};', + ], + ] + ); + + $this->add_control( + 'button_text_color', + [ + 'label' => __('Button Text Color', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::COLOR, + 'selectors' => [ + '{{WRAPPER}} button' => 'color: {{VALUE}};', + ], + ] + ); + + $this->add_responsive_control( + 'button_padding', + [ + 'label' => __('Button Padding', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::DIMENSIONS, + 'size_units' => ['px', '%', 'em'], + 'selectors' => [ + '{{WRAPPER}} button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', + ], + ] + ); + + $this->add_responsive_control( + 'button_border_radius', + [ + 'label' => __('Button Border Radius', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::DIMENSIONS, + 'size_units' => ['px', '%'], + 'selectors' => [ + '{{WRAPPER}} button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', + ], + ] + ); + + $this->add_responsive_control( + 'button_font_size', + [ + 'label' => __('Button Font Size', 'elementor-custom-search'), + 'type' => \Elementor\Controls_Manager::SLIDER, + 'range' => [ + 'px' => [ + 'min' => 10, + 'max' => 50, + ], + ], + 'selectors' => [ + '{{WRAPPER}} button' => 'font-size: {{SIZE}}{{UNIT}};', + ], + ] + ); + + $this->end_controls_section(); + } + + protected function render() + { + $settings = $this->get_settings_for_display(); +?> + +
+ + +
+ + + <# var placeholder=settings.placeholder ? settings.placeholder : 'Search...' ; var buttonText=settings.button_text ? settings.button_text : 'Search' ; #> + +
+ + +
+ + \ No newline at end of file