PluginProbe
Borderless – Addons and Templates for Elementor / 1.2.3
Borderless – Addons and Templates for Elementor v1.2.3
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / includes / widgets / search.php

search.php in Borderless – Addons and Templates for Elementor 1.2.3, at includes/widgets/search.php

267 lines 15.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Adds Borderless_Widget_Search widget.
5 */
6 class Borderless_Widget_Search extends WP_Widget {
7
8 /**
9 * Register widget with WordPress.
10 */
11 public function __construct() {
12
13 parent::__construct(
14 'borderless_search', // Base ID
15 __( 'Borderless - Search', 'borderless' ), // Name
16 array( 'description' => __( 'A search form for your site.', 'borderless' ), ) // Args
17 );
18 }
19
20 /**
21 * Front-end display of widget.
22 *
23 * @see WP_Widget::widget()
24 *
25 * @param array $args Widget arguments.
26 * @param array $instance Saved values from database.
27 */
28 public function widget( $args, $instance ) {
29 extract( $args );
30 $button = apply_filters( 'widget_button', $instance['button'] );
31 $sizing = apply_filters( 'widget_sizing', $instance['sizing'] );
32 $button_text = apply_filters( 'widget_button_text', $instance['button_text'] );
33 $button_color = apply_filters( 'widget_button_color', $instance['button_color'] );
34 $input_color = apply_filters( 'widget_input_color', $instance['input_color'] );
35 $type = apply_filters( 'widget_type', $instance['type'] );
36 $placeholder_text = apply_filters( 'widget_placeholder_text', $instance['placeholder_text'] );
37 $shape = apply_filters( 'widget_shape', $instance['shape'] );
38 $title = apply_filters( 'widget_title', $instance['title'] );
39
40 // Retrieve data from the database.
41 $options = get_option( 'borderless' );
42 $borderless_primary_color = isset( $options['primary_color'] ) ? $options['primary_color'] : '#0000FF'; //Primary Color
43 $borderless_secondary_color = isset( $options['secondary_color'] ) ? $options['secondary_color'] : '#FF6819'; //Secondary Color
44 $borderless_tertiary_color = isset( $options['tertiary_color'] ) ? $options['tertiary_color'] : '#3FCC14'; //Accent Color
45 $borderless_text_color = isset( $options['text_color'] ) ? $options['text_color'] : '#333333'; //Text Color
46
47 ?>
48 <style type="text/css">
49 :root {
50 --borderless-color-primary-lighter: <?php echo luminanceLight ( $borderless_primary_color, 0.4 ); ?>;
51 --borderless-color-primary-light: <?php echo luminanceLight ( $borderless_primary_color, 0.2 ); ?>;
52 --borderless-color-primary: <?php echo $borderless_primary_color; ?>;
53 --borderless-color-primary-dark: <?php echo luminanceDark ( $borderless_primary_color, 0.2 ); ?>;
54 --borderless-color-primary-darker: <?php echo luminanceDark ( $borderless_primary_color, 0.4 ); ?>;
55
56 --borderless-color-secondary-lighter: <?php echo luminanceLight ( $borderless_secondary_color, 0.4 ); ?>;
57 --borderless-color-secondary-light: <?php echo luminanceLight ( $borderless_secondary_color, 0.2 ); ?>;
58 --borderless-color-secondary: <?php echo $borderless_secondary_color; ?>;
59 --borderless-color-secondary-dark: <?php echo luminanceDark ( $borderless_secondary_color, 0.2 ); ?>;
60 --borderless-color-secondary-darker: <?php echo luminanceDark ( $borderless_secondary_color, 0.4 ); ?>;
61
62 --borderless-color-tertiary-lighter: <?php echo luminanceLight ( $borderless_tertiary_color, 0.4 ); ?>;
63 --borderless-color-tertiary-light: <?php echo luminanceLight ( $borderless_tertiary_color, 0.2 ); ?>;
64 --borderless-color-tertiary: <?php echo $borderless_tertiary_color; ?>;
65 --borderless-color-tertiary-dark: <?php echo luminanceDark ( $borderless_tertiary_color, 0.2 ); ?>;
66 --borderless-color-tertiary-darker: <?php echo luminanceDark ( $borderless_tertiary_color, 0.4 ); ?>;
67
68 --borderless-text-color: <?php echo $borderless_text_color; ?>;
69 }
70 </style>
71 <?php
72
73 echo $before_widget;
74 if ( ! empty( $title ) ) {
75 echo $before_title . $title . $after_title;
76 } ?>
77
78 <form method="get" id="borderlesssearchform" class="borderless-search <?php echo $button.' '.$shape.' '.$sizing;?>" action="<?php echo esc_url( home_url( '/' ) ); ?>" role="search">
79
80 <?php if ($button == 'borderless-search--left-button') { ?>
81 <input class="submit borderless-btn <?php echo $button_color. ' '.$type; ?>" id="searchsubmit" name="submit" type="submit"
82 value="<?php echo $button_text; ?>">
83 <?php } ?>
84
85 <input class="borderless-search--input <?php echo $input_color; ?>" id="s" name="s" type="text"
86 placeholder="<?php echo $placeholder_text; ?>" value="<?php the_search_query(); ?>">
87
88 <?php if ($button == 'borderless-search--right-button') { ?>
89 <input class="submit borderless-btn <?php echo $button_color. ' '.$type; ?>" id="searchsubmit" name="submit" type="submit"
90 value="<?php echo $button_text; ?>">
91 <?php } ?>
92 </form>
93
94 <?php echo $after_widget;
95 }
96
97 /**
98 * Back-end widget form.
99 *
100 * @see WP_Widget::form()
101 *
102 * @param array $instance Previously saved values from database.
103 */
104 public function form( $instance ) {
105 $type = isset( $instance['type'] ) ? $instance['type'] : '';
106 // Button
107 if ( isset( $instance[ 'button' ] ) ) {
108 $button = $instance[ 'button' ];
109 }
110 else {
111 $button = 'borderless-search--right-button';
112 }
113
114 // Button Text
115 if ( isset( $instance[ 'button_text' ] ) ) {
116 $button_text = $instance[ 'button_text' ];
117 }
118 else {
119 $button_text = __( 'Search', 'borderless' );
120 }
121
122 // Button Text
123 if ( isset( $instance[ 'sizing' ] ) ) {
124 $sizing = $instance[ 'sizing' ];
125 }
126 else {
127 $sizing = '';
128 }
129
130 // Color
131 if ( isset( $instance[ 'button_color' ] ) ) {
132 $button_color = $instance[ 'button_color' ];
133 }
134 else {
135 $button_color = 'borderless-search--btn-primary';
136 }
137
138 if ( isset( $instance[ 'input_color' ] ) ) {
139 $input_color = $instance[ 'input_color' ];
140 }
141 else {
142 $input_color = 'borderless-search--input-light';
143 }
144
145 // Placeholder Text
146 if ( isset( $instance[ 'placeholder_text' ] ) ) {
147 $placeholder_text = $instance[ 'placeholder_text' ];
148 }
149 else {
150 $placeholder_text = __( 'Search...', 'borderless' );
151 }
152
153 // Shape
154 if ( isset( $instance[ 'shape' ] ) ) {
155 $shape = $instance[ 'shape' ];
156 }
157 else {
158 $shape = 'borderless-search--rounded';
159 }
160
161 // Title
162 if ( isset( $instance[ 'title' ] ) ) {
163 $title = $instance[ 'title' ];
164 }
165 else {
166 $title = __( 'New title', 'borderless' );
167 }
168 ?>
169 <p>
170 <label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:', 'borderless' ); ?></label>
171 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
172 </p>
173 <p>
174 <label for="<?php echo $this->get_field_name( 'button_text' ); ?>"><?php _e( 'Button Text:', 'borderless' ); ?></label>
175 <input class="widefat" id="<?php echo $this->get_field_id( 'button_text' ); ?>" name="<?php echo $this->get_field_name( 'button_text' ); ?>" type="text" value="<?php echo esc_attr( $button_text ); ?>" />
176 </p>
177 <p>
178 <label for="<?php echo $this->get_field_name( 'placeholder_text' ); ?>"><?php _e( 'Placeholder Text:', 'borderless' ); ?></label>
179 <input class="widefat" id="<?php echo $this->get_field_id( 'placeholder_text' ); ?>" name="<?php echo $this->get_field_name( 'placeholder_text' ); ?>" type="text" value="<?php echo esc_attr( $placeholder_text ); ?>" />
180 </p>
181 <p>
182 <label for="<?php echo $this->get_field_id('button'); ?>"><?php _e('Button:', 'borderless') ?></label>
183 <select id="<?php echo $this->get_field_id('button'); ?>" name="<?php echo $this->get_field_name('button'); ?>" class="widefat">
184 <option value='borderless-search--no-button'<?php selected( $button, 'borderless-search--no-button'); ?>><?php _e( 'No Button', 'borderless' ); ?></option>
185 <option value='borderless-search--left-button'<?php selected( $button, 'borderless-search--left-button'); ?>><?php _e( 'Left Button', 'borderless' ); ?></option>
186 <option value='borderless-search--right-button'<?php selected( $button, 'borderless-search--right-button'); ?>><?php _e( 'Right Button', 'borderless' ); ?></option>
187 </select>
188 </p>
189 <p>
190 <label for="<?php echo $this->get_field_id('input_color'); ?>"><?php _e('Input Color:', 'borderless') ?></label>
191 <select id="<?php echo $this->get_field_id('input_color'); ?>" name="<?php echo $this->get_field_name('input_color'); ?>" class="widefat">
192 <option value='borderless-search--input-primary'<?php selected( $input_color, 'borderless-search--input-primary'); ?>><?php _e( 'Primary Color', 'borderless' ); ?></option>
193 <option value='borderless-search--input-secondary'<?php selected( $input_color, 'borderless-search--input-secondary'); ?>><?php _e( 'Secondary Color', 'borderless' ); ?></option>
194 <option value='borderless-search--input-tertiary'<?php selected( $input_color, 'borderless-search--input-tertiary'); ?>><?php _e( 'Tertiary Color', 'borderless' ); ?></option>
195 <option value='borderless-search--input-light'<?php selected( $input_color, 'borderless-search--input-light'); ?>><?php _e( 'Light Color', 'borderless' ); ?></option>
196 <option value='borderless-search--input-dark'<?php selected( $input_color, 'borderless-search--input-dark'); ?>><?php _e( 'Dark Color', 'borderless' ); ?></option>
197 </select>
198 </p>
199 <p>
200 <label for="<?php echo $this->get_field_id('button_color'); ?>"><?php _e('Button Color:', 'borderless') ?></label>
201 <select id="<?php echo $this->get_field_id('button_color'); ?>" name="<?php echo $this->get_field_name('button_color'); ?>" class="widefat">
202 <option value='borderless-btn--primary'<?php selected( $button_color, 'borderless-btn--primary'); ?>><?php _e( 'Primary Color', 'borderless' ); ?></option>
203 <option value='borderless-btn--secondary'<?php selected( $button_color, 'borderless-btn--secondary'); ?>><?php _e( 'Secondary Color', 'borderless' ); ?></option>
204 <option value='borderless-btn--tertiary'<?php selected( $button_color, 'borderless-btn--tertiary'); ?>><?php _e( 'Tertiary Color', 'borderless' ); ?></option>
205 <option value='borderless-btn--light'<?php selected( $button_color, 'borderless-btn--light'); ?>><?php _e( 'Light Color', 'borderless' ); ?></option>
206 <option value='borderless-btn--dark'<?php selected( $button_color, 'borderless-btn--dark'); ?>><?php _e( 'Dark Color', 'borderless' ); ?></option>
207 </select>
208 </p>
209 <p>
210 <label for="<?php echo $this->get_field_id('sizing'); ?>"><?php _e('Sizing:', 'borderless') ?></label>
211 <select id="<?php echo $this->get_field_id('sizing'); ?>" name="<?php echo $this->get_field_name('sizing'); ?>" class="widefat">
212 <option value='borderless-search--sizing-default'<?php selected( $sizing, 'borderless-search--sizing-default'); ?>><?php _e( 'Default', 'borderless' ); ?></option>
213 <option value='borderless-search--sizing-sm'<?php selected( $sizing, 'borderless-search--sizing-sm'); ?>><?php _e( 'Small', 'borderless' ); ?></option>
214 <option value='borderless-search--sizing-lg'<?php selected( $sizing, 'borderless-search--sizing-lg'); ?>><?php _e( 'Large', 'borderless' ); ?></option>
215 </select>
216 </p>
217 <p>
218 <label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Type:', 'borderless') ?></label>
219 <select id="<?php echo $this->get_field_id('type'); ?>" name="<?php echo $this->get_field_name('type'); ?>" class="widefat">
220 <option value='borderless-btn--contained'<?php selected( $type, 'borderless-btn--contained'); ?>><?php _e( 'Contained', 'borderless' ); ?></option>
221 <option value='borderless-btn--outline'<?php selected( $type, 'borderless-btn--outline'); ?>><?php _e( 'Outline', 'borderless' ); ?></option>
222 </select>
223 </p>
224 <p>
225 <label for="<?php echo $this->get_field_id('shape'); ?>"><?php _e('Shape:', 'borderless') ?></label>
226 <select id="<?php echo $this->get_field_id('shape'); ?>" name="<?php echo $this->get_field_name('shape'); ?>" class="widefat">
227 <option value='borderless-search--rounded'<?php selected( $shape, 'borderless-search--rounded'); ?>><?php _e( 'Rounded', 'borderless' ); ?></option>
228 <option value='borderless-search--round'<?php selected( $shape, 'borderless-search--round'); ?>><?php _e( 'Round', 'borderless' ); ?></option>
229 <option value='borderless-search--square'<?php selected( $shape, 'borderless-search--square'); ?>><?php _e( 'Square', 'borderless' ); ?></option>
230 </select>
231 </p>
232 <?php
233 }
234
235 /**
236 * Sanitize widget form values as they are saved.
237 *
238 * @see WP_Widget::update()
239 *
240 * @param array $new_instance Values just sent to be saved.
241 * @param array $old_instance Previously saved values from database.
242 *
243 * @return array Updated safe values to be saved.
244 */
245 public function update( $new_instance, $old_instance ) {
246 $instance = array();
247 $instance['type'] = ( !empty( $new_instance['type'] ) ) ? strip_tags( $new_instance['type'] ) : '';
248 $instance['button'] = ( !empty( $new_instance['button'] ) ) ? strip_tags( $new_instance['button'] ) : '';
249 $instance['sizing'] = ( !empty( $new_instance['sizing'] ) ) ? strip_tags( $new_instance['sizing'] ) : '';
250 $instance['button_text'] = ( !empty( $new_instance['button_text'] ) ) ? strip_tags( $new_instance['button_text'] ) : '';
251 $instance['button_color'] = ( !empty( $new_instance['button_color'] ) ) ? strip_tags( $new_instance['button_color'] ) : '';
252 $instance['input_color'] = ( !empty( $new_instance['input_color'] ) ) ? strip_tags( $new_instance['input_color'] ) : '';
253 $instance['placeholder_text'] = ( !empty( $new_instance['placeholder_text'] ) ) ? strip_tags( $new_instance['placeholder_text'] ) : '';
254 $instance['shape'] = ( !empty( $new_instance['shape'] ) ) ? strip_tags( $new_instance['shape'] ) : '';
255 $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
256
257 return $instance;
258 }
259
260 } // class Borderless_Widget_Search
261
262 // register Borderless_Widget_Search widget
263 add_action( 'widgets_init', 'register_borderless_search' );
264
265 function register_borderless_search() {
266 register_widget( 'Borderless_Widget_Search' );
267 }