Advanced Sidebar Menu - Version 7.1.1

Version Description

Download this release

Release Info

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

Code changes from version 7.1.0 to 7.1.1

advanced-sidebar-menu.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Advanced Sidebar Menu
4
  Plugin URI: https://matlipe.com/advanced-sidebar-menu/
5
  Description: Creates dynamic menus based on parent/child relationship of your pages or categories.
6
  Author: Mat Lipe
7
- Version: 7.1.0
8
  Author URI: https://matlipe.com
9
  Text Domain: advanced-sidebar-menu
10
  */
@@ -14,7 +14,7 @@ if ( defined( 'ADVANCED_SIDEBAR_BASIC_VERSION' ) ) {
14
  return;
15
  }
16
 
17
- define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.1.0' );
18
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
19
 
20
  if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
4
  Plugin URI: https://matlipe.com/advanced-sidebar-menu/
5
  Description: Creates dynamic menus based on parent/child relationship of your pages or categories.
6
  Author: Mat Lipe
7
+ Version: 7.1.1
8
  Author URI: https://matlipe.com
9
  Text Domain: advanced-sidebar-menu
10
  */
14
  return;
15
  }
16
 
17
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.1.1' );
18
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
19
 
20
  if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
composer.json CHANGED
@@ -2,7 +2,7 @@
2
  "name": "lipemat/advanced-sidebar-menu",
3
  "description": "Menu widget generator for wordpress",
4
  "type": "wordpress-plugin",
