Advanced Sidebar Menu - Version 8.6.2

Version Description

  • Assured consistency for levels of page menu's CSS classes.
  • Converted category get highest parent logic to get_ancestors.
  • Gracefully handle invalid taxonomies in Category widgets.
  • Gracefully handle widgets without ids.
  • Fixed color pickers in Elementor.
  • Fixed color pickers in Beaver Builder.
Download this release

Release Info

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

Code changes from version 8.6.1 to 8.6.2

advanced-sidebar-menu.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: https://onpointplugins.com/advanced-sidebar-menu/
5
  * Description: Creates dynamic menus based on parent/child relationship of your pages or categories.
6
  * Author: OnPoint Plugins
7
- * Version: 8.6.1
8
  * Author URI: https://onpointplugins.com
9
  * Text Domain: advanced-sidebar-menu
10
  * Domain Path: /languages/
@@ -19,7 +19,7 @@ if ( defined( 'ADVANCED_SIDEBAR_BASIC_VERSION' ) ) {
19
  return;
20
  }
21
 
22
- define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '8.6.1' );
23
  define( 'ADVANCED_SIDEBAR_MENU_REQUIRED_PRO_VERSION', '8.3.1' );
24
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
25
  define( 'ADVANCED_SIDEBAR_MENU_URL', plugin_dir_url( __FILE__ ) );
4
  * Plugin URI: https://onpointplugins.com/advanced-sidebar-menu/
5
  * Description: Creates dynamic menus based on parent/child relationship of your pages or categories.
6
  * Author: OnPoint Plugins
7
+ * Version: 8.6.2
8
  * Author URI: https://onpointplugins.com
9
  * Text Domain: advanced-sidebar-menu
10
  * Domain Path: /languages/
19
  return;
20
  }
21
 
22
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '8.6.2' );
23
  define( 'ADVANCED_SIDEBAR_MENU_REQUIRED_PRO_VERSION', '8.3.1' );
24
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
25
  define( 'ADVANCED_SIDEBAR_MENU_URL', plugin_dir_url( __FILE__ ) );
readme.txt CHANGED
@@ -4,9 +4,9 @@ Contributors: Mat Lipe, onpointplugins
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40onpointplugins%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, dynamic
6
  Requires at least: 5.2.0
7
- Tested up to: 5.8.0
8
  Requires PHP: 5.6.0
9
- Stable tag: 8.6.1
10
 
11
  == Description ==
12
 
@@ -156,6 +156,14 @@ Yes. Based on whatever page, post, or category you are on, the menu will change
156
 
157
 
158
  == Changelog ==
 
 
 
 
 
 
 
 
159
  = 8.6.1 =
160
  * Improved widget interaction handling.
161
  * Synced styles between block, classic, and customizer widgets.
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40onpointplugins%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, dynamic
6
  Requires at least: 5.2.0
7
+ Tested up to: 5.8.1
8
  Requires PHP: 5.6.0
9
+ Stable tag: 8.6.2
10
 
11
  == Description ==
12
 
156
 
157
 
158
  == Changelog ==
159
+ = 8.6.2 =
160
+ * Assured consistency for levels of page menu's CSS classes.
161
+ * Converted category get highest parent logic to `get_ancestors`.
162
+ * Gracefully handle invalid taxonomies in Category widgets.
163
+ * Gracefully handle widgets without ids.
164
+ * Fixed color pickers in Elementor.
165
+ * Fixed color pickers in Beaver Builder.
166
+
167
  = 8.6.1 =
168
  * Improved widget interaction handling.
169
  * Synced styles between block, classic, and customizer widgets.
