Advanced Sidebar Menu - Version 5.0.4

Version Description

Download this release

Release Info

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

Code changes from version 5.0.3 to 5.0.4

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.3
8
  Author URI: http://matlipe.com
9
  */
10
 
11
- define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.0.3' );
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.4
8
  Author URI: http://matlipe.com
9
  */
10
 
11
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.0.4' );
12
 
13
 
14
  #-- Define Constants
classes/Advanced_Sidebar_Menu_Deprecated.php CHANGED
@@ -16,7 +16,9 @@ class Advanced_Sidebar_Menu_Deprecated {
16
  function page_children( $pID ) {
17
  global $wpdb, $table_prefix;
18
 
19
- return $wpdb->get_results( "SELECT ID FROM " . $table_prefix . "posts WHERE post_parent = " . $pID . " AND post_status='publish' ORDER By " . $this->order_by );
 
 
20
 
21
  }
22
 
16
  function page_children( $pID ) {
17
  global $wpdb, $table_prefix;
18
 
19
+ _deprecated_function( 'advancedSidebarMenu::page_children', "5.0.0", 'advancedSidebarMenu::hasChildren' );
20
+
21
+ return $wpdb->get_results( "SELECT ID FROM " . $table_prefix . "posts WHERE post_parent = " . $pID . " AND post_type = $this->post_type AND post_status='publish' ORDER By " . $this->order_by );
22
 
23
  }
24
 
classes/advancedSidebarMenu.php CHANGED
@@ -18,25 +18,46 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
18
  var $order_by;
19
  var $taxonomy; //For filters to override the taxonomy
20
  var $current_term; //Current category or taxonomy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  public $levels = 100;
22
 
23
 
24
  /**
25
- * Check is a page has children by id
26
  *
27
  * @since 8.29.13
28
  *
29
  * @param int $postId
 
 
30
  */
31
- function hasChildren( $postId ) {
32
- if( $this->post_type == 'page' ){
33
- $children = get_pages( "child_of=$postId" );
34
- } else {
35
- $children = get_posts( array(
36
- 'post_type' => $this->post_type,
37
- 'post_parent' => $postId
38
- ) );
39
- }
 
40
  if( count( $children ) != 0 ){
41
  return true;
42
  } else {
18
  var $order_by;
19
  var $taxonomy; //For filters to override the taxonomy
20
  var $current_term; //Current category or taxonomy
21
+
22
+ /**
23
+ * args
24
+ *
25
+ * Widget Args
26
+ *
27
+ * @var array
28
+ */
29
+ public $args = array();
30
+
31
+ /**
32
+ * post_type
33
+ *
34
+ * @var string
35
+ */
36
+ public $post_type = 'page';
37
+
38
+
39
  public $levels = 100;
40
 
41
 
42
  /**
43
+ * Check is a post has children by id
44
  *
45
  * @since 8.29.13
46
  *
47
  * @param int $postId
48
+ *
49
+ * @return bool
50
  */
51
+ function hasChildren( $postId ){
52
+ $args = array(
53
+ 'post_parent' => $postId,
54
+ 'fields' => 'ids',
55
+ 'post_type' => get_post_type( $postId ),
56
+ 'post_status' => 'publish'
57
+ );
58
+
59
+ $children = get_children( $args );
60
+
61
  if( count( $children ) != 0 ){
62
  return true;
63
  } else {
readme.txt CHANGED
@@ -4,8 +4,8 @@ Contributors: Mat Lipe
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&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, heirchy, category menu, pages menu
6
  Requires at least: 3.8.0
7
- Tested up to: 4.1.0
8
- Stable tag: 5.0.3
9
 
10
  Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
11
 
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&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, heirchy, category menu, pages menu
6
  Requires at least: 3.8.0
7
+ Tested up to: 4.1.1
8
+ Stable tag: 5.0.4
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/page.widget.php CHANGED
@@ -1,265 +1,308 @@
1
- <?php
2
- /**
3
- * Advanced Sidebar Menu Page
4
- *
5
- * Creates a Widget of parent Child Pages
6
- *
7
- * @author mat lipe <mat@matlipe.com>
8
- *
9
- * @package Advanced Sidebar Menu
10
- * @class advanced_sidebar_menu_page
11
- *
12
- */
 
 
13
  class advanced_sidebar_menu_page extends WP_Widget {
14
-
15
- private $defaults = array(
16
- 'title' => false,
17
- 'include_parent' => false,
18
- 'include_childless_parent' => false,
19
- 'order_by' => 'menu_order',
20
- 'css' => false,
21
- 'exclude' => false,
22
- 'legacy_mode' => false,
23
- 'display_all' => false,
24
- 'levels' => 1
25
- );
26
-
27
-
28
-
29
- /**
30
- * Build the widget like a BOSS
31
- *
32
- * @since 4.5.13
33
- *
34
- */
35
- function __construct() {
36
- /* Widget settings. */
37
- $widget_ops = array(
38
- 'classname' => 'advanced-sidebar-menu',
39
- 'description' => __('Creates a menu of all the pages using the child/parent relationship', 'advanced-sidebar-menu')
40
  );
41
- $control_ops = array(
42
- 'width' => 290
43
  );
44
 
45
- /* Create the widget. */
46
- $this->WP_Widget( 'advanced_sidebar_menu', __('Advanced Sidebar Pages Menu','advanced-sidebar-menu'), $widget_ops, $control_ops);
47
-
48
- }
49
-
50
-
51
- /**
52
- * Output a simple widget Form
53
- * Not of ton of options here but who need them
54
- * Most of the magic happens automatically
55
- *
56
- * @filters do_action('advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name('parent_only'), $this->get_field_id('parent_only'));
57
- *
58
- * @since 11.4.13
59
- */
60
- function form( $instance ) {
61
-
62
- $instance = wp_parse_args($instance, $this->defaults);
63
-
64
- ?>
65
- <p> <?php _e('Title','advanced-sidebar-menu'); ?> <br>
66
- <input id="<?php echo $this->get_field_id('title'); ?>"
67
- name="<?php echo $this->get_field_name('title'); ?>" class="widefat" type="text" value="<?php echo $instance['title']; ?>"/></p>
68
-
69
- <p> <?php _e('Include Parent Page','advanced-sidebar-menu'); ?>: <input id="<?php echo $this->get_field_id('include_parent'); ?>"
70
- name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
71
- <?php echo $instance['include_parent']; ?>/></p>
72
-
73
-
74
- <p> <?php _e('Include Parent Even With No Children','advanced-sidebar-menu'); ?>: <input id="<?php echo $this->get_field_id('include_childless_parent'); ?>"
75
- name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
76
- <?php echo $instance['include_childless_parent']; ?>/>
77
- </p>
78
-
79
- <p> <?php _e( 'Order By','advanced-sidebar-menu'); ?>: <select id="<?php echo $this->get_field_id('order_by'); ?>"
80
- name="<?php echo $this->get_field_name('order_by'); ?>">
81
- <?php
82
-
83
- $order_by = array(
84
- 'menu_order' => 'Page Order',
85
- 'post_title' => 'Title',
86
- 'post_date' => 'Published Date'
87
- );
88
-
89
- foreach( $order_by as $key => $order ){
90
-
91
- printf('<option value="%s" %s>%s</option>', $key, selected($instance['order_by'], $key, false), $order );
92
- }
93
- ?>
94
- </select>
95
- </p>
96
-
97
- <p> <?php _e("Use this Plugin's Styling",'advanced-sidebar-menu'); ?>: <input id="<?php echo $this->get_field_id('css'); ?>"
98
- name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
99
- <?php echo $instance['css']; ?>/></p>
100
-
101
- <p> <?php _e( "Pages to Exclude (ids), Comma Separated",'advanced-sidebar-menu'); ?>: <input id="<?php echo $this->get_field_id('exclude'); ?>"
102
- name="<?php echo $this->get_field_name('exclude'); ?>" class="widefat" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
103
-
104
- <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'); ?>"
105
- name="<?php echo $this->get_field_name('legacy_mode'); ?>" type="checkbox" value="checked"
106
- <?php echo $instance['legacy_mode']; ?>/>
107
- </p>
108
-
109
- <p> <?php _e( "Always Display Child Pages", 'advanced-sidebar-menu'); ?>: <input id="<?php echo $this->get_field_id('display_all'); ?>"
110
- name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
111
- onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_id('levels'); ?>' )"
112
- <?php echo $instance['display_all']; ?>/></p>
113
-
114
- <span id="levels-<?php echo $this->get_field_id('levels'); ?>" style="<?php
115
- if( $instance['display_all'] == 'checked' ){
116
- echo 'display:block';
117
- } else {
118
- echo 'display:none';
119
- } ?>">
120
- <p> <?php _e("Levels to Display",'advanced-sidebar-menu'); ?>: <select id="<?php echo $this->get_field_id('levels'); ?>"
121
- name="<?php echo $this->get_field_name('levels'); ?>">
122
- <?php
123
- for( $i= 1; $i<6; $i++ ){
124
- if( $i == $instance['levels'] ){
125
- echo '<option value="'.$i.'" selected>'.$i.'</option>';
126
- } else {
127
- echo '<option value="'.$i.'">'.$i.'</option>';
128
- }
129
- }
130
- echo '</select></p></span>';
131
-
132
-
133
- do_action('advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name('parent_only'), $this->get_field_id('parent_only'), $this );
134
-
135
-
136
- do_action('advanced_sidebar_menu_after_widget_form', $instance, $this );
137
-
138
-
139
- }
140
-
141
-
142
- /**
143
- * Handles the saving of the widget
144
- *
145
- * @filters apply_filters('advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance );
146
- *
147
- * @since 4.26.13
148
- */
149
- function update( $newInstance, $oldInstance ) {
150
- $newInstance['exclude'] = strip_tags($newInstance['exclude']);
151
-
152
- $newInstance = apply_filters('advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance );
153
-
154
- return $newInstance;
155
- }
156
-
157
-
158
- #---------------------------------------------------------------------------------------------------------------------------
159
-
160
- /**
161
- * Outputs the page list
162
- * @see WP_Widget::widget()
163
- *
164
- * @uses for custom post types send the type to the filter titled 'advanced_sidebar_menu_post_type'
165
- * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent'
166
- * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter
167
- *
168
- * @filter apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance );
169
- * apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post, $args, $instance );
170
- * apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance );
171
- * apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance );
172
- *
173
- *
174
- *
175
- * @see Geansai - pointed out a notice level error. Thanks Geansai!!
176
- */
177
- function widget($args, $instance) {
178
- global $wpdb, $post, $table_prefix;
179
-
180
- $asm = new advancedSidebarMenu();
181
- $asm->instance = $instance;
182
- $asm->args = $args;
183
-
184
- do_action( 'advanced_sidebar_menu_widget_pre_render', $asm, $this );
185
-
186
- //The excluded pages
187
- $exclude = apply_filters( 'advanced_sidebar_menu_excluded_pages', explode(',', $instance['exclude']), $post, $args, $instance, $asm );
188
- $asm->exclude = $exclude;
189
-
190
- extract($args);
191
-
192
- //Filter this one with a 'single' for a custom post type will default to working for pages only
193
- $post_type = apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance, $asm );
194
- $asm->post_type = $post_type;
195
-
196
- //Add a has_children class to appropriate pages
197
- add_filter( 'page_css_class', array( $asm, 'hasChildrenClass' ), 2, 2 );
198
-
199
- //Add the default classes to pages from a custom post type
200
- if( $asm->post_type != 'page' ){
201
- add_filter( 'page_css_class', array( $asm, 'custom_post_type_css' ), 2, 4 );
202
- }
203
-
204
-
205
- $proper_single = !( is_page() || ( is_single() && $asm->post_type == get_post_type() ) );
206
- //Filter the single post check if try to display the menu somewhere else like a category page
207
- if( apply_filters( 'advanced_sidebar_menu_proper_single', $proper_single, $args, $instance, $asm ) ){
208
- return;
209
  }
210
-
211
-
212
- //Get the Top Parent Id
213
- if($post->ancestors){
214
- $ancestors = $post->ancestors;
215
- $top_parent = end( $ancestors );
216
- } else {
217
- $top_parent = $post->ID;
218
- }
219
- //Filter for specifying the top parent
220
- $top_parent = apply_filters( 'advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance, $asm );
221
- $asm->top_id = $top_parent;
222
-
223
-
224
- //Bail if the parent page does not belong in this menu
225
- if( get_post_type( $asm->top_id ) != $asm->post_type ) return;
226
-
227
-
228
- //Filter for specifiying the order by
229
- $order_by = apply_filters('advanced_sidebar_menu_order_by', $instance['order_by'], $post, $args, $instance, $asm );
230
- $asm->order_by = $order_by;
231
-
232
- /**
233
- * Must be done this way to prevent doubling up of pages
234
- */
235
- $child_pages = $wpdb->get_results( "SELECT ID FROM ". $wpdb->posts ." WHERE post_parent = $top_parent AND post_status='publish' AND post_type='$post_type' Order by $order_by" );
236
-
237
- //for depreciation
238
- $p = $top_parent;
239
- $result = $child_pages = apply_filters( 'advanced_sidebar_menu_child_pages', $child_pages, $post, $args, $instance, $asm );
240
-
241
- #---- if there are no children do not display the parent unless it is check to do so
242
- if( (!empty($child_pages)) || $asm->checked('include_childless_parent') && (!in_array($top_parent, $exclude) ) ){
243
-
244
- $legacy = $asm->checked('legacy_mode');
245
-
246
- if( $asm->checked('css') ){
247
- echo '<style type="text/css">';
248
- include( $asm->file_hyercy('sidebar-menu.css', $legacy ) );
249
- echo '</style>';
250
- }
251
-
252
-
253
- //Start the menu
254
- echo $before_widget;
255
- #-- Bring in the
256
- $content = '';
257
- require( $asm->file_hyercy( 'page_list.php', $legacy ) );
258
- echo apply_filters('advanced_sidebar_menu_page_widget_output', $content, $args, $instance );
259
- echo $after_widget;
260
-
261
- }
262
-
263
- } #== /widget()
264
-
265
- } #== /Clas
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Advanced Sidebar Menu Page
6
+ *
7
+ * Creates a Widget of parent Child Pages
8
+ *
9
+ * @author mat lipe <mat@matlipe.com>
10
+ *
11
+ * @package Advanced Sidebar Menu
12
+ * @class advanced_sidebar_menu_page
13
+ *
14
+ */
15
  class advanced_sidebar_menu_page extends WP_Widget {
16
+
17
+ private $defaults = array(
18
+ 'title' => false,
19
+ 'include_parent' => false,
20
+ 'include_childless_parent' => false,
21
+ 'order_by' => 'menu_order',
22
+ 'css' => false,
23
+ 'exclude' => false,
24
+ 'legacy_mode' => false,
25
+ 'display_all' => false,
26
+ 'levels' => 1
27
+ );
28
+
29
+
30
+ /**
31
+ * Build the widget like a BOSS
32
+ *
33
+ * @since 4.5.13
34
+ *
35
+ */
36
+ function __construct(){
37
+ /* Widget settings. */
38
+ $widget_ops = array(
39
+ 'classname' => 'advanced-sidebar-menu',
40
+ 'description' => __( 'Creates a menu of all the pages using the child/parent relationship', 'advanced-sidebar-menu' )
 
41
  );
42
+ $control_ops = array(
43
+ 'width' => 290
44
  );
45
 
46
+ /* Create the widget. */
47
+ $this->WP_Widget( 'advanced_sidebar_menu', __( 'Advanced Sidebar Pages Menu', 'advanced-sidebar-menu' ), $widget_ops, $control_ops );
48
+
49
+ }
50
+
51
+
52
+ /**
53
+ * Output a simple widget Form
54
+ * Not of ton of options here but who need them
55
+ * Most of the magic happens automatically
56
+ *
57
+ * @filters do_action('advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name('parent_only'), $this->get_field_id('parent_only'));
58
+ *
59
+ * @since 11.4.13
60
+ */
61
+ function form( $instance ){
62
+
63
+ $instance = wp_parse_args( $instance, $this->defaults );
64
+
65
+ ?>
66
+ <p> <?php _e( 'Title', 'advanced-sidebar-menu' ); ?>
67
+ <br>
68
+ <input id="<?php echo $this->get_field_id( 'title' ); ?>"
69
+ name="<?php echo $this->get_field_name( 'title' ); ?>" class="widefat" type="text" value="<?php echo $instance[ 'title' ]; ?>"/>
70
+ </p>
71
+
72
+ <p> <?php _e( 'Include Parent Page', 'advanced-sidebar-menu' ); ?>:
73
+ <input id="<?php echo $this->get_field_id( 'include_parent' ); ?>"
74
+ name="<?php echo $this->get_field_name( 'include_parent' ); ?>" type="checkbox" value="checked"
75
+ <?php echo $instance[ 'include_parent' ]; ?>/>
76
+ </p>
77
+
78
+
79
+ <p> <?php _e( 'Include Parent Even With No Children', 'advanced-sidebar-menu' ); ?>:
80
+ <input id="<?php echo $this->get_field_id( 'include_childless_parent' ); ?>"
81
+ name="<?php echo $this->get_field_name( 'include_childless_parent' ); ?>" type="checkbox" value="checked"
82
+ <?php echo $instance[ 'include_childless_parent' ]; ?>/>
83
+ </p>
84
+
85
+ <p> <?php _e( 'Order By', 'advanced-sidebar-menu' ); ?>:
86
+ <select id="<?php echo $this->get_field_id( 'order_by' ); ?>"
87
+ name="<?php echo $this->get_field_name( 'order_by' ); ?>">
88
+ <?php
89
+
90
+ $order_by = array(
91
+ 'menu_order' => 'Page Order',
92
+ 'post_title' => 'Title',
93
+ 'post_date' => 'Published Date'
94
+ );
95
+
96
+ foreach( $order_by as $key => $order ){
97
+
98
+ printf( '<option value="%s" %s>%s</option>', $key, selected( $instance[ 'order_by' ], $key, false ), $order );
99
+ }
100
+ ?>
101
+ </select>
102
+ </p>
103
+
104
+ <p> <?php _e( "Use this Plugin's Styling", 'advanced-sidebar-menu' ); ?>:
105
+ <input id="<?php echo $this->get_field_id( 'css' ); ?>"
106
+ name="<?php echo $this->get_field_name( 'css' ); ?>" type="checkbox" value="checked"
107
+ <?php echo $instance[ 'css' ]; ?>/>
108
+ </p>
109
+
110
+ <p> <?php _e( "Pages to Exclude (ids), Comma Separated", 'advanced-sidebar-menu' ); ?>:
111
+ <input id="<?php echo $this->get_field_id( 'exclude' ); ?>"
112
+ name="<?php echo $this->get_field_name( 'exclude' ); ?>" class="widefat" type="text" value="<?php echo $instance[ 'exclude' ]; ?>"/>
113
+ </p>
114
+
115
+ <p> <?php _e( "Legacy Mode: (use pre 4.0 structure and css)", 'advanced-sidebar-menu' ); ?>
116
+ <input id="<?php echo $this->get_field_name( 'legacy_mode' ); ?>"
117
+ name="<?php echo $this->get_field_name( 'legacy_mode' ); ?>" type="checkbox" value="checked"
118
+ <?php echo $instance[ 'legacy_mode' ]; ?>/>
119
+ </p>
120
+
121
+ <p> <?php _e( "Always Display Child Pages", 'advanced-sidebar-menu' ); ?>:
122
+ <input id="<?php echo $this->get_field_id( 'display_all' ); ?>"
123
+ name="<?php echo $this->get_field_name( 'display_all' ); ?>" type="checkbox" value="checked"
124
+ onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_id( 'levels' ); ?>' )"
125
+ <?php echo $instance[ 'display_all' ]; ?>/>
126
+ </p>
127
+
128
+ <span id="levels-<?php echo $this->get_field_id( 'levels' ); ?>" style="<?php
129
+ if( $instance[ 'display_all' ] == 'checked' ){
130
+ echo 'display:block';
131
+ } else {
132
+ echo 'display:none';
133
+ } ?>">
134
+ <p> <?php _e( "Levels to Display", 'advanced-sidebar-menu' ); ?>:
135
+ <select id="<?php echo $this->get_field_id( 'levels' ); ?>"
136
+ name="<?php echo $this->get_field_name( 'levels' ); ?>">
137
+ <?php
138
+ for( $i = 1; $i < 6; $i ++ ){
139
+ if( $i == $instance[ 'levels' ] ){
140
+ echo '<option value="' . $i . '" selected>' . $i . '</option>';
141
+ } else {
142
+ echo '<option value="' . $i . '">' . $i . '</option>';
143
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
145
+ echo '</select></p></span>';
146
+
147
+ do_action( 'advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name( 'parent_only' ), $this->get_field_id( 'parent_only' ), $this );
148
+
149
+ do_action( 'advanced_sidebar_menu_after_widget_form', $instance, $this );
150
+
151
+
152
+ }
153
+
154
+
155
+ /**
156
+ * Handles the saving of the widget
157
+ *
158
+ * @filters apply_filters('advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance );
159
+ *
160
+ * @since 4.26.13
161
+ */
162
+ function update( $newInstance, $oldInstance ){
163
+ $newInstance[ 'exclude' ] = strip_tags( $newInstance[ 'exclude' ] );
164
+
165
+ $newInstance = apply_filters( 'advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance );
166
+
167
+ return $newInstance;
168
+ }
169
+
170
+
171
+ #---------------------------------------------------------------------------------------------------------------------------
172
+
173
+ /**
174
+ * Outputs the page list
175
+ *
176
+ * @see WP_Widget::widget()
177
+ *
178
+ * @uses for custom post types send the type to the filter titled 'advanced_sidebar_menu_post_type'
179
+ * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent'
180
+ * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter
181
+ *
182
+ * @filter apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance );
183
+ * apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post, $args, $instance );
184
+ * apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance );
185
+ * apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance );
186
+ *
187
+ *
188
+ *
189
+ * @see Geansai - pointed out a notice level error. Thanks Geansai!!
190
+ */
191
+ function widget( $args, $instance ){
192
+ global $post;
193
+
194
+ $asm = new advancedSidebarMenu();
195
+ $asm->instance = $instance;
196
+ $asm->args = $args;
197
+ $asm->exclude = apply_filters( 'advanced_sidebar_menu_excluded_pages', explode( ',', $instance[ 'exclude' ] ), $post, $asm->args, $asm->instance, $asm );
198
+
199
+ do_action( 'advanced_sidebar_menu_widget_pre_render', $asm, $this );
200
+
201
+ extract( $args );
202
+
203
+ $filter_args = array(
204
+ 1 => $asm->args,
205
+ 2 => $asm->instance,
206
+ 3 => $asm
207
+ );
208
+
209
+ $filter_args[ 0 ] = 'page';
210
+ $asm->post_type = $post_type = apply_filters_ref_array( 'advanced_sidebar_menu_post_type', $filter_args );
211
+
212
+ add_filter( 'page_css_class', array( $asm, 'hasChildrenClass' ), 2, 2 );
213
+ if( $asm->post_type != 'page' ){
214
+ add_filter( 'page_css_class', array( $asm, 'custom_post_type_css' ), 2, 4 );
215
+ }
216
+
217
+ $proper_single = !( is_page() || ( is_single() && $asm->post_type == get_post_type() ) );
218
+ $filter_args[ 0 ] = $proper_single;
219
+ if( apply_filters_ref_array( 'advanced_sidebar_menu_proper_single', $filter_args ) ){
220
+ return;
221
+ }
222
+
223
+ if( $post->ancestors ){
224
+ $ancestors = $post->ancestors;
225
+ $top_parent = end( $ancestors );
226
+ } else {
227
+ $top_parent = $post->ID;
228
+ }
229
+
230
+ $filter_args[ 0 ] = $top_parent;
231
+ $asm->top_id = $top_parent = apply_filters_ref_array( 'advanced_sidebar_menu_top_parent', $filter_args );
232
+ if( get_post_type( $asm->top_id ) != $asm->post_type ){
233
+ return;
234
+ }
235
+
236
+ unset( $filter_args[ 0 ] );
237
+ array_unshift( $filter_args, $post );
238
+ array_unshift( $filter_args, $instance[ 'order_by' ] );
239
+
240
+ $asm->order_by = $order_by = apply_filters_ref_array( 'advanced_sidebar_menu_order_by', $filter_args );
241
+
242
+ $child_pages = $this->get_child_pages( $asm, $filter_args );
243
+
244
+ #---- if there are no children do not display the parent unless it is check to do so
245
+ if( ( !empty( $child_pages ) ) || $asm->checked( 'include_childless_parent' ) && ( !in_array( $top_parent, $asm->exclude ) ) ){
246
+
247
+ $legacy = $asm->checked( 'legacy_mode' );
248
+
249
+ if( $asm->checked( 'css' ) ){
250
+ echo '<style type="text/css">';
251
+ include( $asm->file_hyercy( 'sidebar-menu.css', $legacy ) );
252
+ echo '</style>';
253
+ }
254
+
255
+ echo $before_widget;
256
+ $content = '';
257
+ require( $asm->file_hyercy( 'page_list.php', $legacy ) );
258
+ echo apply_filters( 'advanced_sidebar_menu_page_widget_output', $content, $args, $instance );
259
+ echo $after_widget;
260
+
261
+ }
262
+
263
+ }
264
+
265
+
266
+ /**
267
+ * get_child_pages
268
+ *
269
+ * Get the children's ids of the top level parent
270
+ *
271
+ * @param advancedSidebarMenu $asm
272
+ * @param array $filter_args
273
+ *
274
+ * @filter advanced_sidebar_menu_child_pages
275
+ *
276
+ * @return mixed
277
+ */
278
+ private function get_child_pages( $asm, $filter_args ){
279
+ global $wpdb;
280
+ $_excluded = '';
281
+
282
+ if( !empty( $asm->exclude ) ){
283
+ $asm->exclude = array_filter( $asm->exclude );
284
+ if( !empty( $asm->exclude ) ){
285
+ foreach( $asm->exclude as $k => $_exclude ){
286
+ $asm->exclude[ $k ] = (int) $_exclude;
287
+ }
288
+ $_excluded = "AND ID NOT IN (" . implode( ',', $asm->exclude ) . ")";
289
+ }
290
+ }
291
+
292
+ $query = "SELECT ID FROM $wpdb->posts
293
+ WHERE post_parent = $asm->top_id
294
+ AND post_status='publish'
295
+ AND post_type='$asm->post_type'
296
+ $_excluded
297
+ Order by $asm->order_by";
298
+
299
+ $child_pages = $wpdb->get_col( $query );
300
+
301
+ $filter_args[ 0 ] = $child_pages;
302
+ $child_pages = apply_filters_ref_array( 'advanced_sidebar_menu_child_pages', $filter_args );
303
+
304
+ return $child_pages;
305
+
306
+ }
307
+
308
+ }