Advanced Sidebar Menu - Version 7.4.2

Version Description

Update to support PRO version 3.4.3

Download this release

Release Info

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

Code changes from version 7.4.1 to 7.4.2

advanced-sidebar-menu.php CHANGED
@@ -4,7 +4,7 @@
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.4.1
8
  * Author URI: https://matlipe.com
9
  * Text Domain: advanced-sidebar-menu
10
  *
@@ -15,7 +15,7 @@ if ( defined( 'ADVANCED_SIDEBAR_BASIC_VERSION' ) ) {
15
  return;
16
  }
17
 
18
- define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.4.1' );
19
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
20
 
21
  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.4.2
8
  * Author URI: https://matlipe.com
9
  * Text Domain: advanced-sidebar-menu
10
  *
15
  return;
16
  }
17
 
18
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.4.2' );
19
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
20
 
21
  if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: menus, sidebar menu, hierarchy, category menu, pages menu
6
  Requires at least: 4.6.0
7
  Tested up to: 4.9.8
8
  Requires PHP: 5.2.4
9
- Stable tag: 7.4.1
10
 
11
  == Description ==
12
 
@@ -228,6 +228,9 @@ Yes. Based on whatever page, post, or category you are on, the menu will change
228
 
229
 
230
  == Upgrade Notice ==
 
 
 
231
  = 7.4.0 =
232
  Update to support PRO version 3.4.0
233
 
6
  Requires at least: 4.6.0
7
  Tested up to: 4.9.8
8
  Requires PHP: 5.2.4
9
+ Stable tag: 7.4.2
10
 
11
  == Description ==
12
 
228
 
229
 
230
  == Upgrade Notice ==
231
+ = 7.4.2 =
232
+ Update to support PRO version 3.4.3
233
+
234
  = 7.4.0 =
235
  Update to support PRO version 3.4.0
236
 
resources/js/advanced-sidebar-menu.js CHANGED
@@ -5,13 +5,19 @@
5
  *
6
  **/
7
  function asm_reveal_element(this_element_id) {
8
- //old used ids. New use data-js so multiple may be used specifically
9
- //@todo remove this select of id once PRO has been converted over
10
- var el = jQuery( '[id="' + this_element_id + '"]:first');
11
- if( ! el.length ){
12
- el = jQuery( '[data-js="' + this_element_id + '"]' );
13
- }
14
  el.toggle();
15
  var status = el.is(':visible') ? 'show' : 'hide';
16
  jQuery( document ).trigger('advanced-sidebar-menu/reveal-element', [this_element_id, status]);
17
  }
 
 
 
 
 
 
 
 
 
 
5
  *
6
  **/
7
  function asm_reveal_element(this_element_id) {
8
+ var el = jQuery( '[data-js="' + this_element_id + '"]' );
9
+
 
 
 
 
10
  el.toggle();
11
  var status = el.is(':visible') ? 'show' : 'hide';
12
  jQuery( document ).trigger('advanced-sidebar-menu/reveal-element', [this_element_id, status]);
13
  }
14
+
15
+ jQuery(function ($) {
16
+ /**
17
+ * Use JS to show/hide widget elements instead of PHP because sometimes widgets are loaded
18
+ * in weird ways like ajax and we don't want any fields hidden if the JS is never loaded
19
+ * to later show them
20
+ */
21
+ $('[data-advanced-sidebar-menu-hide="1"]').hide();
22
+ $('[data-advanced-sidebar-menu-hide="0"]').show();
23
+ });
src/Widget/Widget.php CHANGED
@@ -1,14 +1,17 @@
1
  <?php
2
-
3
  /**
4
  * Advanced_Sidebar_Menu__Widget__Widget
5
  *
6
  * @author Mat Lipe
7
  *
8
  * @since 7.2.0
9
- *
10
  */
11
  abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
 
 
 
 
 
12
  protected $_instance;
13
 
14
 
@@ -19,8 +22,8 @@ abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
19
  *
20
  * @see WP_Widget::form_callback()
21
  *
22
- * @param array $instance
23
- * @param array $defaults
24
  *
25
  * @since 7.2.0
26
  *
@@ -54,12 +57,11 @@ abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
54
  /**
55
  * Hide an reveal_element if a checkbox is checked.
56
  *
57
- * @param string $checkbox - name of checkbox reveal_element which controls this one
58
- * @param string $reveal_element - match the reveal element passed to checkbox which reveals this
59
- * @param bool $reverse - hide on check instead of show on check
60
  *
61
- *
62
- * @todo Convert all uses of this method to supply the $reveal_element
63
  *
64
  * @since 7.2.0
65
  * @since 7.2.2 Added the `reveal_element` argument.
@@ -67,17 +69,21 @@ abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
67
  * @return void
68
  */
