class-my-calendar-simple-search.php
3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* My Calendar Simple Search Widget
*
* @category Widgets
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* My Calendar Simple Search class.
*
* @category Widgets
* @package My Calendar
* @author Joe Dolson
* @copyright 2009
* @license GPLv2 or later
* @version 1.0
*/
class My_Calendar_Simple_Search extends WP_Widget {
/**
* Contructor.
*/
function __construct() {
parent::__construct(
false,
$name = __( 'My Calendar: Simple Event Search', 'my-calendar' ),
array(
'customize_selective_refresh' => true,
'description' => __( 'Search your events.', 'my-calendar' ),
)
);
}
/**
* Build the My Calendar Event Search widget output.
*
* @param array $args Widget arguments.
* @param array $instance This instance settings.
*/
function widget( $args, $instance ) {
$before_widget = $args['before_widget'];
$after_widget = $args['after_widget'];
$before_title = str_replace( 'h1', 'h2', $args['before_title'] );
$after_title = str_replace( 'h1', 'h2', $args['after_title'] );
$widget_title = apply_filters( 'widget_title', $instance['title'], $instance, $args );
$widget_title = ( '' !== $widget_title ) ? $before_title . $widget_title . $after_title : '';
$widget_url = ( isset( $instance['url'] ) ) ? $instance['url'] : false;
echo wp_kses( $before_widget . $widget_title . my_calendar_searchform( 'simple', $widget_url ) . $after_widget, mc_kses_elements() );
}
/**
* Edit the search widget.
*
* @param array $instance Current widget settings.
*/
function form( $instance ) {
$widget_title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
$widget_url = ( isset( $instance['url'] ) ) ? $instance['url'] : '';
?>
<div class="my-calendar-widget-wrapper my-calendar-search-widget">
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'my-calendar' ); ?>:</label><br/>
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $widget_title ); ?>"/>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Search Results Page', 'my-calendar' ); ?>:</label><br/>
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'url' ); ?>" name="<?php echo $this->get_field_name( 'url' ); ?>" value="<?php echo esc_url( $widget_url ); ?>"/>
</p>
</div>
<?php
}
/**
* Update the My Calendar Search Widget settings.
*
* @param array $new Widget settings new data.
* @param array $instance Widget settings instance.
*
* @return array $instance Updated instance.
*/
function update( $new, $instance ) {
$instance['title'] = mc_kses_post( $new['title'] );
$instance['url'] = esc_url_raw( $new['url'] );
return $instance;
}
}