forked from MESH-Research/humcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets.php
175 lines (150 loc) · 4.78 KB
/
widgets.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* HumCore Widgets.
*
* @package HumCORE
* @subpackage Deposits
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Search Facets Widget
*/
class Humcore_Deposits_Search_Facets_Widget extends WP_Widget {
/**
* Constructor method.
*/
function __construct() {
$widget_ops = array(
'description' => __( '(HumCORE) Faceted Search Results', 'humcore_domain' ),
'classname' => 'widget_deposits_search_facets_widget',
);
parent::__construct( false, $name = _x( '(HumCORE) Faceted Search Results', 'widget name', 'humcore_domain' ), $widget_ops );
}
/**
* Display the Faceted Search Results widget.
*
* @see WP_Widget::widget() for description of parameters.
*
* @param array $args Widget arguments.
* @param array $instance Widget settings, as saved by the user.
*/
function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
echo $args['before_title'] .
$title .
$args['after_title']; ?>
<div class="search-facets facet-set" role="navigation"><h5><label for="search-facets"><?php _e( 'Filter results (select all that apply)', 'humcore_domain' ); ?></label></h5>
<?php humcore_search_sidebar_content(); ?>
</div>
<?php
echo $args['after_widget'];
}
/**
* Update the Faceted Search Results widget options.
*
* @param array $new_instance The new instance options.
* @param array $old_instance The old instance options.
* @return array $instance The parsed options to be saved.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
/**
* Output the Faceted Search Results widget options form.
*
* @param $instance Settings for this widget.
*/
function form( $instance ) {
$defaults = array(
'title' => __( 'Search Results', 'humcore_domain' ),
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = strip_tags( $instance['title'] );
?>
<p><label for="bp-core-widget-title"><?php _e( 'Title:', 'humcore_domain' ); ?>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" />
</label></p>
<?php
}
}
add_action(
'widgets_init', function() {
register_widget( 'Humcore_Deposits_Search_Facets_Widget' );
}
);
/**
* Directory Sidebar Widget
*/
class Humcore_Deposits_Directory_Sidebar_Widget extends WP_Widget {
/**
* Constructor method.
*/
function __construct() {
$widget_ops = array(
'description' => __( '(HumCORE) Deposits Directory Sidebar', 'humcore_domain' ),
'classname' => 'widget_deposits_directory_sidebar_widget',
);
parent::__construct( false, $name = _x( '(HumCORE) Deposits Directory Sidebar', 'widget name', 'humcore_domain' ), $widget_ops );
}
/**
* Display the Faceted Search Results widget.
*
* @see WP_Widget::widget() for description of parameters.
*
* @param array $args Widget arguments.
* @param array $instance Widget settings, as saved by the user.
*/
function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
echo $args['before_title'] .
$title .
$args['after_title'];
?>
<div class="directory-facets facet-set" role="navigation">
<?php humcore_directory_sidebar_content(); ?>
</div>
<?php
echo $args['after_widget'];
}
/**
* Update the Faceted Search Results widget options.
*
* @param array $new_instance The new instance options.
* @param array $old_instance The old instance options.
* @return array $instance The parsed options to be saved.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
/**
* Output the Faceted Search Results widget options form.
*
* @param $instance Settings for this widget.
*/
function form( $instance ) {
$defaults = array(
'title' => __( 'Deposits Directory Sidebar', 'humcore_domain' ),
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = strip_tags( $instance['title'] );
?>
<p><label for="bp-core-widget-title"><?php _e( 'Title:', 'humcore_domain' ); ?>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" />
</label></p>
<?php
}
}
add_action(
'widgets_init', function() {
register_widget( 'Humcore_Deposits_Directory_Sidebar_Widget' );
}
);