Version Description
Download this release
Release Info
Developer | Mat Lipe |
Plugin | Advanced Sidebar Menu |
Version | 5.1.1 |
Comparing to | |
See all releases |
Code changes from version 5.0.9 to 5.1.1
- advanced-sidebar-menu.php +17 -11
- classes/Advanced_Sidebar_Menu_Cache.php +122 -0
- classes/Advanced_Sidebar_Menu_List_Pages.php +21 -3
- classes/advancedSidebarMenu.php +74 -49
- legacy/page_list.php +1 -1
- readme.txt +13 -10
- widgets/page.widget.php +28 -26
advanced-sidebar-menu.php
CHANGED
@@ -4,12 +4,12 @@ Plugin Name: Advanced Sidebar Menu
|
|
4 |
Plugin URI: https://matlipe.com/advanced-sidebar-menu/
|
5 |
Description: Creates dynamic menu based on child/parent relationship.
|
6 |
Author: Mat Lipe
|
7 |
-
Version: 5.
|
8 |
Author URI: https://matlipe.com
|
9 |
Text Domain: advanced-sidebar-menu
|
10 |
*/
|
11 |
|
12 |
-
define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.
|
13 |
|
14 |
|
15 |
#-- Define Constants
|
@@ -19,14 +19,21 @@ define( 'ADVANCED_SIDEBAR_VIEWS_DIR', ADVANCED_SIDEBAR_DIR . 'views/' );
|
|
19 |
define( 'ADVANCED_SIDEBAR_LEGACY_DIR', ADVANCED_SIDEBAR_DIR . 'legacy/' );
|
20 |
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
require( ADVANCED_SIDEBAR_DIR.'classes/Advanced_Sidebar_Menu_Deprecated.php' );
|
26 |
-
require( ADVANCED_SIDEBAR_DIR.'classes/advancedSidebarMenu.php' );
|
27 |
-
require( ADVANCED_SIDEBAR_DIR.'classes/Advanced_Sidebar_Menu_Page_Walker.php' );
|
28 |
-
require( ADVANCED_SIDEBAR_DIR.'classes/Advanced_Sidebar_Menu_List_Pages.php' );
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
#-- Translate
|
32 |
add_action('plugins_loaded', 'advanced_sidebar_menu_translate' );
|
@@ -35,7 +42,6 @@ function advanced_sidebar_menu_translate(){
|
|
35 |
}
|
36 |
|
37 |
|
38 |
-
|
39 |
#-- Bring in the JQuery
|
40 |
add_action('admin_print_scripts', 'advanced_sidebar_menu_script');
|
41 |
function advanced_sidebar_menu_script() {
|
4 |
Plugin URI: https://matlipe.com/advanced-sidebar-menu/
|
5 |
Description: Creates dynamic menu based on child/parent relationship.
|
6 |
Author: Mat Lipe
|
7 |
+
Version: 5.1.1
|
8 |
Author URI: https://matlipe.com
|
9 |
Text Domain: advanced-sidebar-menu
|
10 |
*/
|
11 |
|
12 |
+
define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '5.1.1' );
|
13 |
|
14 |
|
15 |
#-- Define Constants
|
19 |
define( 'ADVANCED_SIDEBAR_LEGACY_DIR', ADVANCED_SIDEBAR_DIR . 'legacy/' );
|
20 |
|
21 |
|
22 |
+
if( !function_exists( 'advanced_sidebar_menu_load' ) ){
|
23 |
+
function advanced_sidebar_menu_load(){
|
24 |
+
require( ADVANCED_SIDEBAR_WIDGETS_DIR . 'init.php' );
|
25 |
+
require( ADVANCED_SIDEBAR_DIR . 'classes/Advanced_Sidebar_Menu_Deprecated.php' );
|
26 |
+
require( ADVANCED_SIDEBAR_DIR . 'classes/advancedSidebarMenu.php' );
|
27 |
+
require( ADVANCED_SIDEBAR_DIR . 'classes/Advanced_Sidebar_Menu_Page_Walker.php' );
|
28 |
+
require( ADVANCED_SIDEBAR_DIR . 'classes/Advanced_Sidebar_Menu_List_Pages.php' );
|
29 |
+
require( ADVANCED_SIDEBAR_DIR . 'classes/Advanced_Sidebar_Menu_Cache.php' );
|
30 |
+
|
31 |
+
Advanced_Sidebar_Menu_Cache::init();
|
32 |
+
$asm = new advancedSidebarMenu();
|
33 |
+
}
|
34 |
+
add_action( 'plugins_loaded', 'advanced_sidebar_menu_load' );
|
35 |
+
|
36 |
+
}
|
37 |
|
38 |
#-- Translate
|
39 |
add_action('plugins_loaded', 'advanced_sidebar_menu_translate' );
|
42 |
}
|
43 |
|
44 |
|
|
|
45 |
#-- Bring in the JQuery
|
46 |
add_action('admin_print_scripts', 'advanced_sidebar_menu_script');
|
47 |
function advanced_sidebar_menu_script() {
|
classes/Advanced_Sidebar_Menu_Cache.php
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Advanced_Sidebar_Menu_Cache
|
6 |
+
*
|
7 |
+
* @author Mat Lipe
|
8 |
+
* @since 12/19/2015
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
class Advanced_Sidebar_Menu_Cache {
|
12 |
+
const CACHE_GROUP = 'advanced-sidebar-menu';
|
13 |
+
const CHILD_PAGES_KEY = 'child-pages';
|
14 |
+
|
15 |
+
private function __construct(){
|
16 |
+
$this->hooks();
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
private function hooks(){
|
21 |
+
add_action( 'save_post', array( $this, 'clear_cache_group' ) );
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Clear all of items in this cache group
|
27 |
+
*
|
28 |
+
* @return void
|
29 |
+
*/
|
30 |
+
public function clear_cache_group(){
|
31 |
+
wp_cache_delete( self::CHILD_PAGES_KEY, self::CACHE_GROUP );
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Retrieve a posts child pages from the cache
|
37 |
+
* If no exist in the cache will return false
|
38 |
+
*
|
39 |
+
* @param advancedSidebarMenu|Advanced_Sidebar_Menu_List_Pages $class
|
40 |
+
*
|
41 |
+
* @return array|false
|
42 |
+
*/
|
43 |
+
public function get_child_pages( $class ){
|
44 |
+
$key = $this->get_key_from_asm( $class );
|
45 |
+
$all_child_pages = (array)wp_cache_get( self::CHILD_PAGES_KEY, self::CACHE_GROUP );
|
46 |
+
if( isset( $all_child_pages[ $key ] ) ){
|
47 |
+
return $all_child_pages[ $key ];
|
48 |
+
} else {
|
49 |
+
return false;
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Add a post and its children to the cache
|
56 |
+
* Uses a global key for all posts so this appends to an array
|
57 |
+
*
|
58 |
+
* @param advancedSidebarMenu|Advanced_Sidebar_Menu_List_Pages $class
|
59 |
+
* @param array $child_pages
|
60 |
+
*
|
61 |
+
* @return void
|
62 |
+
*/
|
63 |
+
public function add_child_pages( $class, $child_pages ){
|
64 |
+
$key = $this->get_key_from_asm( $class );
|
65 |
+
$all_child_pages = (array)wp_cache_get( self::CHILD_PAGES_KEY, self::CACHE_GROUP );
|
66 |
+
$all_child_pages[ $key ] = $child_pages;
|
67 |
+
wp_cache_set( self::CHILD_PAGES_KEY, $all_child_pages, self::CACHE_GROUP );
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
* There are many possibilities for properties
|
73 |
+
* set to the object used for generations.
|
74 |
+
* To guarantee we have a unique id for the cache
|
75 |
+
* we serialize the whole object and hash it
|
76 |
+
*
|
77 |
+
*
|
78 |
+
* @param advancedSidebarMenu|Advanced_Sidebar_Menu_List_Pages $class
|
79 |
+
*
|
80 |
+
* @return string
|
81 |
+
*/
|
82 |
+
private function get_key_from_asm( $class ){
|
83 |
+
$string = serialize( $class );
|
84 |
+
$hash = md5( $string );
|
85 |
+
return $hash;
|
86 |
+
}
|
87 |
+
|
88 |
+
|
89 |
+
//********** SINGLETON FUNCTIONS **********/
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Instance of this class for use as singleton
|
93 |
+
*/
|
94 |
+
private static $instance;
|
95 |
+
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Create the instance of the class
|
99 |
+
*
|
100 |
+
* @static
|
101 |
+
* @return void
|
102 |
+
*/
|
103 |
+
public static function init(){
|
104 |
+
self::$instance = self::get_instance();
|
105 |
+
}
|
106 |
+
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Get (and instantiate, if necessary) the instance of the
|
110 |
+
* class
|
111 |
+
*
|
112 |
+
* @static
|
113 |
+
* @return self
|
114 |
+
*/
|
115 |
+
public static function get_instance(){
|
116 |
+
if( !is_a( self::$instance, __CLASS__ ) ){
|
117 |
+
self::$instance = new self();
|
118 |
+
}
|
119 |
+
|
120 |
+
return self::$instance;
|
121 |
+
}
|
122 |
+
}
|
classes/Advanced_Sidebar_Menu_List_Pages.php
CHANGED
@@ -76,6 +76,15 @@ class Advanced_Sidebar_Menu_List_Pages{
|
|
76 |
*/
|
77 |
private $level = 0;
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
/**
|
81 |
* Constructor
|
@@ -239,10 +248,19 @@ class Advanced_Sidebar_Menu_List_Pages{
|
|
239 |
* @return array
|
240 |
*/
|
241 |
public function get_child_pages( $parent_page_id ) {
|
242 |
-
$
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
-
return
|
246 |
|
247 |
}
|
248 |
|
76 |
*/
|
77 |
private $level = 0;
|
78 |
|
79 |
+
/**
|
80 |
+
* Used exclusively for caching
|
81 |
+
* Holds the value of the latest parent we
|
82 |
+
* retrieve children for
|
83 |
+
*
|
84 |
+
* @var int
|
85 |
+
*/
|
86 |
+
private $current_children_parent = 0;
|
87 |
+
|
88 |
|
89 |
/**
|
90 |
* Constructor
|
248 |
* @return array
|
249 |
*/
|
250 |
public function get_child_pages( $parent_page_id ) {
|
251 |
+
$this->current_children_parent = $parent_page_id;
|
252 |
+
|
253 |
+
$cache = Advanced_Sidebar_Menu_Cache::get_instance();
|
254 |
+
$child_pages = $cache->get_child_pages( $this );
|
255 |
+
if( $child_pages === false ){
|
256 |
+
$args = $this->args;
|
257 |
+
$args[ 'parent' ] = $this->current_children_parent;
|
258 |
+
$child_pages = get_pages( $args );
|
259 |
+
|
260 |
+
$cache->add_child_pages( $this, $child_pages );
|
261 |
+
}
|
262 |
|
263 |
+
return $child_pages;
|
264 |
|
265 |
}
|
266 |
|
classes/advancedSidebarMenu.php
CHANGED
@@ -12,7 +12,7 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
12 |
|
13 |
var $instance; //The widget instance
|
14 |
var $top_id; //Either the top cat or page
|
15 |
-
var $exclude;
|
16 |
var $ancestors; //For the category ancestors
|
17 |
var $count = 1; //Count for grandchild levels
|
18 |
var $order_by;
|
@@ -35,35 +35,28 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
35 |
*/
|
36 |
public $post_type = 'page';
|
37 |
|
38 |
-
|
39 |
public $levels = 100;
|
40 |
|
41 |
|
42 |
/**
|
43 |
-
* Check is a post has children
|
44 |
-
*
|
45 |
-
* @since 8.29.13
|
46 |
*
|
47 |
-
* @param int $
|
48 |
*
|
49 |
* @return bool
|
50 |
*/
|
51 |
-
function
|
52 |
$args = array(
|
53 |
-
'post_parent' => $
|
54 |
-
'fields'
|
55 |
-
'post_type'
|
56 |
-
'post_status' => 'publish'
|
|
|
57 |
);
|
58 |
|
59 |
-
$children
|
60 |
-
|
61 |
-
if( count( $children ) != 0 ){
|
62 |
-
return true;
|
63 |
-
} else {
|
64 |
-
return false;
|
65 |
-
}
|
66 |
|
|
|
67 |
}
|
68 |
|
69 |
|
@@ -145,52 +138,44 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
145 |
}
|
146 |
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
/**
|
152 |
* Adds the class for any menu item with children
|
153 |
*
|
154 |
-
* @param array $
|
155 |
-
* @param
|
156 |
-
*
|
157 |
-
*
|
158 |
-
* @since 8.29.13
|
159 |
*
|
160 |
* @return array
|
161 |
*/
|
162 |
-
function
|
163 |
-
if( $this->
|
164 |
-
$
|
165 |
}
|
166 |
|
167 |
-
return $
|
168 |
-
|
169 |
}
|
170 |
|
171 |
|
172 |
/**
|
173 |
* Adds the class for current page item etc to the page list when using a custom post type
|
174 |
*
|
175 |
-
* @param array
|
176 |
-
* @param
|
177 |
*
|
178 |
* @return array
|
179 |
-
* @since 10.10.12
|
180 |
*/
|
181 |
-
function custom_post_type_css( $
|
182 |
global $post;
|
183 |
if( isset( $post->ancestors ) && in_array( $this_menu_item->ID, (array)$post->ancestors ) ){
|
184 |
-
$
|
185 |
}
|
186 |
if( $this_menu_item->ID == $post->ID ){
|
187 |
-
$
|
188 |
|
189 |
} elseif( $this_menu_item->ID == $post->post_parent ) {
|
190 |
-
$
|
191 |
}
|
192 |
|
193 |
-
return $
|
194 |
}
|
195 |
|
196 |
|
@@ -198,7 +183,7 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
198 |
*
|
199 |
* IF this is a top level category
|
200 |
*
|
201 |
-
* @param
|
202 |
*
|
203 |
* @since 6.13.13
|
204 |
*/
|
@@ -218,16 +203,14 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
218 |
/**
|
219 |
* If the cat is a second level cat
|
220 |
*
|
221 |
-
* @param
|
222 |
*
|
223 |
* @since 6.13.13
|
224 |
*/
|
225 |
function second_level_cat( $cat ) {
|
226 |
|
227 |
-
//if this is the
|
228 |
if( $cat->term_id == $this->current_term || in_array( $cat->term_id, $this->ancestors ) ){
|
229 |
-
|
230 |
-
$all_children = array();
|
231 |
$all_children = get_terms( $this->taxonomy, array( 'child_of' => $cat->term_id, 'fields' => 'ids' ) );
|
232 |
if( !empty( $all_children ) ){
|
233 |
$return = true;
|
@@ -252,7 +235,6 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
252 |
* @return bool
|
253 |
*/
|
254 |
function display_all() {
|
255 |
-
|
256 |
return $this->checked( 'display_all' );
|
257 |
}
|
258 |
|
@@ -264,7 +246,6 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
264 |
* @return bool
|
265 |
*/
|
266 |
function include_parent() {
|
267 |
-
|
268 |
if( !$this->checked( 'include_parent' ) ){
|
269 |
return false;
|
270 |
}
|
@@ -297,15 +278,28 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
297 |
}
|
298 |
|
299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
/**
|
301 |
*
|
302 |
* Checks is this id is excluded or not
|
303 |
*
|
304 |
-
* @param int $id
|
305 |
*
|
306 |
* @return bool
|
307 |
*/
|
308 |
-
function
|
309 |
if( !in_array( $id, $this->exclude ) ){
|
310 |
return true;
|
311 |
} else {
|
@@ -315,7 +309,7 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
315 |
|
316 |
|
317 |
/**
|
318 |
-
* Allows for
|
319 |
*
|
320 |
* @since 4.23.13
|
321 |
*
|
@@ -335,5 +329,36 @@ class advancedSidebarMenu extends Advanced_Sidebar_Menu_Deprecated {
|
|
335 |
|
336 |
}
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
} //End class
|
339 |
|
12 |
|
13 |
var $instance; //The widget instance
|
14 |
var $top_id; //Either the top cat or page
|
15 |
+
var $exclude = array();
|
16 |
var $ancestors; //For the category ancestors
|
17 |
var $count = 1; //Count for grandchild levels
|
18 |
var $order_by;
|
35 |
*/
|
36 |
public $post_type = 'page';
|
37 |
|
|
|
38 |
public $levels = 100;
|
39 |
|
40 |
|
41 |
/**
|
42 |
+
* Check is a post has children
|
|
|
|
|
43 |
*
|
44 |
+
* @param int $post_id
|
45 |
*
|
46 |
* @return bool
|
47 |
*/
|
48 |
+
function has_children( $post_id ){
|
49 |
$args = array(
|
50 |
+
'post_parent' => $post_id,
|
51 |
+
'fields' => 'ids',
|
52 |
+
'post_type' => get_post_type( $post_id ),
|
53 |
+
'post_status' => 'publish',
|
54 |
+
'numberposts' => 1,
|
55 |
);
|
56 |
|
57 |
+
$children = get_children( $args );
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
return !empty( $children );
|
60 |
}
|
61 |
|
62 |
|
138 |
}
|
139 |
|
140 |
|
|
|
|
|
|
|
141 |
/**
|
142 |
* Adds the class for any menu item with children
|
143 |
*
|
144 |
+
* @param array $classes the current css classes
|
145 |
+
* @param \WP_Post $page the page being checked
|
|
|
|
|
|
|
146 |
*
|
147 |
* @return array
|
148 |
*/
|
149 |
+
public function add_has_children_class( $classes, $page ) {
|
150 |
+
if( $this->has_children( $page->ID ) ){
|
151 |
+
$classes[] = 'has_children';
|
152 |
}
|
153 |
|
154 |
+
return $classes;
|
|
|
155 |
}
|
156 |
|
157 |
|
158 |
/**
|
159 |
* Adds the class for current page item etc to the page list when using a custom post type
|
160 |
*
|
161 |
+
* @param array $classes the current css classes
|
162 |
+
* @param \WP_Post $this_menu_item the page being checked
|
163 |
*
|
164 |
* @return array
|
|
|
165 |
*/
|
166 |
+
function custom_post_type_css( $classes, $this_menu_item ) {
|
167 |
global $post;
|
168 |
if( isset( $post->ancestors ) && in_array( $this_menu_item->ID, (array)$post->ancestors ) ){
|
169 |
+
$classes[ ] = 'current_page_ancestor';
|
170 |
}
|
171 |
if( $this_menu_item->ID == $post->ID ){
|
172 |
+
$classes[ ] = 'current_page_item';
|
173 |
|
174 |
} elseif( $this_menu_item->ID == $post->post_parent ) {
|
175 |
+
$classes[ ] = 'current_page_parent';
|
176 |
}
|
177 |
|
178 |
+
return $classes;
|
179 |
}
|
180 |
|
181 |
|
183 |
*
|
184 |
* IF this is a top level category
|
185 |
*
|
186 |
+
* @param \WP_Term $cat the cat object
|
187 |
*
|
188 |
* @since 6.13.13
|
189 |
*/
|
203 |
/**
|
204 |
* If the cat is a second level cat
|
205 |
*
|
206 |
+
* @param \WP_Term $cat the cat
|
207 |
*
|
208 |
* @since 6.13.13
|
209 |
*/
|
210 |
function second_level_cat( $cat ) {
|
211 |
|
212 |
+
//if this is the current cat or a parent of the current cat
|
213 |
if( $cat->term_id == $this->current_term || in_array( $cat->term_id, $this->ancestors ) ){
|
|
|
|
|
214 |
$all_children = get_terms( $this->taxonomy, array( 'child_of' => $cat->term_id, 'fields' => 'ids' ) );
|
215 |
if( !empty( $all_children ) ){
|
216 |
$return = true;
|
235 |
* @return bool
|
236 |
*/
|
237 |
function display_all() {
|
|
|
238 |
return $this->checked( 'display_all' );
|
239 |
}
|
240 |
|
246 |
* @return bool
|
247 |
*/
|
248 |
function include_parent() {
|
|
|
249 |
if( !$this->checked( 'include_parent' ) ){
|
250 |
return false;
|
251 |
}
|
278 |
}
|
279 |
|
280 |
|
281 |
+
/**
|
282 |
+
* Retrieve the excluded items' ids
|
283 |
+
*
|
284 |
+
* @return array
|
285 |
+
*/
|
286 |
+
public function get_excluded_ids(){
|
287 |
+
$excluded = $this->exclude;
|
288 |
+
$excluded = array_filter( $excluded );
|
289 |
+
$excluded = array_map( 'intval', $excluded );
|
290 |
+
return $excluded;
|
291 |
+
}
|
292 |
+
|
293 |
+
|
294 |
/**
|
295 |
*
|
296 |
* Checks is this id is excluded or not
|
297 |
*
|
298 |
+
* @param int $id
|
299 |
*
|
300 |
* @return bool
|
301 |
*/
|
302 |
+
public function is_excluded( $id ) {
|
303 |
if( !in_array( $id, $this->exclude ) ){
|
304 |
return true;
|
305 |
} else {
|
309 |
|
310 |
|
311 |
/**
|
312 |
+
* Allows for Overwriting files in the child theme
|
313 |
*
|
314 |
* @since 4.23.13
|
315 |
*
|
329 |
|
330 |
}
|
331 |
|
332 |
+
/*************** Deprectated ***************/
|
333 |
+
|
334 |
+
/**
|
335 |
+
* @see add_has_children_class
|
336 |
+
* @deprecated
|
337 |
+
*/
|
338 |
+
function hasChildrenClass( $classes, $page ) {
|
339 |
+
return $this->add_has_children_class( $classes, $page );
|
340 |
+
}
|
341 |
+
|
342 |
+
|
343 |
+
/**
|
344 |
+
* @see has_children
|
345 |
+
* @deprecated
|
346 |
+
*/
|
347 |
+
function hasChildren( $post_id ){
|
348 |
+
return $this->has_children( $post_id );
|
349 |
+
}
|
350 |
+
|
351 |
+
|
352 |
+
/**
|
353 |
+
* @see is_excluded
|
354 |
+
* @deprecated
|
355 |
+
*/
|
356 |
+
function exclude( $id ) {
|
357 |
+
return $this->is_excluded( $id );
|
358 |
+
}
|
359 |
+
|
360 |
+
|
361 |
+
|
362 |
+
|
363 |
} //End class
|
364 |
|
legacy/page_list.php
CHANGED
@@ -33,7 +33,7 @@ if( $child_pages ){
|
|
33 |
foreach($result as $pID){
|
34 |
|
35 |
#-- If the page is not in the excluded ones
|
36 |
-
if( $asm->
|
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 |
}
|
33 |
foreach($result as $pID){
|
34 |
|
35 |
#-- If the page is not in the excluded ones
|
36 |
+
if( $asm->is_excluded( $pID->ID) ){
|
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 |
}
|
readme.txt
CHANGED
@@ -1,25 +1,23 @@
|
|
1 |
=== Advanced Sidebar Menu ===
|
2 |
|
3 |
Contributors: Mat Lipe
|
4 |
-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%
|
5 |
Tags: menus, sidebar menu, hierarchy, category menu, pages menu
|
6 |
-
Requires at least:
|
7 |
-
Tested up to: 4.
|
8 |
-
Stable tag: 5.
|
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
|
15 |
Keeps the menu clean and usable.
|
16 |
|
17 |
<h3>Want more options and better support?</h3>
|
18 |
|
19 |
-
<strong><big><a href="
|
20 |
|
21 |
|
22 |
-
|
23 |
<ol>
|
24 |
<li>Add a title to the widget</li>
|
25 |
<li>Include the highest level parent page</li>
|
@@ -31,7 +29,7 @@ Includes Page options:
|
|
31 |
<li>Always display child Pages</li>
|
32 |
<li>Number of levels of child pages to display</li>
|
33 |
</ol>
|
34 |
-
|
35 |
<ol>
|
36 |
<li>Add a title to the widget</li>
|
37 |
<li>Include Parent Category</li>
|
@@ -131,6 +129,11 @@ I do offer premium services for building custom add-ons for additional functiona
|
|
131 |
|
132 |
|
133 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
134 |
= 5.0.0 =
|
135 |
* Greatly improved performance
|
136 |
* Improved code structure
|
1 |
=== Advanced Sidebar Menu ===
|
2 |
|
3 |
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¤cy_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.2.0
|
7 |
+
Tested up to: 4.4.1
|
8 |
+
Stable tag: 5.1.1
|
|
|
|
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
Creates a widget for both pages and categories that will display the current page/category and an child pages or categories.
|
13 |
Keeps the menu clean and usable.
|
14 |
|
15 |
<h3>Want more options and better support?</h3>
|
16 |
|
17 |
+
<strong><big><a href="https://matlipe.com/product/advanced-sidebar-menu-pro/">Go Pro!</a></big></strong>
|
18 |
|
19 |
|
20 |
+
Included page options:
|
21 |
<ol>
|
22 |
<li>Add a title to the widget</li>
|
23 |
<li>Include the highest level parent page</li>
|
29 |
<li>Always display child Pages</li>
|
30 |
<li>Number of levels of child pages to display</li>
|
31 |
</ol>
|
32 |
+
Included category options:
|
33 |
<ol>
|
34 |
<li>Add a title to the widget</li>
|
35 |
<li>Include Parent Category</li>
|
129 |
|
130 |
|
131 |
== Changelog ==
|
132 |
+
= 5.1.0 =
|
133 |
+
* Convert query over to get_posts() to allow for more extendability
|
134 |
+
* Implement object caching to improve performance for environments using external object caches
|
135 |
+
* Begin modernizing the naming conventions of methods and improving PHPdocs
|
136 |
+
|
137 |
= 5.0.0 =
|
138 |
* Greatly improved performance
|
139 |
* Improved code structure
|
widgets/page.widget.php
CHANGED
@@ -203,8 +203,10 @@ class advanced_sidebar_menu_page extends WP_Widget {
|
|
203 |
$filter_args[ 0 ] = 'page';
|
204 |
$asm->post_type = $post_type = apply_filters_ref_array( 'advanced_sidebar_menu_post_type', $filter_args );
|
205 |
|
206 |
-
|
207 |
-
|
|
|
|
|
208 |
add_filter( 'page_css_class', array( $asm, 'custom_post_type_css' ), 2, 4 );
|
209 |
}
|
210 |
|
@@ -242,15 +244,16 @@ class advanced_sidebar_menu_page extends WP_Widget {
|
|
242 |
|
243 |
if( $asm->checked( 'css' ) ){
|
244 |
echo '<style type="text/css">';
|
245 |
-
|
246 |
echo '</style>';
|
247 |
}
|
248 |
|
249 |
-
echo $before_widget;
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
254 |
|
255 |
}
|
256 |
|
@@ -270,27 +273,26 @@ class advanced_sidebar_menu_page extends WP_Widget {
|
|
270 |
* @return mixed
|
271 |
*/
|
272 |
private function get_child_pages( $asm, $filter_args ){
|
273 |
-
|
274 |
-
$
|
275 |
-
|
276 |
-
if(
|
277 |
-
$
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
283 |
}
|
284 |
-
}
|
285 |
|
286 |
-
|
287 |
-
WHERE post_parent = $asm->top_id
|
288 |
-
AND post_status='publish'
|
289 |
-
AND post_type='$asm->post_type'
|
290 |
-
$_excluded
|
291 |
-
Order by $asm->order_by";
|
292 |
|
293 |
-
|
|
|
294 |
|
295 |
$filter_args[ 0 ] = $child_pages;
|
296 |
$child_pages = apply_filters_ref_array( 'advanced_sidebar_menu_child_pages', $filter_args );
|
203 |
$filter_args[ 0 ] = 'page';
|
204 |
$asm->post_type = $post_type = apply_filters_ref_array( 'advanced_sidebar_menu_post_type', $filter_args );
|
205 |
|
206 |
+
if( 'page' == $asm->post_type ){
|
207 |
+
add_filter( 'page_css_class', array( $asm, 'add_has_children_class' ), 2, 2 );
|
208 |
+
|
209 |
+
} else {
|
210 |
add_filter( 'page_css_class', array( $asm, 'custom_post_type_css' ), 2, 4 );
|
211 |
}
|
212 |
|
244 |
|
245 |
if( $asm->checked( 'css' ) ){
|
246 |
echo '<style type="text/css">';
|
247 |
+
include( $asm->file_hyercy( 'sidebar-menu.css', $legacy ) );
|
248 |
echo '</style>';
|
249 |
}
|
250 |
|
251 |
+
echo $args[ 'before_widget' ];
|
252 |
+
|
253 |
+
$content = '';
|
254 |
+
require( $asm->file_hyercy( 'page_list.php', $legacy ) );
|
255 |
+
echo apply_filters( 'advanced_sidebar_menu_page_widget_output', $content, $args, $instance );
|
256 |
+
echo $args[ 'after_widget' ];
|
257 |
|
258 |
}
|
259 |
|
273 |
* @return mixed
|
274 |
*/
|
275 |
private function get_child_pages( $asm, $filter_args ){
|
276 |
+
$cache = Advanced_Sidebar_Menu_Cache::get_instance();
|
277 |
+
$child_pages = $cache->get_child_pages( $asm );
|
278 |
+
|
279 |
+
if( $child_pages === false ){
|
280 |
+
$child_page_args = array(
|
281 |
+
'post_type' => $asm->post_type,
|
282 |
+
'orderby' => $asm->order_by,
|
283 |
+
'post_parent' => $asm->top_id,
|
284 |
+
'fields' => 'ids',
|
285 |
+
);
|
286 |
+
|
287 |
+
$excluded = $asm->get_excluded_ids();
|
288 |
+
if( !empty( $excluded ) ){
|
289 |
+
$child_page_args[ 'post__not_in' ] = $excluded;
|
290 |
}
|
|
|
291 |
|
292 |
+
$child_pages = get_posts( $child_page_args );
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
+
$cache->add_child_pages( $asm, $child_pages );
|
295 |
+
}
|
296 |
|
297 |
$filter_args[ 0 ] = $child_pages;
|
298 |
$child_pages = apply_filters_ref_array( 'advanced_sidebar_menu_child_pages', $filter_args );
|