69
  public function hide_element( $checkbox, $reveal_element = null, $reverse = false ) {
70
- if ( $reverse ) {
71
- if ( $this->checked( $checkbox ) ) {
72
- ?>style="display:none"<?php
73
- }
74
- } else {
75
- if ( ! $this->checked( $checkbox ) ) {
76
- ?>style="display:none"<?php
77
- }
78
  }
 
79
  if ( null !== $reveal_element ) {
80
- ?> data-js="<?php echo esc_attr( $this->get_field_id( $reveal_element ) ); ?>"<?php
 
 
 
 
 
 
 
 
81
  }
82
  }
83
 
@@ -85,13 +91,12 @@ abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
85
  /**
86
  * Outputs a <input type="checkbox" with id and name filled
87
  *
88
- * @param string $name
89
- * @param string|null $reveal_element
90
  *
91
  * @since 7.2.0
92
- *
93
  */
94
- public function checkbox( $name, $reveal_element = null ) {
95
  if ( empty( $this->_instance[ $name ] ) ) {
96
  $this->_instance[ $name ] = null;
97
  }
@@ -103,7 +108,7 @@ abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
103
  type="checkbox"
104
  value="checked"
105
  data-js="advanced-sidebar-menu/widget/<?php echo esc_attr( $this->id_base ); ?>/<?php echo esc_attr( $name ); ?>"
106
- <?php echo ( null !== $reveal_element ) ? 'onclick="asm_reveal_element( \'' . esc_attr( $this->get_field_id( $reveal_element ) ) . '\')"' : ''; ?>
107
  <?php echo esc_html( $this->_instance[ $name ] ); ?>
108
  />
109
  <?php
1
  <?php
 
2
  /**
3
  * Advanced_Sidebar_Menu__Widget__Widget
4
  *
5
  * @author Mat Lipe
6
  *
7
  * @since 7.2.0
 
8
  */
9
  abstract class Advanced_Sidebar_Menu__Widget__Widget extends WP_Widget {
10
+ /**
11
+ * The current widget instance
12
+ *
13
+ * @var array
14
+ */
15
  protected $_instance;
16
 
17
 
22
  *
23
  * @see WP_Widget::form_callback()
24
  *
25
+ * @param array $instance - widget settings.
26
+ * @param array $defaults - defaults for all widgets.
27
  *
28
  * @since 7.2.0
29
  *
57
  /**
58
  * Hide an reveal_element if a checkbox is checked.
59
  *
60
+ * @param string $checkbox - name of checkbox reveal_element which controls this one.
61
+ * @param string $reveal_element - match the reveal element passed to checkbox which reveals this.
62
+ * @param bool $reverse - hide on check instead of show on check.
63
  *
64
+ * @todo Convert all uses of this method to supply the $reveal_element
 
65
  *
66
  * @since 7.2.0
67
  * @since 7.2.2 Added the `reveal_element` argument.
69
  * @return void
70
  */
71
  public function hide_element( $checkbox, $reveal_element = null, $reverse = false ) {
72
+ $hide = false;
73
+ if ( ( $reverse && $this->checked( $checkbox ) ) || ( ! $reverse && ! $this->checked( $checkbox ) ) ) {
74
+ $hide = true;
 
 
 
 
 
75
  }
76
+
77
  if ( null !== $reveal_element ) {
78
+ ?> data-js="<?php echo esc_attr( $this->get_field_id( $reveal_element ) ); ?>"
79
+ <?php
80
+ }
81
+ // Append the hide to a global variable so it can be picked up only if the advanced-sidebar-menu JS is present.
82
+ // Prevents hiding of elements when widgets are loaded in unique ways like ajax.
83
+ if ( $hide ) {
84
+ ?>
85
+ data-advanced-sidebar-menu-hide="1"
86
+ <?php
87
  }
88
  }
89
 
91
  /**
92
  * Outputs a <input type="checkbox" with id and name filled
93
  *
94
+ * @param string $name - name of field.
95
+ * @param string|null $element_to_reveal - element to reveal/hide when box is checked/unchecked.
96
  *
97
  * @since 7.2.0
 
98
  */
99
+ public function checkbox( $name, $element_to_reveal = null ) {
100
  if ( empty( $this->_instance[ $name ] ) ) {
101
  $this->_instance[ $name ] = null;
102
  }
108
  type="checkbox"
109
  value="checked"
110
  data-js="advanced-sidebar-menu/widget/<?php echo esc_attr( $this->id_base ); ?>/<?php echo esc_attr( $name ); ?>"
111
+ <?php echo ( null !== $element_to_reveal ) ? 'onclick="asm_reveal_element( \'' . esc_attr( $this->get_field_id( $element_to_reveal ) ) . '\')"' : ''; ?>
112
  <?php echo esc_html( $this->_instance[ $name ] ); ?>
113
  />
114
  <?php