Advanced Sidebar Menu - Version 5.0.7

Version Description

Download this release

Release Info

Developer Mat Lipe
Plugin Icon 128x128 Advanced Sidebar Menu
Version 5.0.7
Comparing to
See all releases

Code changes from version 5.0.6 to 5.0.7

advanced-sidebar-menu.php CHANGED
@@ -4,11 +4,11 @@ Plugin Name: Advanced Sidebar Menu
4
  Plugin URI: http://matlipe.com/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
- Version: 5.0.6
8
  Author URI: http://matlipe.com
9
  */
10
 
11
- define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.0.6' );
12
 
13
 
14
  #-- Define Constants
4
  Plugin URI: http://matlipe.com/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
+ Version: 5.0.7
8
  Author URI: http://matlipe.com
9
  */
10
 
11
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.0.7' );
12
 
13
 
14
  #-- Define Constants
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypa
5
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
6
  Requires at least: 3.8.0
7
  Tested up to: 4.2.2
8
- Stable tag: 5.0.6
9
 
10
  Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
11
 
5
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
6
  Requires at least: 3.8.0
7
  Tested up to: 4.2.2
8
+ Stable tag: 5.0.7
9
 
10
  Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
11
 
widgets/category.widget.php CHANGED
@@ -1,341 +1,359 @@
1
- <?php
2
-
3
-
4
- /**
5
- * Creates a Widget of parent Child Categories
6
- *
7
- * @author mat lipe
8
- * @since 1.7.14
9
- * @package Advanced Sidebar Menu
10
- *
11
- * @todo Clean this bad boy up. Still rookie code from years ago
12
- *
13
- *
14
- */
15
  class advanced_sidebar_menu_category extends WP_Widget {
16
-
17
- private $defaults = array(
18
- 'title' => false,
19
- 'include_parent' => false,
20
- 'include_childless_parent' => false,
21
- 'single' => false,
22
- 'css' => false,
23
- 'exclude' => false,
24
- 'new_widget' => 'list',
25
- 'legacy_mode' => false,
26
- 'display_all' => false,
27
- 'levels' => 1
28
- );
29
-
30
-
31
- #-------------------------------------------------------------------------------------------------------------------------
32
-
33
- /**
34
- * Build the widget like a Baller
35
- *
36
- * @since 8.1.13
37
- */
38
- function __construct() {
39
- /* Widget settings. */
40
- $widget_ops = array( 'classname' => 'advanced-sidebar-menu advanced-sidebar-category', 'description' => 'Creates a menu of all the Categories using the child/parent relationship' );
41
- $control_ops = array( 'width' => 290 );
42
- /* Create the widget. */
43
- $this->WP_Widget( 'advanced_sidebar_menu_category', 'Advanced Sidebar Categories Menu', $widget_ops, $control_ops );
44
- }
45
-
46
-
47
-
48
-
49
- /**
50
- * Creates a form for the Widget Options
51
- *
52
- * @since 1.7.14
53
- *
54
- * @param array $instance
55
- *
56
- * @actions do_action('advanced_sidebar_menu_category_widget_form', $instance );
57
- */
58
- function form( $instance ) {
59
-
60
- $instance = wp_parse_args($instance, $this->defaults);
61
-
62
- ?>
63
- <p> <?php _e('Title','advanced-sidebar-menu'); ?> <br>
64
- <input id="<?php echo $this->get_field_name('title'); ?>"
65
- name="<?php echo $this->get_field_name('title'); ?>" class="widefat" type="text" value="<?php echo $instance['title']; ?>"/></p>
66
-
67
-
68
- <p> <?php _e( 'Include Parent Category','advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('include_parent'); ?>"
69
- name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
70
- <?php echo $instance['include_parent']; ?>/></p>
71
-
72
-
73
- <p> <?php _e( 'Include Parent Even With No Children','advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
74
- name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
75
- <?php echo $instance['include_childless_parent']; ?>/></p>
76
-
77
- <p> <?php _e('Use this plugins styling','advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('css'); ?>"
78
- name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
79
- <?php echo $instance['css']; ?>/></p>
80
-
81
- <p> <?php _e( 'Display Categories on Single Posts','advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('single'); ?>"
82
- name="<?php echo $this->get_field_name('single'); ?>" type="checkbox" value="checked"
83
- onclick="javascript:asm_reveal_element( 'new-widget-<?php echo $this->get_field_name('new_widget'); ?>' )"
84
- <?php echo $instance['single']; ?>/></p>
85
-
86
- <span id="new-widget-<?php echo $this->get_field_name('new_widget'); ?>" style="<?php
87
- if( $instance['single'] == 'checked' ){
88
- echo 'display:block';
89
- } else {
90
- echo 'display:none';
91
- } ?>">
92
- <p><?php _e("Display Each Single Post's Category",'advanced-sidebar-menu'); ?>
93
- <select id="<?php echo $this->get_field_name('new_widget'); ?>"
94
- name="<?php echo $this->get_field_name('new_widget'); ?>">
95
- <?php
96
- if( $instance['new_widget'] == 'widget' ){
97
- echo '<option value="widget" selected> In a new widget </option>';
98
- echo '<option value="list"> In another list in the same widget </option>';
99
- } else {
100
- echo '<option value="widget"> In a new widget </option>';
101
- echo '<option value="list" selected> In another list in the same widget </option>';
102
- }
103
-
104
- ?></select>
 
 
 
 
 
 
 
 
 
 
 
105
  </p>
106
  </span>
107
-
108
-
109
-
110
- <p> <?php _e( "Categories to Exclude, Comma Separated", 'advanced-sidebar-menu'); ?>:<input id="<?php echo $this->get_field_name('exclude'); ?>"
111
- name="<?php echo $this->get_field_name('exclude'); ?>" type="text" class="widefat" value="<?php echo $instance['exclude']; ?>"/></p>
112
-
113
-
114
- <p> <?php _e( "Legacy Mode: (use pre 4.0 structure and css)",'advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('legacy_mode'); ?>"
115
- name="<?php echo $this->get_field_name('legacy_mode'); ?>" type="checkbox" value="checked"
116
- <?php echo $instance['legacy_mode']; ?>/>
117
- </p>
118
-
119
-
120
- <p> <?php _e("Always Display Child Categories",'advanced-sidebar-menu'); ?> <input id="<?php echo $this->get_field_name('display_all'); ?>"
121
- name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
122
- onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_name('levels'); ?>' )"
123
- <?php echo $instance['display_all']; ?>/></p>
124
-
125
- <span id="levels-<?php echo $this->get_field_name('levels'); ?>" style="<?php
126
- if( $instance['display_all'] == 'checked' ){
127
- echo 'display:block';
128
- } else {
129
- echo 'display:none';
130
- } ?>">
131
- <p> <?php _e( "Levels to Display",'advanced-sidebar-menu'); ?> <select id="<?php echo $this->get_field_name('levels'); ?>"
132
- name="<?php echo $this->get_field_name('levels'); ?>">
133
- <?php
134
- for( $i= 1; $i<6; $i++ ){
135
- if( $i == $instance['levels'] ){
136
- echo '<option value="'.$i.'" selected>'.$i.'</option>';
137
- } else {
138
- echo '<option value="'.$i.'">'.$i.'</option>';
139
- }
140
- }
141
- echo '</select></p></span>';
142
-
143
-
144
- do_action('advanced_sidebar_menu_category_widget_form', $instance, $this );
145
-
146
- do_action('advanced_sidebar_menu_after_widget_form', $instance, $this );
147
-
148
- }
149
-
150
-
151
- /**
152
- * Updates the widget data
153
- *
154
- * @filter - $newInstance = apply_filters('advanced_sidebar_menu_category_widget_update', $newInstance, $oldInstance );
155
- * @since 5.19.13
156
- */
157
- function update( $newInstance, $oldInstance ) {
158
- $newInstance['exclude'] = strip_tags($new_instance['exclude']);
159
- $newInstance = apply_filters('advanced_sidebar_menu_category_widget_update', $newInstance, $oldInstance );
160
-
161
- return $newInstance;
162
- }
163
-
164
-
165
-
166
-
167
- #---------------------------------------------------------------------------------------------------------------------------
168
-
169
- /**
170
- * Outputs the categories widget to the page
171
- *
172
- * @since 11.15.13
173
- * @uses loads the views/category_list.php
174
- *
175
- * @filters apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
176
- * apply_filters('advanced_sidebar_menu_taxonomy', 'post', $args, $instance );
177
- * apply_filters('advanced_sidebar_menu_proper_single', $asm->checked('single'), $args, $instance)
178
- * apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance )
179
- *
180
- */
181
- function widget($args, $instance) {
182
-
183
- $defaults = array(
184
- 'title' => '',
185
- 'include_parent' => false,
186
- 'include_childless_parent' => false,
187
- 'css' => false,
188
- 'single' => false,
189
- 'new_widget' => 'widget',
190
- 'exclude' => '',
191
- 'legacy_mode' => false,
192
- 'display_all' => false,
193
- 'levels' => 1,
194
- 'order' => 'DESC'
195
- );
196
-
197
- $instance = wp_parse_args( $instance, $defaults);
198
-
199
-
200
-
201
- if( is_single() && !isset( $instance['single'] ) ) return;
202
- $asm = new advancedSidebarMenu;
203
- $asm->instance = $instance;
204
- $asm->args = $args;
205
-
206
- //Had to display twice for backward compat - because originaly not set to anything
207
- $asm->order_by = apply_filters('advanced_sidebar_menu_category_orderby', null, $args, $instance );
208
-
209
- do_action( 'advanced_sidebar_menu_widget_pre_render', $asm, $this );
210
-
211
- $legacy = $asm->checked('legacy_mode');
212
-
213
- $cat_ids = $already_top = array();
214
- $asm_once = false; //keeps track of how many widgets this created
215
-
216
-
217
- $exclude = explode(',', $instance['exclude']);
218
- $asm->exclude = $exclude;
219
-
220
- $asm->taxonomy = apply_filters('advanced_sidebar_menu_taxonomy', 'category', $args, $instance );
221
-
222
- extract( $args);
223
-
224
- //If on a single page create an array of each category and create a list for each
225
- if( is_single() ){
226
- if( !apply_filters('advanced_sidebar_menu_proper_single', $asm->checked('single'), $args, $instance) ) return;
227
- global $post;
228
- $category_array = wp_get_object_terms($post->ID, $asm->taxonomy);
229
-
230
- //Sort by a field like term order for other plugins
231
- $asm->order_by = apply_filters('advanced_sidebar_menu_category_orderby', 'name', $args, $instance );
232
-
233
- uasort( $category_array, array( $asm, 'sortTerms'));
234
-
235
- foreach( $category_array as $id => $cat ){
236
- $cat_ids[] = $cat->term_id;
237
- }
238
-
239
- //IF on a category page get the id of the category
240
- } elseif( is_tax() || is_category() ){
241
-
242
- $asm->current_term = get_queried_object()->term_id;
243
- $cat_ids[] = get_queried_object()->term_id;
244
- }
245
-
246
-
247
-
248
- $cat_ids = apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance );
249
-
250
- if( empty( $cat_ids ) ) return;
251
-
252
- //Go through each category there will be only one if this is a category page mulitple possible if this is single
253
- foreach( $cat_ids as $cat_id ){
254
-
255
- //Get the top category id
256
- $asm->top_id = $asm->getTopCat($cat_id);
257
-
258
- //Keeps track or already used top levels so this won't double up
259
- if( in_array( $asm->top_id, $already_top ) ) continue;
260
-
261
- $already_top[] = $asm->top_id;
262
-
263
- //Check for children
264
- $all_categories = $all = array_filter(
265
- get_terms(
266
- $asm->taxonomy, array(
267
- 'child_of' => $asm->top_id,
268
- 'orderby' => $asm->order_by,
269
- 'order' => $instance['order']
270
- )
271
- )
272
- );
273
-
274
- //For Backwards Compatibility
275
- foreach( $all_categories as $tc ){
276
- $tc->cat_ID = $tc->term_id;
277
- }
278
-
279
-
280
-
281
- //If there are no children and not displaying childless parent - bail
282
- if( empty($all_categories ) && !( $asm->checked('include_childless_parent') ) ) continue;
283
- //If there are no children and the parent is excluded bail
284
- if( empty($all_categories ) && in_array($asm->top_id, $exclude) ) continue;
285
-
286
-
287
- //Creates a new widget for each category the single page has if the options are selected to do so
288
- //Also starts the first widget
289
- if( !$asm_once || ($instance['new_widget'] == 'widget') ){
290
-
291
- //Start the menu
292
- echo $before_widget;
293
- if( !$asm_once ) {
294
- $asm->title();
295
- if( $asm->checked('css') ){
296
- echo '<style type="text/css">';
297
- include( $asm->file_hyercy('sidebar-menu.css', $legacy ) );
298
- echo '</style>';
299
- }
300
-
301
- $asm_once = true; //There has been a div
302
- $close = true; //The div should be closed at the end
303
-
304
- if($instance['new_widget'] == 'list'){
305
- $close = false; //If this is a list leave it open for now
306
- }
307
- }
308
- }
309
-
310
- //for deprecation
311
- $top_cat = $asm->top_id;
312
- $cat_ancestors = $asm->ancestors;
313
-
314
- //Bring in the view
315
- require( $asm->file_hyercy( 'category_list.php', $legacy ) );
316
-
317
- echo apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
318
-
319
- if( $close ){
320
- //End the Widget Area
321
- echo $after_widget;
322
- echo '<!-- First $after_widget -->';
323
- }
324
-
325
-
326
- } //End of each cat loop
327
-
328
-
329
- //IF we were waiting for all the individual lists to complete
330
- if( !$close && $asm_once ){
331
- //End the Widget Area
332
- echo $after_widget;
333
- echo '<!-- Second $after_widget -->';
334
-
335
- }
336
-
337
-
338
-
339
- } #== /widget()
340
-
 
 
 
 
 
 
 
341
  } #== /Clas
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Creates a Widget of parent Child Categories
6
+ *
7
+ * @author mat lipe
8
+ * @since 1.7.14
9
+ * @package Advanced Sidebar Menu
10
+ *
11
+ * @todo Clean this bad boy up. Still rookie code from years ago
12
+ *
13
+ *
14
+ */
15
  class advanced_sidebar_menu_category extends WP_Widget {
16
+
17
+ private $defaults = array(
18
+ 'title' => false,
19
+ 'include_parent' => false,
20
+ 'include_childless_parent' => false,
21
+ 'single' => false,
22
+ 'css' => false,
23
+ 'exclude' => false,
24
+ 'new_widget' => 'list',
25
+ 'legacy_mode' => false,
26
+ 'display_all' => false,
27
+ 'levels' => 1
28
+ );
29
+
30
+
31
+ #-------------------------------------------------------------------------------------------------------------------------
32
+
33
+ /**
34
+ * Build the widget like a Baller
35
+ *
36
+ * @since 8.1.13
37
+ */
38
+ function __construct(){
39
+ /* Widget settings. */
40
+ $widget_ops = array(
41
+ 'classname' => 'advanced-sidebar-menu advanced-sidebar-category',
42
+ 'description' => 'Creates a menu of all the Categories using the child/parent relationship'
43
+ );
44
+ $control_ops = array( 'width' => 290 );
45
+ /* Create the widget. */
46
+ $this->WP_Widget( 'advanced_sidebar_menu_category', 'Advanced Sidebar Categories Menu', $widget_ops, $control_ops );
47
+ }
48
+
49
+
50
+ /**
51
+ * Creates a form for the Widget Options
52
+ *
53
+ * @since 1.7.14
54
+ *
55
+ * @param array $instance
56
+ *
57
+ * @actions do_action('advanced_sidebar_menu_category_widget_form', $instance );
58
+ */
59
+ function form( $instance ){
60
+
61
+ $instance = wp_parse_args( $instance, $this->defaults );
62
+
63
+ ?>
64
+ <p> <?php _e( 'Title', 'advanced-sidebar-menu' ); ?>
65
+ <br>
66
+ <input id="<?php echo $this->get_field_name( 'title' ); ?>"
67
+ name="<?php echo $this->get_field_name( 'title' ); ?>" class="widefat" type="text" value="<?php echo $instance[ 'title' ]; ?>"/>
68
+ </p>
69
+
70
+
71
+ <p> <?php _e( 'Include Parent Category', 'advanced-sidebar-menu' ); ?>
72
+ <input id="<?php echo $this->get_field_name( 'include_parent' ); ?>"
73
+ name="<?php echo $this->get_field_name( 'include_parent' ); ?>" type="checkbox" value="checked"
74
+ <?php echo $instance[ 'include_parent' ]; ?>/>
75
+ </p>
76
+
77
+
78
+ <p> <?php _e( 'Include Parent Even With No Children', 'advanced-sidebar-menu' ); ?>
79
+ <input id="<?php echo $this->get_field_name( 'include_childless_parent' ); ?>"
80
+ name="<?php echo $this->get_field_name( 'include_childless_parent' ); ?>" type="checkbox" value="checked"
81
+ <?php echo $instance[ 'include_childless_parent' ]; ?>/>
82
+ </p>
83
+
84
+ <p> <?php _e( 'Use this plugins styling', 'advanced-sidebar-menu' ); ?>
85
+ <input id="<?php echo $this->get_field_name( 'css' ); ?>"
86
+ name="<?php echo $this->get_field_name( 'css' ); ?>" type="checkbox" value="checked"
87
+ <?php echo $instance[ 'css' ]; ?>/>
88
+ </p>
89
+
90
+ <p> <?php _e( 'Display Categories on Single Posts', 'advanced-sidebar-menu' ); ?>
91
+ <input id="<?php echo $this->get_field_name( 'single' ); ?>"
92
+ name="<?php echo $this->get_field_name( 'single' ); ?>" type="checkbox" value="checked"
93
+ onclick="javascript:asm_reveal_element( 'new-widget-<?php echo $this->get_field_name( 'new_widget' ); ?>' )"
94
+ <?php echo $instance[ 'single' ]; ?>/>
95
+ </p>
96
+
97
+ <span id="new-widget-<?php echo $this->get_field_name( 'new_widget' ); ?>" style="<?php
98
+ if( $instance[ 'single' ] == 'checked' ){
99
+ echo 'display:block';
100
+ } else {
101
+ echo 'display:none';
102
+ } ?>">
103
+ <p><?php _e( "Display Each Single Post's Category", 'advanced-sidebar-menu' ); ?>
104
+ <select id="<?php echo $this->get_field_name( 'new_widget' ); ?>"
105
+ name="<?php echo $this->get_field_name( 'new_widget' ); ?>">
106
+ <?php
107
+ if( $instance[ 'new_widget' ] == 'widget' ){
108
+ echo '<option value="widget" selected> In a new widget </option>';
109
+ echo '<option value="list"> In another list in the same widget </option>';
110
+ } else {
111
+ echo '<option value="widget"> In a new widget </option>';
112
+ echo '<option value="list" selected> In another list in the same widget </option>';
113
+ }
114
+
115
+ ?></select>
116
  </p>
117
  </span>
118
+
119
+
120
+
121
+ <p> <?php _e( "Categories to Exclude, Comma Separated", 'advanced-sidebar-menu' ); ?>:
122
+ <input id="<?php echo $this->get_field_name( 'exclude' ); ?>"
123
+ name="<?php echo $this->get_field_name( 'exclude' ); ?>" type="text" class="widefat" value="<?php echo $instance[ 'exclude' ]; ?>"/>
124
+ </p>
125
+
126
+
127
+ <p> <?php _e( "Legacy Mode: (use pre 4.0 structure and css)", 'advanced-sidebar-menu' ); ?>
128
+ <input id="<?php echo $this->get_field_name( 'legacy_mode' ); ?>"
129
+ name="<?php echo $this->get_field_name( 'legacy_mode' ); ?>" type="checkbox" value="checked"
130
+ <?php echo $instance[ 'legacy_mode' ]; ?>/>
131
+ </p>
132
+
133
+
134
+ <p> <?php _e( "Always Display Child Categories", 'advanced-sidebar-menu' ); ?>
135
+ <input id="<?php echo $this->get_field_name( 'display_all' ); ?>"
136
+ name="<?php echo $this->get_field_name( 'display_all' ); ?>" type="checkbox" value="checked"
137
+ onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_name( 'levels' ); ?>' )"
138
+ <?php echo $instance[ 'display_all' ]; ?>/>
139
+ </p>
140
+
141
+ <span id="levels-<?php echo $this->get_field_name( 'levels' ); ?>" style="<?php
142
+ if( $instance[ 'display_all' ] == 'checked' ){
143
+ echo 'display:block';
144
+ } else {
145
+ echo 'display:none';
146
+ } ?>">
147
+ <p> <?php _e( "Levels to Display", 'advanced-sidebar-menu' ); ?>
148
+ <select id="<?php echo $this->get_field_name( 'levels' ); ?>"
149
+ name="<?php echo $this->get_field_name( 'levels' ); ?>">
150
+ <?php
151
+ for( $i = 1; $i < 6; $i ++ ){
152
+ if( $i == $instance[ 'levels' ] ){
153
+ echo '<option value="' . $i . '" selected>' . $i . '</option>';
154
+ } else {
155
+ echo '<option value="' . $i . '">' . $i . '</option>';
156
+ }
157
+ }
158
+ echo '</select></p></span>';
159
+
160
+ do_action( 'advanced_sidebar_menu_category_widget_form', $instance, $this );
161
+
162
+ do_action( 'advanced_sidebar_menu_after_widget_form', $instance, $this );
163
+
164
+ }
165
+
166
+
167
+ /**
168
+ * Updates the widget data
169
+ *
170
+ * @filter - $newInstance = apply_filters('advanced_sidebar_menu_category_widget_update', $newInstance, $oldInstance );
171
+ * @since 5.19.13
172
+ */
173
+ function update( $newInstance, $oldInstance ){
174
+ $newInstance[ 'exclude' ] = strip_tags( $newInstance[ 'exclude' ] );
175
+ $newInstance = apply_filters( 'advanced_sidebar_menu_category_widget_update', $newInstance, $oldInstance );
176
+
177
+ return $newInstance;
178
+ }
179
+
180
+
181
+
182
+
183
+ #---------------------------------------------------------------------------------------------------------------------------
184
+
185
+ /**
186
+ * Outputs the categories widget to the page
187
+ *
188
+ * @since 11.15.13
189
+ * @uses loads the views/category_list.php
190
+ *
191
+ * @filters apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
192
+ * apply_filters('advanced_sidebar_menu_taxonomy', 'post', $args, $instance );
193
+ * apply_filters('advanced_sidebar_menu_proper_single', $asm->checked('single'), $args, $instance)
194
+ * apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance )
195
+ *
196
+ */
197
+ function widget( $args, $instance ){
198
+
199
+ $defaults = array(
200
+ 'title' => '',
201
+ 'include_parent' => false,
202
+ 'include_childless_parent' => false,
203
+ 'css' => false,
204
+ 'single' => false,
205
+ 'new_widget' => 'widget',
206
+ 'exclude' => '',
207
+ 'legacy_mode' => false,
208
+ 'display_all' => false,
209
+ 'levels' => 1,
210
+ 'order' => 'DESC'
211
+ );
212
+
213
+ $instance = wp_parse_args( $instance, $defaults );
214
+
215
+ if( is_single() && !isset( $instance[ 'single' ] ) ){
216
+ return;
217
+ }
218
+ $asm = new advancedSidebarMenu;
219
+ $asm->instance = $instance;
220
+ $asm->args = $args;
221
+
222
+ //Had to display twice for backward compat - because originaly not set to anything
223
+ $asm->order_by = apply_filters( 'advanced_sidebar_menu_category_orderby', null, $args, $instance );
224
+
225
+ do_action( 'advanced_sidebar_menu_widget_pre_render', $asm, $this );
226
+
227
+ $legacy = $asm->checked( 'legacy_mode' );
228
+
229
+ $cat_ids = $already_top = array();
230
+ $asm_once = false; //keeps track of how many widgets this created
231
+
232
+ $exclude = explode( ',', $instance[ 'exclude' ] );
233
+ $asm->exclude = $exclude;
234
+
235
+ $asm->taxonomy = apply_filters( 'advanced_sidebar_menu_taxonomy', 'category', $args, $instance );
236
+
237
+ extract( $args );
238
+
239
+ //If on a single page create an array of each category and create a list for each
240
+ if( is_single() ){
241
+ if( !apply_filters( 'advanced_sidebar_menu_proper_single', $asm->checked( 'single' ), $args, $instance ) ){
242
+ return;
243
+ }
244
+ global $post;
245
+ $category_array = wp_get_object_terms( $post->ID, $asm->taxonomy );
246
+
247
+ //Sort by a field like term order for other plugins
248
+ $asm->order_by = apply_filters( 'advanced_sidebar_menu_category_orderby', 'name', $args, $instance );
249
+
250
+ uasort( $category_array, array( $asm, 'sortTerms' ) );
251
+
252
+ foreach( $category_array as $id => $cat ){
253
+ $cat_ids[ ] = $cat->term_id;
254
+ }
255
+
256
+ //IF on a category page get the id of the category
257
+ } elseif( is_tax() || is_category() ) {
258
+
259
+ $asm->current_term = get_queried_object()->term_id;
260
+ $cat_ids[ ] = get_queried_object()->term_id;
261
+ }
262
+
263
+ $cat_ids = apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance );
264
+
265
+ if( empty( $cat_ids ) ){
266
+ return;
267
+ }
268
+
269
+ //Go through each category there will be only one if this is a category page mulitple possible if this is single
270
+ foreach( $cat_ids as $cat_id ){
271
+
272
+ //Get the top category id
273
+ $asm->top_id = $asm->getTopCat( $cat_id );
274
+
275
+ //Keeps track or already used top levels so this won't double up
276
+ if( in_array( $asm->top_id, $already_top ) ){
277
+ continue;
278
+ }
279
+
280
+ $already_top[ ] = $asm->top_id;
281
+
282
+ //Check for children
283
+ $all_categories = $all = array_filter(
284
+ get_terms(
285
+ $asm->taxonomy, array(
286
+ 'child_of' => $asm->top_id,
287
+ 'orderby' => $asm->order_by,
288
+ 'order' => $instance[ 'order' ]
289
+ )
290
+ )
291
+ );
292
+
293
+ //For Backwards Compatibility
294
+ foreach( $all_categories as $tc ){
295
+ $tc->cat_ID = $tc->term_id;
296
+ }
297
+
298
+ //If there are no children and not displaying childless parent - bail
299
+ if( empty( $all_categories ) && !( $asm->checked( 'include_childless_parent' ) ) ){
300
+ continue;
301
+ }
302
+ //If there are no children and the parent is excluded bail
303
+ if( empty( $all_categories ) && in_array( $asm->top_id, $exclude ) ){
304
+ continue;
305
+ }
306
+
307
+ //Creates a new widget for each category the single page has if the options are selected to do so
308
+ //Also starts the first widget
309
+ if( !$asm_once || ( $instance[ 'new_widget' ] == 'widget' ) ){
310
+
311
+ //Start the menu
312
+ echo $before_widget;
313
+ if( !$asm_once ){
314
+ $asm->title();
315
+ if( $asm->checked( 'css' ) ){
316
+ echo '<style type="text/css">';
317
+ include( $asm->file_hyercy( 'sidebar-menu.css', $legacy ) );
318
+ echo '</style>';
319
+ }
320
+
321
+ $asm_once = true; //There has been a div
322
+ $close = true; //The div should be closed at the end
323
+
324
+ if( $instance[ 'new_widget' ] == 'list' ){
325
+ $close = false; //If this is a list leave it open for now
326
+ }
327
+ }
328
+ }
329
+
330
+ //for deprecation
331
+ $top_cat = $asm->top_id;
332
+ $cat_ancestors = $asm->ancestors;
333
+
334
+ //Bring in the view
335
+ require( $asm->file_hyercy( 'category_list.php', $legacy ) );
336
+
337
+ echo apply_filters( 'advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
338
+
339
+ if( $close ){
340
+ //End the Widget Area
341
+ echo $after_widget;
342
+ echo '<!-- First $after_widget -->';
343
+ }
344
+
345
+
346
+ } //End of each cat loop
347
+
348
+ //IF we were waiting for all the individual lists to complete
349
+ if( !$close && $asm_once ){
350
+ //End the Widget Area
351
+ echo $after_widget;
352
+ echo '<!-- Second $after_widget -->';
353
+
354
+ }
355
+
356
+
357
+ } #== /widget()
358
+
359
  } #== /Clas