5
- "license": "GPL",
6
  "authors": [
7
  {
8
  "name": "lipemat",
2
  "name": "lipemat/advanced-sidebar-menu",
3
  "description": "Menu widget generator for wordpress",
4
  "type": "wordpress-plugin",
5
+ "license": "MIT",
6
  "authors": [
7
  {
8
  "name": "lipemat",
readme.txt CHANGED
@@ -4,25 +4,36 @@ Contributors: Mat Lipe
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40matlipe%2ecom&lc=US&item_name=Advanced%20Sidebar%20Menu&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
5
  Tags: menus, sidebar menu, hierarchy, category menu, pages menu
6
  Requires at least: 4.6.0
7
- Tested up to: 4.9.1
8
- Stable tag: 7.1.0
 
9
 
10
  == Description ==
11
 
12
- Uses the parent/child relationship of your pages or categories to generate menus based on the current section of your site. Simply assign a page or category to a parent and this will do the rest for you.
13
 
14
- Keeps the menu clean and usable. Only related items display so you don't have to worry about keeping a custom menu up to date or displaying links to items that don't belong.
15
 
16
-
17
- <strong>Check out <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/">Advanced Sidebar Menu Pro</a> for more features including priority support, the ability to customize the look and feel, custom text for your links, excluding of pages, category link ordering, accordions, custom post types, and so much more!</strong>
18
 
19
  <blockquote><a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Pro version 3.0.0</a> just dropped with lots of great new stuff!</blockquote>
20
 
 
 
 
 
 
 
 
 
 
 
 
21
  <h4>Page Widget Options</h4>
22
  * Add a title to the widget
23
- * Include the highest level parent page
24
- * Include the highest level parent page even with no Children
25
- * Order Pages By (date, title, page order)
26
  * Use built in styling (very plain styling, for more advanced styling <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Go Pro!</a>)
27
  * Exclude pages
28
  * Always display child Pages
@@ -30,35 +41,35 @@ Keeps the menu clean and usable. Only related items display so you don't have to
30
 
31
  <h4>Category Widget Options</h4>
32
  * Add a title to the widget
33
- * Include Parent Category
34
- * Include Parent Even with no Children
35
  * Use built in styling (very plain styling, for more advanced styling <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Go Pro!</a>)
36
- * Display Categories on Single Posts
37
- * To display each Single Posts Category in a new widget or in same list
38
- * Exclude Categories
39
  * Always display child categories
40
  * Levels of Categories to display when always display child categories is checked
41
 
42
  <h4>Pro Features</h4>
43
  * Priority support
44
  * Ability to customize each page link’s text
 
 
45
  * Click and drag styling for both the page and category widgets
46
- * Styling options for links including color, background color, size, and font weight
47
  * Styling options for different levels of links
48
  * Styling options for the current page or category
49
  * Styling options for the parent of the current page or category
50
  * Block styling options including borders and border colors
51
  * Bullet style selection from 7 styles or select none to have no bullets
52
- * Current page parent only for the page widget
53
  * Accordion menu support for pages
54
  * Accordion menu support for categories
55
  * Accordion icon selection from 4 styles of icons
56
  * Accordion icon color selection
57
- * Accordion close all sections
58
- * Include parent in accordion
59
  * Ability to exclude a page from all menus using a simple checkbox
60
  * Link ordering for the category widget
61
- * Number of levels of pages to show when always displayed child pages is not checked.
62
  * Ability to select and display custom post types **NEW**
63
  * Ability to select and display custom taxonomies **NEW**
64
 
@@ -86,8 +97,10 @@ Manual Installation
86
 
87
  == Screenshots ==
88
 
89
- 1. Screenshot of the Page widget and options
90
- 2. Screenshot of the Categories widget and options
 
 
91
 
92
 
93
  == Frequently Asked Questions ==
@@ -111,6 +124,7 @@ For Instance This would remove the dot and change the color
111
  }
112
  </code>
113
 
 
114
 
115
  = How do you get the categories to display on single post pages? =
116
 
@@ -119,19 +133,13 @@ There is a checkbox in the widget options that will display the same structure f
119
  = How do you edit the output or built in css? =
120
 
121
  Create a folder in your child theme named "advanced-sidebar-menu" copy any of the files from the "views" folder into
122
- the folder you just created. You may edit the files at will to change the output or css.
123
- You must have the option checked to use the built in CSS (in the widget) to be able to edit the css file in this way.
124
 
125
 
126
  = Does the menu change for each page you are on? =
127
 
128
- Yes. Based on whatever page you are on, the menu will change automatically to display the current parents and children.
129
-
130
- = How does this work with styling the page? =
131
 
132
- This will automatically generate class names for each level for menu system.
133
- You can add classes to your theme's style.css file to style it accordingly.
134
- You may want to use something like margins to set the levels apart.
135
 
136
  == Changelog ==
137
  = 7.1.0 =
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40matlipe%2ecom&lc=US&item_name=Advanced%20Sidebar%20Menu&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
5
  Tags: menus, sidebar menu, hierarchy, category menu, pages menu
6
  Requires at least: 4.6.0
7
+ Tested up to: 4.9.2
8
+ Requires PHP: 5.2.4
9
+ Stable tag: 7.1.1
10
 
11
  == Description ==
12
 
13
+ Uses the parent/child relationship of your pages or categories to generate menus based on the current section of your site. Assign a page or category to a parent and this will do the rest for you.
14
 
15
+ Keeps the menu clean and usable. Only related items display so you don't have to worry about keeping a custom menu up to date or displaying links to items that don't belong.
16
 
17
+ <strong>Check out <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/">Advanced Sidebar Menu Pro</a> for more features including priority support, the ability to customize the look and feel, custom link text, excluding of pages, category ordering, accordions, custom post types, custom taxonomies, and so much more!</strong>
 
18
 
19
  <blockquote><a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Pro version 3.0.0</a> just dropped with lots of great new stuff!</blockquote>
20
 
21
+ <h4>Features</h4>
22
+ * Page and Category widgets
23
+ * Option to display or not display the highest level parent page or category
24
+ * Option to display the menu when there is only the highest level parent
25
+ * Ability to order pages by (date, title, page order)
26
+ * Exclude pages or categories by entering a comma separated list of ids
27
+ * Option to always display child pages or categories
28
+ * Option to select the levels of pages or categories to display when always display child is used
29
+ * Option to display or not display categories on single posts
30
+ * Ability to display each single post's category in a new widget or in same list
31
+
32
  <h4>Page Widget Options</h4>
33
  * Add a title to the widget
34
+ * Display highest level parent page
35
+ * Display menu when there is only the parent page
36
+ * Order pages by (date, title, page order)
37
  * Use built in styling (very plain styling, for more advanced styling <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Go Pro!</a>)
38
  * Exclude pages
39
  * Always display child Pages
41
 
42
  <h4>Category Widget Options</h4>
43
  * Add a title to the widget
44
+ * Display highest level parent category
45
+ * Display menu when there is only the parent category
46
  * Use built in styling (very plain styling, for more advanced styling <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Go Pro!</a>)
47
+ * Display categories on single posts
48
+ * Display each single post's category in a new widget or in same list
49
+ * Exclude categories
50
  * Always display child categories
51
  * Levels of Categories to display when always display child categories is checked
52
 
53
  <h4>Pro Features</h4>
54
  * Priority support
55
  * Ability to customize each page link’s text
56
+ * Option to display the current page's parents and grandparents only
57
+ * Number of levels of pages to show when always displayed child pages is not checked
58
  * Click and drag styling for both the page and category widgets
59
+ * Styling options for links including color, background color, size, and font weight
60
  * Styling options for different levels of links
61
  * Styling options for the current page or category
62
  * Styling options for the parent of the current page or category
63
  * Block styling options including borders and border colors
64
  * Bullet style selection from 7 styles or select none to have no bullets
 
65
  * Accordion menu support for pages
66
  * Accordion menu support for categories
67
  * Accordion icon selection from 4 styles of icons
68
  * Accordion icon color selection
69
+ * Accordion option to keep all sections closed until clicked
70
+ * Accordion option to include highest level parent in accordion
71
  * Ability to exclude a page from all menus using a simple checkbox
72
  * Link ordering for the category widget
 
73
  * Ability to select and display custom post types **NEW**
74
  * Ability to select and display custom taxonomies **NEW**
75
 
97
 
98
  == Screenshots ==
99
 
100
+ 1. Page widget options
101
+ 2. Category widget options
102
+ 3. Example of a page menu using the 2017 theme and default styles
103
+ 3. Example of a category menu ordered by title using the 2017 theme and default styles
104
 
105
 
106
  == Frequently Asked Questions ==
124
  }
125
  </code>
126
 
127
+ To style your menu without using any code <a href="https://matlipe.com/product/advanced-sidebar-menu-pro/" target="_blank">Go Pro!</a>
128
 
129
  = How do you get the categories to display on single post pages? =
130
 
133
  = How do you edit the output or built in css? =
134
 
135
  Create a folder in your child theme named "advanced-sidebar-menu" copy any of the files from the "views" folder into
136
+ the folder you just created. You may edit the files to change the output or css. You must have the option checked to use the built in CSS (in the widget) to be able to edit the css file in this way.
 
137
 
138
 
139
  = Does the menu change for each page you are on? =
140
 
141
+ Yes. Based on whatever page, post, or category you are on, the menu will change automatically to display the current parents and children.
 
 
142
 
 
 
 
143
 
144
  == Changelog ==
145
  = 7.1.0 =
src/Menus/Category.php CHANGED
@@ -31,11 +31,11 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
31
  public $taxonomy = 'category';
32
 
33
  /**
34
- * current_term
35
  *
36
  * @var WP_Term
37
  */
38
- public $current_term;
39
 
40
 
41
  /**
@@ -44,20 +44,30 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
44
  * @return void
45
  */
46
  public function hook() {
47
- add_filter( 'category_css_class', array( $this, 'add_has_children_category_class' ), 2, 2 );
48
  }
49
 
50
 
51
- public function set_current_term( WP_Term $term ) {
52
- $this->top_id = $term->term_id;
53
- $this->current_term = $term;
 
 
 
 
 
 
 
 
 
54
  }
55
 
 
56
  /**
57
  * Return the list of args for wp_list_categories()
58
  *
59
- * @param string $level - level of menu so we have full control of updates
60
- * @param WP_Term $term - Term for child and grandchild
61
  *
62
  * @return array
63
  */
@@ -72,25 +82,25 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
72
  'title_li' => '',
73
  );
74
 
75
- if( null === $level ){
76
  return $args;
77
  }
78
- switch ( $level ){
79
  case 'parent':
80
- $args[ 'hide_empty' ] = 0;
81
- $args[ 'include' ] = trim( $this->get_top_parent_id() );
82
  break;
83
  case 'display-all':
84
- $args[ 'child_of' ] = $this->get_top_parent_id();
85
- $args[ 'depth' ] = $this->get_levels_to_display();
 
 
 
 
86
  break;
87
- case 'child':
88
- $args[ 'include' ] = $term->term_id;
89
- $args[ 'depth' ] = 1;
90
- break;
91
  case 'grandchild':
92
- $args[ 'child_of' ] = $term->term_id;
93
- $args[ 'depth' ] = $this->get_menu_depth();
94
  break;
95
  }
96
 
@@ -98,13 +108,25 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
98
  }
