| 1 |
<?php |
| 2 |
/** |
| 3 |
* Event Posts widget |
| 4 |
* |
| 5 |
* @package Themify Event Post |
| 6 |
*/ |
| 7 |
|
| 8 |
class Themify_Event_Posts_Widget extends WP_Widget { |
| 9 |
|
| 10 |
function __construct() { |
| 11 |
/* Widget settings. */ |
| 12 |
$widget_ops = array( 'classname' => 'event-posts', 'description' => __( 'A list of events.', 'themify-event-post' ) ); |
| 13 |
|
| 14 |
/* Widget control settings. */ |
| 15 |
$control_ops = array('id_base' => 'themify-event-post'); |
| 16 |
|
| 17 |
/* Create the widget. */ |
| 18 |
parent::__construct('themify-event-post', __( 'Themify - Event Posts', 'themify-event-post' ), $widget_ops, $control_ops); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Initialize widget |
| 23 |
* |
| 24 |
* @param array $args |
| 25 |
* @param array $instance |
| 26 |
*/ |
| 27 |
function widget( $args, $instance ) { |
| 28 |
echo Themify_Event_Post::get_instance()->get_template( 'widget-posts', array( |
| 29 |
'args' => $args, |
| 30 |
'instance' => $instance, |
| 31 |
'widget' => $this, |
| 32 |
) ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Save widget options |
| 37 |
* |
| 38 |
* @param array $new_instance |
| 39 |
* @param array $old_instance |
| 40 |
* |
| 41 |
* @return array |
| 42 |
*/ |
| 43 |
function update( $new_instance, $old_instance ) { |
| 44 |
$instance = $old_instance; |
| 45 |
|
| 46 |
/* Strip tags (if needed) and update the widget settings. */ |
| 47 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
| 48 |
$instance['category'] = $new_instance['category']; |
| 49 |
$instance['show_count'] = $new_instance['show_count']; |
| 50 |
$instance['show'] = $new_instance['show']; |
| 51 |
|
| 52 |
return $instance; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Render widget form |
| 57 |
* @param array $instance |
| 58 |
* |
| 59 |
* @return string|void |
| 60 |
*/ |
| 61 |
function form( $instance ) { |
| 62 |
|
| 63 |
/* Set up some default widget settings. */ |
| 64 |
$defaults = array( |
| 65 |
'title' => __( 'Events', 'themify-event-post' ), |
| 66 |
'category' => 0, |
| 67 |
'show_count' => 5, |
| 68 |
'show' => 'upcoming', |
| 69 |
); |
| 70 |
$instance = wp_parse_args( (array) $instance, $defaults ); |
| 71 |
$categories = get_categories( array( 'taxonomy' => 'event-category' ) ); |
| 72 |
?> |
| 73 |
|
| 74 |
<p> |
| 75 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'themify-event-post'); ?></label><br /> |
| 76 |
<input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" width="100%" /> |
| 77 |
</p> |
| 78 |
|
| 79 |
<p> |
| 80 |
<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Category:', 'themify-event-post'); |
| 81 |
?></label> |
| 82 |
<select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> |
| 83 |
<option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'themify-event-post'); ?></option> |
| 84 |
<?php |
| 85 |
foreach ( $categories as $cat ) { |
| 86 |
echo '<option value="' . $cat->cat_ID . '"'; |
| 87 |
if ($cat->cat_ID == $instance['category']) |
| 88 |
echo ' selected="selected"'; |
| 89 |
echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')'; |
| 90 |
echo '</option>'; |
| 91 |
} |
| 92 |
?> |
| 93 |
</select> |
| 94 |
</p> |
| 95 |
|
| 96 |
<p> |
| 97 |
<label for="<?php echo $this->get_field_id('show_count'); ?>"><?php _e('Limit:', 'themify-event-post'); ?></label> |
| 98 |
<input id="<?php echo $this->get_field_id('show_count'); ?>" name="<?php echo $this->get_field_name('show_count'); ?>" value="<?php echo $instance['show_count']; ?>" size="2" /> <?php _e('events', 'themify-event-post'); ?> |
| 99 |
</p> |
| 100 |
|
| 101 |
<p> |
| 102 |
<label for="<?php echo $this->get_field_id('show'); ?>"><?php _e('Show:', 'themify-event-post'); ?></label> |
| 103 |
<select id="<?php echo $this->get_field_id('show'); ?>" name="<?php echo $this->get_field_name('show'); ?>"> |
| 104 |
<option value="upcoming" <?php selected( $instance['show'], 'upcoming' ); ?>><?php _e( 'Upcoming Events' ); ?></option> |
| 105 |
<option value="past" <?php selected( $instance['show'], 'past' ); ?>><?php _e( 'Past Events' ); ?></option> |
| 106 |
<option value="mix" <?php selected( $instance['show'], 'mix' ); ?>><?php _e( 'Both' ); ?></option> |
| 107 |
</select> |
| 108 |
</p> |
| 109 |
|
| 110 |
<?php |
| 111 |
} |
| 112 |
|
| 113 |
public static function register() { |
| 114 |
register_widget( 'Themify_Event_Posts_Widget' ); |
| 115 |
} |
| 116 |
} |
| 117 |
add_action( 'widgets_init', array( 'Themify_Event_Posts_Widget', 'register' ) ); |
| 118 |
|
| 119 |
class Themify_Event_Categories_Widget extends WP_Widget { |
| 120 |
|
| 121 |
function __construct() { |
| 122 |
/* Widget settings. */ |
| 123 |
$widget_ops = array( 'classname' => 'event-categories', 'description' => __( 'A list of event categories.', 'themify-event-post' ) ); |
| 124 |
|
| 125 |
/* Widget control settings. */ |
| 126 |
$control_ops = array( 'id_base' => 'themify-event-categories' ); |
| 127 |
|
| 128 |
/* Create the widget. */ |
| 129 |
parent::__construct( 'themify-event-categories', __( 'Themify - Event Categories', 'themify-event-post' ), $widget_ops, $control_ops ); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Initialize widget |
| 134 |
* |
| 135 |
* @param array $args |
| 136 |
* @param array $instance |
| 137 |
*/ |
| 138 |
function widget( $args, $instance ) { |
| 139 |
echo Themify_Event_Post::get_instance()->get_template( 'widget-categories', array( |
| 140 |
'args' => $args, |
| 141 |
'instance' => $instance, |
| 142 |
'widget' => $this, |
| 143 |
) ); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Save widget options |
| 148 |
* |
| 149 |
* @param array $new_instance |
| 150 |
* @param array $old_instance |
| 151 |
* |
| 152 |
* @return array |
| 153 |
*/ |
| 154 |
function update( $new_instance, $old_instance ) { |
| 155 |
$instance = $old_instance; |
| 156 |
|
| 157 |
/* Strip tags (if needed) and update the widget settings. */ |
| 158 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
| 159 |
$instance['parent'] = $new_instance['parent']; |
| 160 |
$instance['depth'] = $new_instance['depth']; |
| 161 |
$instance['orderby'] = $new_instance['orderby']; |
| 162 |
$instance['exclude'] = $new_instance['exclude']; |
| 163 |
$instance['show_dropdown'] = $new_instance['show_dropdown']; |
| 164 |
$instance['show_counts'] = $new_instance['show_counts']; |
| 165 |
$instance['show_hierarchy'] = $new_instance['show_hierarchy']; |
| 166 |
|
| 167 |
return $instance; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Render widget form |
| 172 |
* @param array $instance |
| 173 |
* |
| 174 |
* @return string|void |
| 175 |
*/ |
| 176 |
function form( $instance ) { |
| 177 |
/* Set up some default widget settings. */ |
| 178 |
$defaults = array( |
| 179 |
'title' => __('Categories', 'themify-event-post'), |
| 180 |
'parent' => 0, |
| 181 |
'depth' => 0, |
| 182 |
'orderby' => 'name', |
| 183 |
'exclude' => '', |
| 184 |
'show_dropdown' => false, |
| 185 |
'show_counts' => false, |
| 186 |
'show_hierarchy' => true |
| 187 |
); |
| 188 |
$instance = wp_parse_args( (array) $instance, $defaults ); |
| 189 |
?> |
| 190 |
|
| 191 |
<p> |
| 192 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'themify-event-post'); ?></label><br /> |
| 193 |
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'title' ) ); ?>" value="<?php esc_attr_e( $instance['title'] ); ?>" width="100%" /> |
| 194 |
</p> |
| 195 |
|
| 196 |
<p> |
| 197 |
<label for="<?php echo $this->get_field_id( 'parent' ); ?>"><?php _e('Parent:', 'themify-event-post'); ?></label> |
| 198 |
<?php |
| 199 |
wp_dropdown_categories( array( |
| 200 |
'taxonomy' => 'event-category', |
| 201 |
'show_option_all' => __('All', 'themify-event-post'), |
| 202 |
'orderby' => 'name', |
| 203 |
'hierarchical' => 1, |
| 204 |
'selected' => $instance['parent'], |
| 205 |
'id' => $this->get_field_id( 'parent' ), |
| 206 |
'name' => $this->get_field_name( 'parent' ), |
| 207 |
)); |
| 208 |
?> |
| 209 |
</p> |
| 210 |
|
| 211 |
<p> |
| 212 |
<label for="<?php echo $this->get_field_id( 'depth' ); ?>"><?php _e('Depth:', 'themify-event-post'); ?></label> |
| 213 |
<select id="<?php echo $this->get_field_id( 'depth' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'depth' ) ); ?>"> |
| 214 |
<option value="0" <?php if ( 0 == $instance['depth'] ) echo 'selected="selected"'; ?>><?php _e('0 (default)', 'themify-event-post'); ?></option> |
| 215 |
<option value="1" <?php if ( 1 == $instance['depth'] ) echo 'selected="selected"'; ?>>1</option> |
| 216 |
<option value="2" <?php if ( 2 == $instance['depth'] ) echo 'selected="selected"'; ?>>2</option> |
| 217 |
<option value="3" <?php if ( 3 == $instance['depth'] ) echo 'selected="selected"'; ?>>3</option> |
| 218 |
<option value="4" <?php if ( 4 == $instance['depth'] ) echo 'selected="selected"'; ?>>4</option> |
| 219 |
</select> |
| 220 |
</p> |
| 221 |
|
| 222 |
<p> |
| 223 |
<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e('Orderby:', 'themify-event-post'); ?></label> |
| 224 |
<select id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'orderby' ) ); ?>"> |
| 225 |
<option value="id" <?php if ( 'id' === $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e( 'ID', 'themify-event-post' ); ?></option> |
| 226 |
<option value="name" <?php if ( 'name' === $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e( 'Name', 'themify-event-post' ); ?></option> |
| 227 |
<option value="slug" <?php if ( 'slug' === $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e( 'Slug', 'themify-event-post' ); ?></option> |
| 228 |
<option value="count" <?php if ( 'count' === $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e('Count', 'themify-event-post'); ?></option> |
| 229 |
</select> |
| 230 |
</p> |
| 231 |
|
| 232 |
<p> |
| 233 |
<label for="<?php echo $this->get_field_id( 'exclude' ); ?>"><?php _e('Exclude:', 'themify-event-post'); ?></label><br /> |
| 234 |
<input id="<?php echo $this->get_field_id( 'exclude' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'exclude' ) ); ?>" value="<?php esc_attr_e( $instance['exclude'] ); ?>" /><br /> |
| 235 |
<small><?php _e('Category IDs, separated by commas (eg. 5,8)', 'themify-event-post'); ?></small> |
| 236 |
</p> |
| 237 |
|
| 238 |
<p> |
| 239 |
<input class="checkbox" type="checkbox" <?php checked( $instance['show_dropdown'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_dropdown' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'show_dropdown' ) ); ?>" /> |
| 240 |
<label for="<?php echo $this->get_field_id( 'show_dropdown' ); ?>"><?php _e('Show as dropdown', 'themify-event-post'); ?></label> |
| 241 |
</p> |
| 242 |
|
| 243 |
<p> |
| 244 |
<input class="checkbox" type="checkbox" <?php checked( $instance['show_counts'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_counts' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'show_counts' ) ); ?>" /> |
| 245 |
<label for="<?php echo $this->get_field_id( 'show_counts' ); ?>"><?php _e('Show post counts', 'themify-event-post'); ?></label> |
| 246 |
</p> |
| 247 |
|
| 248 |
<p> |
| 249 |
<input class="checkbox" type="checkbox" <?php checked( $instance['show_hierarchy'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_hierarchy' ); ?>" name="<?php esc_attr_e( $this->get_field_name( 'show_hierarchy' ) ); ?>" /> |
| 250 |
<label for="<?php echo $this->get_field_id( 'show_hierarchy' ); ?>"><?php _e('Show hierarchy', 'themify-event-post'); ?></label> |
| 251 |
</p> |
| 252 |
<?php |
| 253 |
|
| 254 |
} |
| 255 |
|
| 256 |
public static function register() { |
| 257 |
register_widget( 'Themify_Event_Categories_Widget' ); |
| 258 |
} |
| 259 |
} |
| 260 |
add_action( 'widgets_init', array( 'Themify_Event_Categories_Widget', 'register' ) ); |