PluginProbe
Year Make Model Search for WooCommerce / trunk
Year Make Model Search for WooCommerce vtrunk
ymm-search / Widget / Selector.php

Selector.php in Year Make Model Search for WooCommerce trunk, at Widget/Selector.php

118 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 class Pektsekye_Ymm_Widget_Selector extends WP_Widget {
8
9
10 function __construct() {
11
12 $widgetOptions = array(
13 'description' => __( 'Year Make Model search box for WooCommerce products.', 'ymm-search')
14 );
15
16 parent::__construct(false, _x('YMM Search', 'Wigdet title in admin panel', 'ymm-search'), $widgetOptions);
17 }
18
19
20 // widget form creation
21 function form($instance) {
22
23 // Check values
24 if ( $instance && !empty($instance['title'])) {
25 $title = esc_attr($instance['title']);
26 } else {
27 $title = __('Search by Vehicle', 'ymm-search');
28 }
29 if ( $instance && !empty($instance['filter_title'])) {
30 $filterTitle = esc_attr($instance['filter_title']);
31 } else {
32 $filterTitle = __('Filter by Vehicle', 'ymm-search');
33 }
34 if ( $instance && !empty($instance['as_filter_on_category_page'])) {
35 $filterCategoryPage = esc_attr($instance['as_filter_on_category_page']);
36 } else {
37 $filterCategoryPage = 0;
38 }
39
40 $garageEnabled = !isset($instance['garage_enabled']) || $instance['garage_enabled'] == 1 ? 1 : 0;
41 $removeFromGarageEnabled = !isset($instance['remove_from_garage_enabled']) || $instance['remove_from_garage_enabled'] == 1 ? 1 : 0;
42
43 ?>
44 <p>
45 <label for="<?php echo $this->get_field_id('title'); ?>"><?php echo __('Search Box Title', 'ymm-search'); ?></label>
46 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
47 </p>
48 <p>
49 <label for="<?php echo $this->get_field_id('filter_title'); ?>"><?php echo __('Filter Box Title', 'ymm-search'); ?></label>
50 <input class="widefat" id="<?php echo $this->get_field_id('filter_title'); ?>" name="<?php echo $this->get_field_name('filter_title'); ?>" type="text" value="<?php echo $filterTitle; ?>" />
51 </p>
52 <p>
53 <input class="widefat" id="<?php echo $this->get_field_id('as_filter_on_category_page'); ?>" name="<?php echo $this->get_field_name('as_filter_on_category_page'); ?>" type="checkbox" value="1" <?php echo $filterCategoryPage == 1 ? 'checked="checked"' : ''; ?>/>
54 <label for="<?php echo $this->get_field_id('as_filter_on_category_page'); ?>"><?php echo __('Filter products on category page', 'ymm-search'); ?></label>
55 </p>
56 <p>
57 <input class="widefat" id="<?php echo $this->get_field_id('garage_enabled'); ?>" name="<?php echo $this->get_field_name('garage_enabled'); ?>" type="checkbox" value="1" <?php echo $garageEnabled == 1 ? 'checked="checked"' : ''; ?>/>
58 <label for="<?php echo $this->get_field_id('garage_enabled'); ?>"><?php echo __('Enable Garage feature', 'ymm-search'); ?></label>
59 </p>
60 <p>
61 <input class="widefat" id="<?php echo $this->get_field_id('remove_from_garage_enabled'); ?>" name="<?php echo $this->get_field_name('remove_from_garage_enabled'); ?>" type="checkbox" value="1" <?php echo $removeFromGarageEnabled == 1 ? 'checked="checked"' : ''; ?>/>
62 <label for="<?php echo $this->get_field_id('remove_from_garage_enabled'); ?>"><?php echo __('Enable "Remove from Garage" link', 'ymm-search'); ?></label>
63 </p>
64 <?php
65 }
66
67
68 // widget update
69 function update($new_instance, $old_instance) {
70 $instance = $old_instance;
71 // Fields
72 $instance['title'] = strip_tags($new_instance['title']);
73 $instance['filter_title'] = strip_tags($new_instance['filter_title']);
74 $instance['as_filter_on_category_page'] = isset($new_instance['as_filter_on_category_page']) && $new_instance['as_filter_on_category_page'] == 1 ? 1 : 0;
75 $instance['garage_enabled'] = isset($new_instance['garage_enabled']) && $new_instance['garage_enabled'] == 1 ? 1 : 0;
76 $instance['remove_from_garage_enabled'] = isset($new_instance['remove_from_garage_enabled']) && $new_instance['remove_from_garage_enabled'] == 1 ? 1 : 0;
77 return $instance;
78 }
79
80
81 // widget display
82 function widget($args, $instance) {
83 extract( $args );
84
85 $searchTitle = isset($instance['title']) ? $instance['title'] : '';
86 $filterTitle = isset($instance['filter_title']) ? $instance['filter_title'] : '';
87 $filterCategory = isset($instance['as_filter_on_category_page']) && $instance['as_filter_on_category_page'] == 1;
88 $garageEnabled = isset($instance['garage_enabled']) && $instance['garage_enabled'] == 1;
89 $removeFromGarageEnabled = !isset($instance['remove_from_garage_enabled']) || $instance['remove_from_garage_enabled'] == 1;
90
91 $title = $filterCategory && is_product_category() ? $filterTitle : $searchTitle;
92
93 echo $before_widget;
94 // Display the widget
95
96 echo '<div class="widget-text wp_widget_plugin_box">';
97
98 // Check if title is set
99 if ( $title ) {
100 echo $before_title . $title . $after_title;
101 }
102
103 include_once( Pektsekye_YMM()->getPluginPath() . 'Block/Selector.php');
104
105 $block = new Pektsekye_Ymm_Block_Selector();
106 if (isset($args['widget_id'])){
107 $block->setWidgetId($args['widget_id']);
108 }
109 $block->setSearchTitle($searchTitle);
110 $block->setFilterCategoryPage($filterCategory);
111 $block->setGarageEnabled($garageEnabled);
112 $block->setRemoveFromGarageEnabled($removeFromGarageEnabled);
113 $block->page_init();
114
115 echo '</div>';
116 echo $after_widget;
117 }
118 }