Advanced Sidebar Menu - Version 4.0.0

Version Description

  • Added support for an unlimited number of page levels
  • Change structure slightly for future enhancements
  • Added Legacy Mode for backwards compatibility
Download this release

Release Info

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

Code changes from version 3.6.2 to 4.0.0

advanced-sidebar-menu.php CHANGED
@@ -4,9 +4,9 @@ Plugin Name: Advanced Sidebar Menu
4
  Plugin URI: http://lipeimagination.info/wordpress/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
- Version: 3.6.2
8
  Author URI: http://lipeimagination.info
9
- Since: 3.6.13
10
  */
11
 
12
  #-- Bring in the functions
4
  Plugin URI: http://lipeimagination.info/wordpress/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
+ Version: 4.0.0
8
  Author URI: http://lipeimagination.info
9
+ Since: 4.5.13
10
  */
11
 
12
  #-- Bring in the functions
lib/advancedSidebarMenu.php CHANGED
@@ -4,13 +4,87 @@
4
  /**
5
  * These Functions are Specific to the Advanced Sidebar Menu
6
  * @author Mat Lipe
7
- * @since 10.12.12
8
  */
9
  class advancedSidebarMenu{
10
- private $instance; //The widget instance
11
- private $top_id; //Either the top cat or page
12
- private $exclude;
13
- private $ancestors; //For the category ancestors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
 
16
  /**
@@ -20,7 +94,7 @@ class advancedSidebarMenu{
20
  * @return array
21
  * @since 10.10.12
22
  */
23
- function custom_post_type_css($css, $this_menu_item){
24
  global $post;
25
  if ( isset($post->ancestors) && in_array($this_menu_item->ID, (array)$post->ancestors) ){
26
  $css[] = 'current_page_ancestor';
@@ -32,7 +106,7 @@ class advancedSidebarMenu{
32
  $css[] = 'current_page_parent';
33
  }
34
  return $css;
35
- }
36
 
37
 
38
 
4
  /**
5
  * These Functions are Specific to the Advanced Sidebar Menu
6
  * @author Mat Lipe
7
+ * @since 4.5.13
8
  */
9
  class advancedSidebarMenu{
10
+ var $instance; //The widget instance
11
+ var $top_id; //Either the top cat or page
12
+ var $exclude;
13
+ var $ancestors; //For the category ancestors
14
+ var $count = 1; //Count for grandchild levels
15
+ var $order_by;
16
+
17
+
18
+ /**
19
+ * The Old way of doing thing which displayed all 3rd levels and below when on a second level page
20
+ * This is only here for people afraid of change who liked the old way of doing things
21
+ *
22
+ * @uses used in views -> page_list.php when legacy mode is checked in widget
23
+ * @since 4.5.13
24
+ */
25
+ function grandChildLegacyMode($pID ){
26
+ #-- if the link that was just listed is the current page we are on
27
+ if( !$this->page_ancestor( $pID ) ) return;
28
+
29
+ //Get the children of this page
30
+ $grandkids = $this->page_children($pID->ID );
31
+ if( $grandkids ){
32
+ #-- Create a new menu with all the children under it
33
+ echo '<ul class="grandchild-sidebar-menu">';
34
+ wp_list_pages("post_type=".$this->post_type."&sort_column=$order_by&title_li=&echo=1&exclude=".$this->instance['exclude']."&child_of=".$pID->ID);
35
+
36
+ echo '</ul>';
37
+ }
38
+ }
39
+
40
+
41
+ /**
42
+ * Displays all the levels of the Grandchild Menus
43
+ *
44
+ * Will run until there are no children left for the current page's hyercy
45
+ * Only displays the pages if we are on a child or grandchild page of the Id sent
46
+ * which at the time of creation comes from the child level pages
47
+ *
48
+ *
49
+ * @uses called by the widget view page_list.php
50
+ * @since 4.0
51
+ */
52
+ function displayGrandChildMenu($page){
53
+ static $count = 1;
54
+ $count++;
55
+
56
+ //If the page sent is not a child of the current page
57
+ if( !$this->page_ancestor($page) ) return;
58
+
59
+ //if there are no children of the current page bail
60
+ if( !$children = $this->page_children($page->ID) ) return;
61
+
62
+ foreach( $children as $child ){
63
+ printf('<ul class="grandchild-sidebar-menu level-%s">',$count );
64
+
65
+ $args = array(
66
+ 'post_type' => $this->post_type,
67
+ 'sort_column' => $this->order_by,
68
+ 'title_li' => '',
69
+ 'echo' => 1,
70
+ 'depth' => 1,
71
+ 'exclude' => join(',',$this->exclude),
72
+ 'include' => $child->ID
73
+ );
74
+
75
+ wp_list_pages($args);
76
+
77
+ //If this newly outputed child is a direct parent of the current page
78
+ if( $this->page_ancestor($child) ){
79
+ $this->displayGrandChildMenu($child);
80
+ }
81
+ echo '</ul>';
82
+ }
83
+
84
+ }
85
+
86
+
87
+
88
 
89
 
90
  /**
94
  * @return array
95
  * @since 10.10.12
96
  */
97
+ function custom_post_type_css($css, $this_menu_item){
98
  global $post;
99
  if ( isset($post->ancestors) && in_array($this_menu_item->ID, (array)$post->ancestors) ){
100
  $css[] = 'current_page_ancestor';
106
  $css[] = 'current_page_parent';
107
  }
108
  return $css;
109
+ }
110
 
111
 
112
 
readme.txt CHANGED
@@ -4,12 +4,12 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypa
4
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
5
  Requires at least: 3.1
6
  Tested up to: 3.5.1
7
- Stable tag: 3.6.2
8
- License: GPLv2
9
 
10
  Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
11
 
12
  == Description ==
 
13
 
14
  Creates a widget for both page and categories that will display the current page/category and an child pages or categories.
15
  Keeps the menu clean and usable.
@@ -21,6 +21,7 @@ Includes Page options:
21
  <li>Include the highest level parent page even with no Children</li>
22
  <li>Use built in styling (very plain styling currently but plans for more advanced in near future versions)</li>
23
  <li>Exclude pages</li>
 
24
  <li>Always display child Pages</li>
25
  <li>Number of levels of child pages to display</li>
26
  </ol>
@@ -37,7 +38,7 @@ Includes Category Options:
37
  <li>Levels of Categories to display</li>
38
  </ol>
39
 
40
- There is also built in functionality to overright the output of the widgets and the css to customize this and still be upgrade safe.
41
 
42
 
43
 
@@ -60,6 +61,19 @@ e.g.
60
 
61
  == Frequently Asked Questions ==
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  = How do you get the categories to display on single post pages? =
64
 
65
  There is a checkbox in the widget options as of version 3.2 that will display the same structure for the categories the post is in.
@@ -87,6 +101,11 @@ You may want to use something like margins to set the levels apart.
87
 
88
 
89
  == Changelog ==
 
 
 
 
 
90
 
91
  = 3.4.0 =
92
  * Added filter support for custom post types
4
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
5
  Requires at least: 3.1
6
  Tested up to: 3.5.1
7
+ Stable tag: 4.0.0
 
8
 
9
  Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
10
 
11
  == Description ==
12
+ <h3>Now Supports an Unlimited Levels of Pages</h3>
13
 
14
  Creates a widget for both page and categories that will display the current page/category and an child pages or categories.
15
  Keeps the menu clean and usable.
21
  <li>Include the highest level parent page even with no Children</li>
22
  <li>Use built in styling (very plain styling currently but plans for more advanced in near future versions)</li>
23
  <li>Exclude pages</li>
24
+ <li>Legacy Mode - For those who like the way it was pre version 4.0</li>
25
  <li>Always display child Pages</li>
26
  <li>Number of levels of child pages to display</li>
27
  </ol>
38
  <li>Levels of Categories to display</li>
39
  </ol>
40
 
41
+ There is also built in functionality to overwrite the output of the widgets and the css to customize this and still be upgrade safe.
42
 
43
 
44
 
61
 
62
  == Frequently Asked Questions ==
63
 
64
+ = Version 4.0 is not displaying all my 3rd and 4th level pages always. How do I bring this back?=
65
+
66
+ You will find a checkbox in the widget options for Legacy Mode.
67
+
68
+ = How do I order my links by title? =
69
+
70
+ Add this to your theme's functions.php file
71
+ <code>add_filter('advanced_sidebar_menu_order_by', 'order_by_post_title' );
72
+ function order_by_post_title($order){
73
+ return 'post_title';
74
+ }
75
+ </code>
76
+
77
  = How do you get the categories to display on single post pages? =
78
 
79
  There is a checkbox in the widget options as of version 3.2 that will display the same structure for the categories the post is in.
101
 
102
 
103
  == Changelog ==
104
+ = 4.0.0 =
105
+ * Added support for an unlimited number of page levels
106
+ * Change structure slightly for future enhancements
107
+ * Added Legacy Mode for backwards compatibility
108
+
109
 
110
  = 3.4.0 =
111
  * Added filter support for custom post types
views/page_list.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * The Ouput of the Advanced Sidebar Page Widget
4
  * @author Mat Lipe
5
- * @since 3.1.13
6
  *
7
  *
8
  * @uses to edit, create a file named page_list.php and put in a folder in the your theme called 'advanced-sidebar-menu
@@ -37,20 +37,15 @@ if( $child_pages ){
37
  #--echo the current page from the $result
38
  wp_list_pages("post_type=".$post_type."&sort_column=$order_by&title_li=&echo=1&depth=1&include=".$pID->ID);
39
  }
40
-
41
- #-- if the link that was just listed is the current page we are on
42
- if( $asm->page_ancestor( $pID ) ){
43
-
44
- //Get the children of this page
45
- $grandkids = $asm->page_children($pID->ID );
46
- if( $grandkids ){
47
- #-- Create a new menu with all the children under it
48
- echo '<ul class="grandchild-sidebar-menu">';
49
- wp_list_pages("post_type=".$post_type."&sort_column=$order_by&title_li=&echo=1&exclude=".$instance['exclude']."&child_of=".$pID->ID);
50
-
51
- echo '</ul>';
52
- }
53
- }
54
  }
55
  }
56
 
2
  /**
3
  * The Ouput of the Advanced Sidebar Page Widget
4
  * @author Mat Lipe
5
+ * @since 4.0.0
6
  *
7
  *
8
  * @uses to edit, create a file named page_list.php and put in a folder in the your theme called 'advanced-sidebar-menu
37
  #--echo the current page from the $result
38
  wp_list_pages("post_type=".$post_type."&sort_column=$order_by&title_li=&echo=1&depth=1&include=".$pID->ID);
39
  }
40
+
41
+ if( !$instance['legacy_mode'] ){
42
+ #-- Displays all levels of granchild pages related to the current page
43
+ $asm->displayGrandChildMenu($pID);
44
+ } else{
45
+ $asm->grandChildLegacyMode($pID);
46
+ }
47
+
48
+
 
 
 
 
 
49
  }
50
  }
51
 
widgets/page.widget.php CHANGED
@@ -5,21 +5,37 @@
5
  * Creates a Widget of parent Child Pages
6
  *
7
  * @author mat lipe
8
- * @since 3.6.13
9
  * @package Advanced Sidebar Menu
10
  *
11
  */
12
-
13
-
14
-
15
  class advanced_sidebar_menu_page extends WP_Widget {
16
 
17
- #-----------------------------------------------------------------------------------------------------------------------------------
18
- // this creates the widget form for the dashboard
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function form( $instance ) {
20
- // require( ADVANCED_SIDEBAR_DIR . 'advanced-sidebar-menu.js' );
21
- ?>
22
-
23
  <p> Title <br>
24
  <input id="<?php echo $this->get_field_name('title'); ?>"
25
  name="<?php echo $this->get_field_name('title'); ?>" size="50" type="text" value="<?php echo $instance['title']; ?>"/></p>
@@ -32,13 +48,17 @@ class advanced_sidebar_menu_page extends WP_Widget {
32
  <p> Include Parent Even With No Children: <input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
33
  name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
34
  <?php echo $instance['include_childless_parent']; ?>/></p>
35
-
36
  <p> Use Built in Styling: <input id="<?php echo $this->get_field_name('css'); ?>"
37
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
38
  <?php echo $instance['css']; ?>/></p>
39
 
40
  <p> Pages to Exclude, Comma Separated: <input id="<?php echo $this->get_field_name('exclude'); ?>"
41
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
 
 
 
 
42
 
43
  <p> Always Display Child Pages: <input id="<?php echo $this->get_field_name('display_all'); ?>"
44
  name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
@@ -62,34 +82,20 @@ class advanced_sidebar_menu_page extends WP_Widget {
62
  }
63
  }
64
  echo '</select></p></span>';
 
 
65
  }
66
 
67
- #------------------------------------------------------------------------------------------------------------------------------
68
- // this allows more than one instance
69
 
 
 
 
 
 
70
  function update( $new_instance, $old_instance ) {
71
- $instance = $old_instance;
72
- $instance['include_childless_parent'] = strip_tags($new_instance['include_childless_parent']);
73
- $instance['include_parent'] = strip_tags($new_instance['include_parent']);
74
- $instance['exclude'] = strip_tags($new_instance['exclude']);
75
- $instance['display_all'] = strip_tags($new_instance['display_all']);
76
- $instance['levels'] = strip_tags($new_instance['levels']);
77
- $instance['css'] = strip_tags($new_instance['css']);
78
- $instance['title'] = strip_tags($new_instance['title']);
79
- return $instance;
80
- }
81
-
82
- #-------------------------------------------------------------------------------------------------------------------------
83
-
84
- // This decides the name of the widget
85
- function advanced_sidebar_menu_page( ) {
86
- /* Widget settings. */
87
- $widget_ops = array( 'classname' => 'advanced-sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' );
88
- $control_ops = array( 'width' => 290 );
89
-
90
- /* Create the widget. */
91
- $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops, $control_ops);
92
- }
93
 
94
 
95
  #---------------------------------------------------------------------------------------------------------------------------
@@ -102,26 +108,30 @@ class advanced_sidebar_menu_page extends WP_Widget {
102
  * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent'
103
  * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter
104
  *
105
- * @since 3.6.13
106
  */
107
  function widget($args, $instance) {
108
  global $wpdb, $post, $table_prefix;
109
  $asm = new advancedSidebarMenu;
110
 
 
111
  extract($args);
112
 
113
  //Filter this one with a 'single' for a custom post type will default to working for pages only
114
  $post_type = apply_filters('advanced_sidebar_menu_post_type', 'page' );
115
-
116
 
117
  if( $post_type != 'page' ){
118
  add_filter('page_css_class', array( $asm, 'custom_post_type_css'), 2, 4 );
119
 
120
  }
121
-
 
122
 
123
  #-- Create a usable array of the excluded pages
124
  $exclude = explode(',', $instance['exclude']);
 
 
125
 
126
  #-- if the post has parents
127
  if($post->ancestors){
@@ -134,10 +144,14 @@ class advanced_sidebar_menu_page extends WP_Widget {
134
 
135
  //Filter for specifying the top parent
136
  $top_parent = apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post );
 
 
137
 
138
  //Filter for specifiying the order by
139
  $order_by = apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post );
140
-
 
 
141
  /**
142
  * Must be done this way to prevent doubling up of pages
143
  */
@@ -146,7 +160,7 @@ class advanced_sidebar_menu_page extends WP_Widget {
146
  //for depreciation
147
  $p = $top_parent;
148
  $result = $child_pages;
149
-
150
  #---- if there are no children do not display the parent unless it is check to do so
151
  if( ($child_pages) || (($instance['include_childless_parent'] == 'checked') && (!in_array($top_parent, $exclude)) ) ){
152
 
@@ -159,7 +173,7 @@ class advanced_sidebar_menu_page extends WP_Widget {
159
 
160
  //Start the menu
161
  echo $before_widget;
162
- $asm->set_widget_vars( $instance, $top_parent, $exclude );
163
  #-- Bring in the view
164
  require( $asm->file_hyercy( 'page_list.php' ) );
165
  echo $after_widget;
5
  * Creates a Widget of parent Child Pages
6
  *
7
  * @author mat lipe
8
+ * @since 4.5.13
9
  * @package Advanced Sidebar Menu
10
  *
11
  */
 
 
 
12
  class advanced_sidebar_menu_page extends WP_Widget {
13
 
14
+ /**
15
+ * Build the widget like a Mo Fo
16
+ *
17
+ * @since 4.5.13
18
+ *
19
+ */
20
+ function __construct() {
21
+ /* Widget settings. */
22
+ $widget_ops = array( 'classname' => 'advanced-sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' );
23
+ $control_ops = array( 'width' => 290 );
24
+
25
+ /* Create the widget. */
26
+ $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops, $control_ops);
27
+ }
28
+
29
+
30
+ /**
31
+ * Output a simple widget Form
32
+ * Not of ton of options here but who need them
33
+ * Most of the magic happens automatically
34
+ *
35
+ * @since 4.5.13
36
+ */
37
  function form( $instance ) {
38
+ ?>
 
 
39
  <p> Title <br>
40
  <input id="<?php echo $this->get_field_name('title'); ?>"
41
  name="<?php echo $this->get_field_name('title'); ?>" size="50" type="text" value="<?php echo $instance['title']; ?>"/></p>
48
  <p> Include Parent Even With No Children: <input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
49
  name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
50
  <?php echo $instance['include_childless_parent']; ?>/></p>
51
+
52
  <p> Use Built in Styling: <input id="<?php echo $this->get_field_name('css'); ?>"
53
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
54
  <?php echo $instance['css']; ?>/></p>
55
 
56
  <p> Pages to Exclude, Comma Separated: <input id="<?php echo $this->get_field_name('exclude'); ?>"
57
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
58
+ <p> Legacy Mode: (displays all 3rd level and down pages when on a second level page) <input id="<?php echo $this->get_field_name('legacy_mode'); ?>"
59
+ name="<?php echo $this->get_field_name('legacy_mode'); ?>" type="checkbox" value="checked"
60
+ <?php echo $instance['legacy_mode']; ?>/>
61
+ </p>
62
 
63
  <p> Always Display Child Pages: <input id="<?php echo $this->get_field_name('display_all'); ?>"
64
  name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
82
  }
83
  }
84
  echo '</select></p></span>';
85
+
86
+
87
  }
88
 
 
 
89
 
90
+ /**
91
+ * Handles the saving of the widget
92
+ *
93
+ * @since 4.5.13
94
+ */
95
  function update( $new_instance, $old_instance ) {
96
+ $new_instance['exclude'] = strip_tags($new_instance['exclude']);
97
+ return $new_instance;
98
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
 
101
  #---------------------------------------------------------------------------------------------------------------------------
108
  * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent'
109
  * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter
110
  *
111
+ * @since 4.5.13
112
  */
113
  function widget($args, $instance) {
114
  global $wpdb, $post, $table_prefix;
115
  $asm = new advancedSidebarMenu;
116
 
117
+ $asm->instance = $instance;
118
  extract($args);
119
 
120
  //Filter this one with a 'single' for a custom post type will default to working for pages only
121
  $post_type = apply_filters('advanced_sidebar_menu_post_type', 'page' );
122
+ $asm->post_type = $post_type;
123
 
124
  if( $post_type != 'page' ){
125
  add_filter('page_css_class', array( $asm, 'custom_post_type_css'), 2, 4 );
126
 
127
  }
128
+
129
+
130
 
131
  #-- Create a usable array of the excluded pages
132
  $exclude = explode(',', $instance['exclude']);
133
+ $asm->exclude = $exclude;
134
+
135
 
136
  #-- if the post has parents
137
  if($post->ancestors){
144
 
145
  //Filter for specifying the top parent
146
  $top_parent = apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post );
147
+ $asm->top_id = $top_parent;
148
+
149
 
150
  //Filter for specifiying the order by
151
  $order_by = apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post );
152
+ $asm->order_by = $order_by;
153
+
154
+
155
  /**
156
  * Must be done this way to prevent doubling up of pages
157
  */
160
  //for depreciation
161
  $p = $top_parent;
162
  $result = $child_pages;
163
+
164
  #---- if there are no children do not display the parent unless it is check to do so
165
  if( ($child_pages) || (($instance['include_childless_parent'] == 'checked') && (!in_array($top_parent, $exclude)) ) ){
166
 
173
 
174
  //Start the menu
175
  echo $before_widget;
176
+
177
  #-- Bring in the view
178
  require( $asm->file_hyercy( 'page_list.php' ) );
179
  echo $after_widget;