1: <?php
2: if ( ! defined( 'ABSPATH' ) ) exit;
3:
4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class WooThemes_Sensei_Course_Categories_Widget extends WP_Widget {
16: protected $woo_widget_cssclass;
17: protected $woo_widget_description;
18: protected $woo_widget_idbase;
19: protected $woo_widget_title;
20:
21: 22: 23: 24: 25:
26: public function __construct() {
27:
28: $this->woo_widget_cssclass = 'widget_sensei_course_categories';
29: $this->woo_widget_description = __( 'This widget will output a list of Course Categories.', 'woothemes-sensei' );
30: $this->woo_widget_idbase = 'sensei_course_categories';
31: $this->woo_widget_title = __( 'Sensei - Course Categories', 'woothemes-sensei' );
32:
33:
34: $widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
35:
36:
37: $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
38:
39:
40: parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
41: }
42:
43: 44: 45: 46: 47: 48: 49:
50: public function widget( $args, $instance ) {
51:
52: $before_widget = $args[ 'before_widget' ];
53: $before_title = $args[ 'before_title' ];
54: $after_title = $args[ 'after_title' ];
55: $after_widget = $args[ 'after_widget' ];
56:
57:
58: $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
59:
60:
61: echo $before_widget;
62:
63:
64: if ( $title ) { echo $before_title . $title . $after_title; }
65:
66:
67:
68: do_action( $this->woo_widget_cssclass . '_top' );
69:
70: $this->load_component( $instance );
71:
72:
73: do_action( $this->woo_widget_cssclass . '_bottom' );
74:
75:
76: echo $after_widget;
77:
78: }
79:
80: 81: 82: 83: 84: 85: 86:
87: public function update ( $new_instance, $old_instance ) {
88: $instance = $old_instance;
89:
90:
91: $instance['title'] = strip_tags( $new_instance['title'] );
92:
93:
94: $instance['limit'] = esc_attr( $new_instance['limit'] );
95:
96:
97: $instance['count'] = $new_instance['count'];
98: $instance['hierarchical'] = $new_instance['hierarchical'];
99:
100: return $instance;
101: }
102:
103: 104: 105: 106: 107: 108: 109:
110: public function form( $instance ) {
111:
112:
113:
114: $defaults = array(
115: 'title' => '',
116: 'limit' => 3,
117: 'count' => false,
118: 'hierarchical' => false
119: );
120:
121: $instance = wp_parse_args( (array) $instance, $defaults );
122: ?>
123: <!-- Widget Title: Text Input -->
124: <p>
125: <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
126: <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
127: </p>
128: <!-- Widget Limit: Text Input -->
129: <p>
130: <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Categories (optional):', 'woothemes-sensei' ); ?></label>
131: <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
132: </p>
133: <!-- Widget Show Count: Checkbox Input -->
134: <p>
135: <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id('count') ); ?>" name="<?php echo esc_attr( $this->get_field_name('count') ); ?>"<?php checked( $instance['count'], 'on' ); ?> />
136: <label for="<?php echo esc_attr( $this->get_field_id('count') ); ?>"><?php _e( 'Show post counts', 'woothemes-sensei' ); ?></label><br />
137: </p>
138: <!-- Widget Show Hierarchy: Checkbox Input -->
139: <p>
140: <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id('hierarchical') ); ?>" name="<?php echo esc_attr( $this->get_field_name('hierarchical') ); ?>"<?php checked( $instance['hierarchical'], 'on' ); ?> />
141: <label for="<?php echo esc_attr( $this->get_field_id('hierarchical') ); ?>"><?php _e( 'Show hierarchy', 'woothemes-sensei' ); ?></label></p>
142: </p>
143: <?php
144: }
145:
146: 147: 148: 149: 150: 151:
152: protected function load_component ( $instance ) {
153:
154: $limit = intval( $instance['limit'] );
155: $count = isset($instance['count']) ? (bool) $instance['count'] :false;
156: $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
157:
158: $cat_args = array( 'title_li' => '', 'taxonomy' => 'course-category', 'orderby' => 'name', 'show_count' => $count, 'hierarchical' => $hierarchical);
159: if ( 0 < $limit ) {
160: $cat_args[ 'number' ] = $limit;
161: }
162: echo '<ul>';
163: wp_list_categories( apply_filters('widget_course_categories_args', $cat_args) );
164: echo '</ul>';
165: }
166: }