resources/css/advanced-sidebar-menu.css CHANGED
@@ -315,11 +315,8 @@ select.advanced-sidebar-menu-block-field {
315
 
316
  .elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container.wp-picker-active {
317
  top: auto;
318
- }
319
-
320
- .elementor-control-content .advanced-sidebar-menu-styles-box .wp-picker-active {
321
  width: 100%;
322
- margin: 5px 0 10px 0;
323
  }
324
 
325
  .elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container input[type='text'].wp-color-picker {
@@ -426,7 +423,7 @@ select.advanced-sidebar-menu-block-field {
426
 
427
  .fl-field-control-wrapper .advanced-sidebar-menu-styles-box .wp-picker-active {
428
  width: 100%;
429
- margin: 5px 0 10px 0;
430
  }
431
 
432
  .fl-field-control-wrapper .advanced-sidebar-menu-column-box .wp-picker-container input[type='text'].wp-color-picker {
315
 
316
  .elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container.wp-picker-active {
317
  top: auto;
 
 
 
318
  width: 100%;
319
+ margin: 5px 0 10px 0 !important;
320
  }
321
 
322
  .elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container input[type='text'].wp-color-picker {
423
 
424
  .fl-field-control-wrapper .advanced-sidebar-menu-styles-box .wp-picker-active {
425
  width: 100%;
426
+ margin: 5px 0 10px 0 !important;
427
  }
428
 
429
  .fl-field-control-wrapper .advanced-sidebar-menu-column-box .wp-picker-container input[type='text'].wp-color-picker {
src/List_Pages.php CHANGED
@@ -99,7 +99,13 @@ class List_Pages {
99
 
100
 
101
  /**
102
- * Add the custom classes to the list items
 
 
 
 
 
 
103
  *
104
  * @param array $classes - Provided classes for item.
105
  * @param \WP_Post $post - The item.
@@ -107,26 +113,25 @@ class List_Pages {
107
  * @return array
108
  */
109
  public function add_list_item_classes( $classes, \WP_Post $post ) {
110
- if ( $post->ID === $this->top_parent_id ) {
111
- $children = $this->get_child_pages( $post->ID, true );
112
- } else {
113
- $children = $this->get_child_pages( $post->ID );
114
- }
115
  if ( ! empty( $children ) ) {
116
  $classes[] = 'has_children';
117
  }
118
-
119
- // page posts are handled by wp core. This is for custom post types.
120
- if ( 'page' !== $post->post_type ) {
121
- $ancestors = get_post_ancestors( $post );
122
- if ( ! empty( $ancestors ) && in_array( $this->get_current_page_id(), $ancestors, false ) ) { //phpcs:ignore
123
- $classes[] = 'current_page_ancestor';
124
  } elseif ( $this->get_current_page_id() === $post->post_parent ) {
125
  $classes[] = 'current_page_parent';
 
 
 
 
 
 
126
  }
127
  }
128
 
129
- return array_unique( $classes );
130
  }
131
 
132
 
99
 
100
 
101
  /**
102
+ * Add hierarchical level classes to menu items.
103
+ *
104
+ * Follow existing WP core pattern for `wp_list_pages`.
105
+ *
106
+ * WP core handles pages, but it doesn't handle custom custom post types.
107
+ * We cover pages as well to handle edge cases where a site's theme
108
+ * changes/removes default classes.
109
  *
110
  * @param array $classes - Provided classes for item.
111
  * @param \WP_Post $post - The item.
113
  * @return array
114
  */
115
  public function add_list_item_classes( $classes, \WP_Post $post ) {
116
+ $children = $this->get_child_pages( $post->ID, $post->ID === $this->top_parent_id );
 
 
 
 
117
  if ( ! empty( $children ) ) {
118
  $classes[] = 'has_children';
119
  }
120
+ if ( ! empty( $this->get_current_page_id() ) ) {
121
+ if ( $this->get_current_page_id() === $post->ID ) {
122
+ $classes[] = 'current_page_item';
 
 
 
123
  } elseif ( $this->get_current_page_id() === $post->post_parent ) {
124
  $classes[] = 'current_page_parent';
125
+ $classes[] = 'current_page_ancestor';
126
+ } else {
127
+ $ancestors = get_post_ancestors( $this->get_current_page_id() );
128
+ if ( ! empty( $ancestors ) && \in_array( $post->ID, $ancestors, true ) ) {
129
+ $classes[] = 'current_page_ancestor';
130
+ }
131
  }
132
  }
133
 
134
+ return \array_unique( $classes );
135
  }
136
 
137
 
src/Menus/Category.php CHANGED
@@ -18,7 +18,7 @@ class Category extends Menu_Abstract {
18
  const EACH_CATEGORY_DISPLAY = 'new_widget';
19
 
20
  /**
21
- * Parents and grandparents fo current term.
22
  *
23
  * @var array
24
  */
@@ -103,8 +103,8 @@ class Category extends Menu_Abstract {
103
  * @return \WP_Term[]
104
  */
105
  public function get_child_terms() {
106
- $terms = array_filter(
107
- get_terms(
108
  [
109
  'taxonomy' => $this->get_taxonomy(),
110
  'parent' => $this->get_top_parent_id(),
@@ -113,7 +113,8 @@ class Category extends Menu_Abstract {
113
  ]
114
  )
115
  );
116
- return apply_filters( 'advanced-sidebar-menu/menus/category/get-child-terms', $terms, $this );
 
117
  }
118
 
119
 
@@ -149,7 +150,7 @@ class Category extends Menu_Abstract {
149
  if ( ! empty( $top_level_term_ids ) ) {
150
  $terms = get_terms(
151
  [
152
- 'include' => array_unique( array_filter( $top_level_term_ids ) ),
153
  'hide_empty' => false,
154
  'orderby' => $this->get_order_by(),
155
  'order' => $this->get_order(),
@@ -319,29 +320,21 @@ class Category extends Menu_Abstract {
319
 
320
  /**
321
  * Retrieve the highest level term_id based on the given
322
- * term's ancestors
 
 
 
323
  *
324
  * @param int $term_id - Provided term's id.
325
  *
326
  * @return int
327
  */
328
  public function get_highest_parent( $term_id ) {
329
- $cat_ancestors = [];
330
- $cat_ancestors[] = $term_id;
331
-
332
- do {
333
- $term = get_term( $term_id, $this->get_taxonomy() );
334
- if ( is_a( $term, \WP_Term::class ) ) {
335
- $term_id = $term->parent;
336
- $cat_ancestors[] = $term_id;
337
- } else {
338
- $term = false;
339
- }
340
- } while ( $term );
341
 
342
- // We only track the last calls ancestors because we only care about these when on a single term archive.
343
- $this->ancestors = array_reverse( $cat_ancestors );
344
- return $this->ancestors[1];
345
  }
346
 
347
 
18
  const EACH_CATEGORY_DISPLAY = 'new_widget';
19
 
20
  /**
21
+ * Parents and grandparents of current term.
22
  *
23
  * @var array
24
  */
103
  * @return \WP_Term[]
104
  */
105
  public function get_child_terms() {
106
+ $terms = get_terms(
107
+ \array_filter(
108
  [
109
  'taxonomy' => $this->get_taxonomy(),
110
  'parent' => $this->get_top_parent_id(),
113
  ]
114
  )
115
  );
116
+
117
+ return apply_filters( 'advanced-sidebar-menu/menus/category/get-child-terms', \array_filter( $terms ), $this );
118
  }
119
 
120
 
150
  if ( ! empty( $top_level_term_ids ) ) {
151
  $terms = get_terms(
152
  [
153
+ 'include' => \array_unique( \array_filter( $top_level_term_ids ) ),
154
  'hide_empty' => false,
155
  'orderby' => $this->get_order_by(),
156
  'order' => $this->get_order(),
320
 
321
  /**
322
  * Retrieve the highest level term_id based on the given
323
+ * term's ancestors.
324
+ *
325
+ * Track the latest call's ancestors on the class for use
326
+ * on the single term's archive.
327
  *
328
  * @param int $term_id - Provided term's id.
329
  *
330
  * @return int
331
  */
332
  public function get_highest_parent( $term_id ) {
333
+ $this->ancestors = \array_reverse( get_ancestors( $term_id, $this->get_taxonomy(), 'taxonomy' ) );
334
+ // Store current term at the end ancestors for backward compatibility.
335
+ $this->ancestors[] = $term_id;
 
 
 
 
 
 
 
 
 
336
 
337
+ return reset( $this->ancestors );
 
 
338
  }
339
 
340
 
src/Menus/Menu_Abstract.php CHANGED
@@ -124,15 +124,16 @@ abstract class Menu_Abstract {
124
  * @return void
125
  */
126
  protected function increment_widget_id() {
 
127
  if ( ! isset( $this->args['widget_id'] ) ) {
128
- return;
129
  }
130
- if ( in_array( $this->args['widget_id'], self::$unique_widget_ids, true ) ) {
131
  $suffix = 2;
132
  do {
133
  $alt_widget_id = $this->args['widget_id'] . "-$suffix";
134
  $suffix ++;
135
- } while ( in_array( $alt_widget_id, self::$unique_widget_ids, true ) );
136
  $this->args['widget_id'] = $alt_widget_id;
137
  self::$unique_widget_ids[] = $alt_widget_id;
138
  } else {
124
  * @return void
125
  */
126
  protected function increment_widget_id() {
127
+ // Block widgets loaded via the REST API don't have full widget args.
128
  if ( ! isset( $this->args['widget_id'] ) ) {
129
+ $this->args['widget_id'] = wp_hash( microtime() );
130
  }
131
+ if ( \in_array( $this->args['widget_id'], self::$unique_widget_ids, true ) ) {
132
  $suffix = 2;
133
  do {
134
  $alt_widget_id = $this->args['widget_id'] . "-$suffix";
135
  $suffix ++;
136
+ } while ( \in_array( $alt_widget_id, self::$unique_widget_ids, true ) );
137
  $this->args['widget_id'] = $alt_widget_id;
138
  self::$unique_widget_ids[] = $alt_widget_id;
139
  } else {