99
 
100
 
 
 
 
 
 
 
 
 
 
 
 
101
  public function get_child_terms() {
102
  $child_terms = array_filter(
103
  get_terms(
104
- $this->get_taxonomy(), array(
105
- 'parent' => $this->get_top_parent_id(),
106
- 'orderby' => $this->get_order_by(),
107
- 'order' => $this->get_order(),
 
108
  )
109
  )
110
  );
@@ -141,13 +163,13 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
141
  * @return array
142
  */
143
  public function get_top_level_terms() {
144
- $child_term_ids = $this->get_included_term_ids();
145
  $top_level_term_ids = array();
146
- foreach( $child_term_ids as $_term_id ){
147
  $top_level_term_ids[] = $this->get_highest_parent( $_term_id );
148
  }
149
  $terms = array();
150
- if( !empty( $top_level_term_ids ) ){
151
  $terms = get_terms( array(
152
  'include' => array_unique( array_filter( $top_level_term_ids ) ),
153
  'hide_empty' => false,
@@ -155,7 +177,7 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
155
  'order' => $this->get_order(),
156
  ) );
157
  }
158
- if( is_wp_error( $terms ) ){
159
  return array();
160
  }
161
 
@@ -172,9 +194,9 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
172
  */
173
  public function get_included_term_ids() {
174
  $term_ids = array();
175
- if( is_single() ){
176
  $term_ids = wp_get_object_terms( get_the_ID(), $this->get_taxonomy(), array( 'fields' => 'ids' ) );
177
- } elseif( $this->is_tax() ) {
178
  $term_ids[] = get_queried_object()->term_id;
179
  }
180
 
@@ -190,10 +212,11 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
190
 
191
 
192
  public function get_top_parent_id() {
193
- if( empty( $this->current_term->term_id ) ){
194
  return null;
195
  }
196
- return $this->current_term->term_id;
 
197
  }
198
 
199
 
@@ -213,15 +236,15 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
213
 
214
  public function is_displayed() {
215
  $display = false;
216
- if( is_single() ){
217
- if( $this->checked( self::DISPLAY_ON_SINGLE ) ){
218
  $display = true;
219
  }
220
- if( has_filter( 'advanced_sidebar_menu_proper_single' ) ){
221
  _deprecated_hook( 'advanced_sidebar_menu_proper_single', '7.0.0', 'advanced-sidebar-menu/menus/category/is-displayed' );
222
- $display = !apply_filters( 'advanced_sidebar_menu_proper_single', !$display, $this->args, $this->instance, $this );
223
  }
224
- } elseif( $this->is_tax() ) {
225
  $display = true;
226
  }
227
 
@@ -243,11 +266,11 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
243
  * @return bool
244
  */
245
  public function is_term_displayed( array $child_terms ) {
246
- if( empty( $child_terms ) ){
247
- if( !$this->checked( self::INCLUDE_PARENT ) || !$this->checked( self::INCLUDE_CHILDLESS_PARENT ) ){
248
  return false;
249
  }
250
- if( $this->is_excluded( $this->get_top_parent_id() ) ){
251
  return false;
252
  }
253
  }
@@ -264,11 +287,11 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
264
  */
265
  protected function is_tax() {
266
  $taxonomy = $this->get_taxonomy();
267
- if( 'category' === $taxonomy ){
268
- if( is_category() ){
269
  return true;
270
  }
271
- } elseif( is_tax( $taxonomy ) ) {
272
  return true;
273
  }
274
 
@@ -291,7 +314,7 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
291
  * @return string|bool
292
  */
293
  public function openListItem( $item = false ) {
294
- if( !$item ){
295
  return false;
296
  }
297
 
@@ -308,18 +331,18 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
308
  * @return int
309
  */
310
  public function get_highest_parent( $term_id ) {
311
- $cat_ancestors = array();
312
  $cat_ancestors[] = $term_id;
313
 
314
  do {
315
  $term = get_term( $term_id, $this->get_taxonomy() );
316
- if( !is_wp_error( $term ) ){
317
- $term_id = $term->parent;
318
  $cat_ancestors[] = $term_id;
319
  } else {
320
  $term = false;
321
  }
322
- } while( $term );
323
 
324
  //we only track the last calls ancestors because we only care
325
  //about these when on a single term archive
@@ -345,7 +368,7 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
345
  'hide_empty' => false,
346
  'number' => 1,
347
  ) );
348
- if( !empty( $children ) ){
349
  $classes[] = 'has_children';
350
  }
351
 
@@ -367,7 +390,7 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
367
  */
368
  public function is_first_level_term( WP_Term $term ) {
369
  $return = false;
370
- if( !$this->is_excluded( $term->term_id ) && (int) $term->parent === (int) $this->get_top_parent_id() ){
371
  $return = true;
372
  }
373
 
@@ -385,17 +408,17 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
385
  */
386
  public function is_current_term_ancestor( WP_Term $term ) {
387
  $return = false;
388
- if( (int) $term->term_id === (int) $this->current_term->term_id || in_array( $term->term_id, $this->ancestors, false ) ){
389
  $all_children = get_terms( $this->get_taxonomy(), array(
390
  'child_of' => $term->term_id,
391
  'fields' => 'ids',
392
  ) );
393
- if( !empty( $all_children ) ){
394
  $return = true;
395
  }
396
  }
397
 
398
- if( has_filter( 'advanced_sidebar_menu_second_level_category' ) ){
399
  _deprecated_hook( 'advanced_sidebar_menu_second_level_category', '7.0.0', 'advanced-sidebar-menu/menus/category/is-current-term-ancestor' );
400
  $return = apply_filters( 'advanced_sidebar_menu_second_level_category', $return, $term, $this );
401
  }
@@ -413,9 +436,9 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
413
  * @return mixed
414
  */
415
  public function has_children( WP_Term $term ) {
416
- $return = false;
417
  $children = get_term_children( $term->term_id, $this->get_taxonomy() );
418
- if( !empty( $children ) ){
419
  $return = true;
420
  }
421
 
@@ -429,37 +452,37 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
429
  * @return void
430
  */
431
  public function render() {
432
- if( !$this->is_displayed() ){
433
  return;
434
  }
435
 
436
- $menu_open = false;
437
  $close_menu = false;
438
 
439
- foreach( $this->get_top_level_terms() as $_cat ){
440
- $this->set_current_term( $_cat );
441
  //@deprecated 7.0.0 variable name
442
  $all_categories = $this->get_child_terms();
443
- if( !$this->is_term_displayed( $all_categories ) ){
444
  continue;
445
  }
446
 
447
- if( !$menu_open || ( $this->instance[ self::EACH_CATEGORY_DISPLAY ] === 'widget' ) ){
448
  //Start the menu
449
- echo $this->args[ 'before_widget' ];
450
 
451
  do_action( 'advanced-sidebar-menu/menus/category/render', $this );
452
 
453
- if( !$menu_open ){
454
  //must remain in the loop vs the template
455
  $this->title();
456
- if( $this->checked( self::USE_PLUGIN_STYLES ) ){
457
  Advanced_Sidebar_Menu_Core::instance()->include_plugin_styles();
458
  }
459
 
460
- $menu_open = true;
461
  $close_menu = true;
462
- if( $this->instance[ self::EACH_CATEGORY_DISPLAY ] === 'list' ){
463
  $close_menu = false;
464
  }
465
  }
@@ -469,13 +492,13 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
469
 
470
  echo apply_filters( 'advanced_sidebar_menu_category_widget_output', $output, $this->args, $this->instance, $this );
471
 
472
- if( $close_menu ){
473
- echo $this->args[ 'after_widget' ];
474
  }
475
  }
476
 
477
- if( !$close_menu && $menu_open ){
478
- echo $this->args[ 'after_widget' ];
479
  }
480
 
481
  }
@@ -523,4 +546,4 @@ class Advanced_Sidebar_Menu_Menus_Category extends Advanced_Sidebar_Menu_Menus_A
523
  return $class;
524
  }
525
 
526
- }
31
  public $taxonomy = 'category';
32
 
33
  /**
34
+ * top_level_term
35
  *
36
  * @var WP_Term
37
  */
38
+ public $top_level_term;
39
 
40
 
41
  /**
44
  * @return void
45
  */
46
  public function hook() {
47
+ add_filter( 'category_css_class', array( $this, 'add_has_children_category_class' ), 2, 2 );
48
  }
49
 
50
 
51
+ /**
52
+ * If we are on a post we could potentially have more than one
53
+ * top level term so we end up calling this more than once.
54
+ *
55
+ *
56
+ * @param WP_Term $term
57
+ *
58
+ * @return void
59
+ */
60
+ public function set_current_top_level_term( WP_Term $term ) {
61
+ $this->top_id = $term->term_id;
62
+ $this->top_level_term = $term;
63
  }
64
 
65
+
66
  /**
67
  * Return the list of args for wp_list_categories()
68
  *
69
+ * @param string $level - level of menu so we have full control of updates
70
+ * @param WP_Term $term - Term for child and grandchild
71
  *
72
  * @return array
73
  */
82
  'title_li' => '',
83
  );
84
 
85
+ if ( null === $level ) {
86
  return $args;
87
  }
88
+ switch ( $level ) {
89
  case 'parent':
90
+ $args['hide_empty'] = 0;
91
+ $args['include'] = trim( $this->get_top_parent_id() );
92
  break;
93
  case 'display-all':
94
+ $args['child_of'] = $this->get_top_parent_id();
95
+ $args['depth'] = $this->get_levels_to_display();
96
+ break;
97
+ case 'child':
98
+ $args['include'] = $term->term_id;
99
+ $args['depth'] = 1;
100
  break;
 
 
 
 
101
  case 'grandchild':
102
+ $args['child_of'] = $term->term_id;
103
+ $args['depth'] = $this->get_menu_depth();
104
  break;
105
  }
106
 
108
  }
109
 
110
 
111
+ /**
112
+ * Get the first level child terms.
113
+ *
114
+ * $this->set_current_top_level_term() most likely should be called
115
+ * before this.
116
+ *
117
+ * @see Advanced_Sidebar_Menu_Menus_Category::set_current_top_level_term()
118
+ *
119
+ *
120
+ * @return array
121
+ */
122
  public function get_child_terms() {
123
  $child_terms = array_filter(
124
  get_terms(
125
+ array(
126
+ 'taxonomy' => $this->get_taxonomy(),
127
+ 'parent' => $this->get_top_parent_id(),
128
+ 'orderby' => $this->get_order_by(),
129
+ 'order' => $this->get_order(),
130
  )
131
  )
132
  );
163
  * @return array
164
  */
165
  public function get_top_level_terms() {
166
+ $child_term_ids = $this->get_included_term_ids();
167
  $top_level_term_ids = array();
168
+ foreach ( $child_term_ids as $_term_id ) {
169
  $top_level_term_ids[] = $this->get_highest_parent( $_term_id );
170
  }
171
  $terms = array();
172
+ if ( ! empty( $top_level_term_ids ) ) {
173
  $terms = get_terms( array(
174
  'include' => array_unique( array_filter( $top_level_term_ids ) ),
175
  'hide_empty' => false,
177
  'order' => $this->get_order(),
178
  ) );
179
  }
180
+ if ( is_wp_error( $terms ) ) {
181
  return array();
182
  }
183
 
194
  */
195
  public function get_included_term_ids() {
196
  $term_ids = array();
197
+ if ( is_single() ) {
198
  $term_ids = wp_get_object_terms( get_the_ID(), $this->get_taxonomy(), array( 'fields' => 'ids' ) );
199
+ } elseif ( $this->is_tax() ) {
200
  $term_ids[] = get_queried_object()->term_id;
201
  }
202
 
212
 
213
 
214
  public function get_top_parent_id() {
215
+ if ( empty( $this->top_level_term->term_id ) ) {
216
  return null;
217
  }
218
+
219
+ return $this->top_level_term->term_id;
220
  }
221
 
222
 
236
 
237
  public function is_displayed() {
238
  $display = false;
239
+ if ( is_single() ) {
240
+ if ( $this->checked( self::DISPLAY_ON_SINGLE ) ) {
241
  $display = true;
242
  }
243
+ if ( has_filter( 'advanced_sidebar_menu_proper_single' ) ) {
244
  _deprecated_hook( 'advanced_sidebar_menu_proper_single', '7.0.0', 'advanced-sidebar-menu/menus/category/is-displayed' );
245
+ $display = ! apply_filters( 'advanced_sidebar_menu_proper_single', ! $display, $this->args, $this->instance, $this );
246
  }
247
+ } elseif ( $this->is_tax() ) {
248
  $display = true;
249
  }
250
 
266
  * @return bool
267
  */
268
  public function is_term_displayed( array $child_terms ) {
269
+ if ( empty( $child_terms ) ) {
270
+ if ( ! $this->checked( self::INCLUDE_PARENT ) || ! $this->checked( self::INCLUDE_CHILDLESS_PARENT ) ) {
271
  return false;
272
  }
273
+ if ( $this->is_excluded( $this->get_top_parent_id() ) ) {
274
  return false;
275
  }
276
  }
287
  */
288
  protected function is_tax() {
289
  $taxonomy = $this->get_taxonomy();
290
+ if ( 'category' === $taxonomy ) {
291
+ if ( is_category() ) {
292
  return true;
293
  }
294
+ } elseif ( is_tax( $taxonomy ) ) {
295
  return true;
296
  }
297
 
314
  * @return string|bool
315
  */
316
  public function openListItem( $item = false ) {
317
+ if ( ! $item ) {
318
  return false;
319
  }
320
 
331
  * @return int
332
  */
333
  public function get_highest_parent( $term_id ) {
334
+ $cat_ancestors = array();
335
  $cat_ancestors[] = $term_id;
336
 
337
  do {
338
  $term = get_term( $term_id, $this->get_taxonomy() );
339
+ if ( ! is_wp_error( $term ) ) {
340
+ $term_id = $term->parent;
341
  $cat_ancestors[] = $term_id;
342
  } else {
343
  $term = false;
344
  }
345
+ } while ( $term );
346
 
347
  //we only track the last calls ancestors because we only care
348
  //about these when on a single term archive
368
  'hide_empty' => false,
369
  'number' => 1,
370
  ) );
371
+ if ( ! empty( $children ) ) {
372
  $classes[] = 'has_children';
373
  }
374
 
390
  */
391
  public function is_first_level_term( WP_Term $term ) {
392
  $return = false;
393
+ if ( ! $this->is_excluded( $term->term_id ) && (int) $term->parent === (int) $this->get_top_parent_id() ) {
394
  $return = true;
395
  }
396
 
408
  */
409
  public function is_current_term_ancestor( WP_Term $term ) {
410
  $return = false;
411
+ if ( (int) $term->term_id === (int) $this->top_level_term->term_id || in_array( $term->term_id, $this->ancestors, false ) ) {
412
  $all_children = get_terms( $this->get_taxonomy(), array(
413
  'child_of' => $term->term_id,
414
  'fields' => 'ids',
415
  ) );
416
+ if ( ! empty( $all_children ) ) {
417
  $return = true;
418
  }
419
  }
420
 
421
+ if ( has_filter( 'advanced_sidebar_menu_second_level_category' ) ) {
422
  _deprecated_hook( 'advanced_sidebar_menu_second_level_category', '7.0.0', 'advanced-sidebar-menu/menus/category/is-current-term-ancestor' );
423
  $return = apply_filters( 'advanced_sidebar_menu_second_level_category', $return, $term, $this );
424
  }
436
  * @return mixed
437
  */
438
  public function has_children( WP_Term $term ) {
439
+ $return = false;
440
  $children = get_term_children( $term->term_id, $this->get_taxonomy() );
441
+ if ( ! empty( $children ) ) {
442
  $return = true;
443
  }
444
 
452
  * @return void
453
  */
454
  public function render() {
455
+ if ( ! $this->is_displayed() ) {
456
  return;
457
  }
458
 
459
+ $menu_open = false;
460
  $close_menu = false;
461
 
462
+ foreach ( $this->get_top_level_terms() as $_cat ) {
463
+ $this->set_current_top_level_term( $_cat );
464
  //@deprecated 7.0.0 variable name
465
  $all_categories = $this->get_child_terms();
466
+ if ( ! $this->is_term_displayed( $all_categories ) ) {
467
  continue;
468
  }
469
 
470
+ if ( ! $menu_open || ( 'widget' === $this->instance[ self::EACH_CATEGORY_DISPLAY ] ) ) {
471
  //Start the menu
472
+ echo $this->args['before_widget'];
473
 
474
  do_action( 'advanced-sidebar-menu/menus/category/render', $this );
475
 
476
+ if ( ! $menu_open ) {
477
  //must remain in the loop vs the template
478
  $this->title();
479
+ if ( $this->checked( self::USE_PLUGIN_STYLES ) ) {
480
  Advanced_Sidebar_Menu_Core::instance()->include_plugin_styles();
481
  }
482
 
483
+ $menu_open = true;
484
  $close_menu = true;
485
+ if ( 'list' === $this->instance[ self::EACH_CATEGORY_DISPLAY ] ) {
486
  $close_menu = false;
487
  }
488
  }
492
 
493
  echo apply_filters( 'advanced_sidebar_menu_category_widget_output', $output, $this->args, $this->instance, $this );
494
 
495
+ if ( $close_menu ) {
496
+ echo $this->args['after_widget'];
497
  }
498
  }
499
 
500
+ if ( ! $close_menu && $menu_open ) {
501
+ echo $this->args['after_widget'];
502
  }
503
 
504
  }
546
  return $class;
547
  }
548
 
549
+ }
src/Widget/Category.php CHANGED
@@ -69,7 +69,7 @@ class Advanced_Sidebar_Menu_Widget_Category extends WP_Widget {
69
  </p>
70
 
71
 
72
- <p> <?php _e( 'Display parent category', 'advanced-sidebar-menu' ); ?>
73
  <input id="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>"
74
  name="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>" type="checkbox" value="checked"
75
  <?php echo $instance[ self::INCLUDE_PARENT ]; ?>/>
69
  </p>
70
 
71
 
72
+ <p> <?php _e( 'Display highest level parent category', 'advanced-sidebar-menu' ); ?>
73
  <input id="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>"
74
  name="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>" type="checkbox" value="checked"
75
  <?php echo $instance[ self::INCLUDE_PARENT ]; ?>/>
src/Widget/Page.php CHANGED
@@ -68,7 +68,7 @@ class Advanced_Sidebar_Menu_Widget_Page extends WP_Widget {
68
  name="<?php echo $this->get_field_name( self::TITLE ); ?>" class="widefat" type="text" value="<?php echo $instance[ self::TITLE ]; ?>"/>
69
  </p>
70
 
71
- <p> <?php _e( 'Display parent page', 'advanced-sidebar-menu' ); ?>:
72
  <input id="<?php echo $this->get_field_id( self::INCLUDE_PARENT ); ?>"
73
  name="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>" type="checkbox" value="checked"
74
  <?php echo $instance[ self::INCLUDE_PARENT ]; ?>/>
@@ -81,7 +81,7 @@ class Advanced_Sidebar_Menu_Widget_Page extends WP_Widget {
81
  <?php echo $instance[ self::INCLUDE_CHILDLESS_PARENT ]; ?>/>
82
  </p>
83
 
84
- <p> <?php _e( 'Order By', 'advanced-sidebar-menu' ); ?>:
85
  <select id="<?php echo $this->get_field_id( self::ORDER_BY ); ?>"
86
  name="<?php echo $this->get_field_name( self::ORDER_BY ); ?>">
87
  <?php
68
  name="<?php echo $this->get_field_name( self::TITLE ); ?>" class="widefat" type="text" value="<?php echo $instance[ self::TITLE ]; ?>"/>
69
  </p>
70
 
71
+ <p> <?php _e( 'Display highest level parent page', 'advanced-sidebar-menu' ); ?>:
72
  <input id="<?php echo $this->get_field_id( self::INCLUDE_PARENT ); ?>"
73
  name="<?php echo $this->get_field_name( self::INCLUDE_PARENT ); ?>" type="checkbox" value="checked"
74
  <?php echo $instance[ self::INCLUDE_PARENT ]; ?>/>
81
  <?php echo $instance[ self::INCLUDE_CHILDLESS_PARENT ]; ?>/>
82
  </p>
83
 
84
+ <p> <?php _e( 'Order by', 'advanced-sidebar-menu' ); ?>:
85
  <select id="<?php echo $this->get_field_id( self::ORDER_BY ); ?>"
86
  name="<?php echo $this->get_field_name( self::ORDER_BY ); ?>">
87
  <?php