Advanced Sidebar Menu - Version 8.0.1

Version Description

Major version update. Not fully backward compatible with version 7 filters or code. Please see migration guide if you are extending the plugin via code.

Download this release

Release Info

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

Code changes from version 8.0.0 to 8.0.1

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.0.0
8
  * Author URI: https://onpointplugins.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', '8.0.0' );
19
  define( 'ADVANCED_SIDEBAR_MENU_REQUIRED_PRO_VERSION', '8.0.0' );
20
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
21
  define( 'ADVANCED_SIDEBAR_MENU_URL', plugin_dir_url( __FILE__ ) );
@@ -28,6 +28,7 @@ use Advanced_Sidebar_Menu\Menus\Category;
28
  use Advanced_Sidebar_Menu\Menus\Menu_Abstract;
29
  use Advanced_Sidebar_Menu\Menus\Page;
30
  use Advanced_Sidebar_Menu\Scripts;
 
31
  use Advanced_Sidebar_Menu\Traits\Singleton;
32
  use Advanced_Sidebar_Menu\Walkers\Page_Walker;
33
  use Advanced_Sidebar_Menu\Widget\Category as Widget_Category;
@@ -81,6 +82,7 @@ function advanced_sidebar_menu_autoload( $class ) {
81
  Page::class => 'Menus/Page.php',
82
 
83
  // Traits.
 
84
  Singleton::class => 'Traits/Singleton.php',
85
 
86
  // Walkers.
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.0.1
8
  * Author URI: https://onpointplugins.com
9
  * Text Domain: advanced-sidebar-menu
10
  *
15
  return;
16
  }
17
 
18
+ define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '8.0.1' );
19
  define( 'ADVANCED_SIDEBAR_MENU_REQUIRED_PRO_VERSION', '8.0.0' );
20
  define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
21
  define( 'ADVANCED_SIDEBAR_MENU_URL', plugin_dir_url( __FILE__ ) );
28
  use Advanced_Sidebar_Menu\Menus\Menu_Abstract;
29
  use Advanced_Sidebar_Menu\Menus\Page;
30
  use Advanced_Sidebar_Menu\Scripts;
31
+ use Advanced_Sidebar_Menu\Traits\Memoize;
32
  use Advanced_Sidebar_Menu\Traits\Singleton;
33
  use Advanced_Sidebar_Menu\Walkers\Page_Walker;
34
  use Advanced_Sidebar_Menu\Widget\Category as Widget_Category;
82
  Page::class => 'Menus/Page.php',
83
 
84
  // Traits.
85
+ Memoize::class => 'Traits/Memoize.php',
86
  Singleton::class => 'Traits/Singleton.php',
87
 
88
  // Walkers.
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: menus, sidebar menu, hierarchy, category menu, pages menu
6
  Requires at least: 4.8.0
7
  Tested up to: 5.4.2
8
  Requires PHP: 5.6.0
9
- Stable tag: 8.0.0
10
 
11
  == Description ==
12
 
@@ -16,7 +16,7 @@ Keeps the menu clean and usable. Only related items display so you don't have to
16
 
17
  <strong>Check out <a href="https://onpointplugins.com/product/advanced-sidebar-menu-pro/">Advanced Sidebar Menu Pro</a> for more features including priority support, the ability to customize the look and feel, custom link text, excluding of pages, category ordering, accordions, custom post types, custom taxonomies, and so much more!</strong>
18
 
19
- <blockquote><a href="https://onpointplugins.com/product/advanced-sidebar-menu-pro/" target="_blank">Pro version 3.10.0</a> is now available with support to exclude and change titles of navigation menu items using each page's settings!</blockquote>
20
 
21
  <h3>Features</h3>
22
  * Page and Category widgets.
@@ -217,7 +217,7 @@ Major version update. See <a href="https://onpointplugins.com/advanced-sidebar-m
217
 
218
 
219
  == Upgrade Notice ==
220
- = 8.0.0 =
221
  Major version update. Not fully backward compatible with version 7 filters or code. Please see migration guide if you are extending the plugin via code.
222
 
223
  = 7.7.0 =
6
  Requires at least: 4.8.0
7
  Tested up to: 5.4.2
8
  Requires PHP: 5.6.0
9
+ Stable tag: 8.0.1
10
 
11
  == Description ==
12
 
16
 
17
  <strong>Check out <a href="https://onpointplugins.com/product/advanced-sidebar-menu-pro/">Advanced Sidebar Menu Pro</a> for more features including priority support, the ability to customize the look and feel, custom link text, excluding of pages, category ordering, accordions, custom post types, custom taxonomies, and so much more!</strong>
18
 
19
+ <blockquote><a href="https://onpointplugins.com/product/advanced-sidebar-menu-pro/" target="_blank">Pro version 8.0.0</a> is now available with support to exclude and change titles of navigation menu items using each page's settings!</blockquote>
20
 
21
  <h3>Features</h3>
22
  * Page and Category widgets.
217
 
218
 
219
  == Upgrade Notice ==
220
+ = 8.0.1 =
221
  Major version update. Not fully backward compatible with version 7 filters or code. Please see migration guide if you are extending the plugin via code.
222
 
223
  = 7.7.0 =
src/Menus/Page.php CHANGED
@@ -104,7 +104,7 @@ class Page extends Menu_Abstract {
104
  if ( is_page() || ( is_single() && $post_type === $this->get_current_post()->post_type ) ) {
105
  // If we are on the correct post type.
106
  if ( get_post_type( $this->get_top_parent_id() ) === $post_type ) {
107
- // Ff we have children.
108
  if ( $this->has_pages() ) {
109
  $display = true;
110
  // No children + not excluded + include parent +include childless parent.
104
  if ( is_page() || ( is_single() && $post_type === $this->get_current_post()->post_type ) ) {
105
  // If we are on the correct post type.
106
  if ( get_post_type( $this->get_top_parent_id() ) === $post_type ) {
107
+ // If we have children.
108
  if ( $this->has_pages() ) {
109
  $display = true;
110
  // No children + not excluded + include parent +include childless parent.
src/Traits/Memoize.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Advanced_Sidebar_Menu\Traits;
4
+
5
+ /**
6
+ * Support simple memoization for class methods which respond
7
+ * with different caches based on the arguments provided.
8
+ *
9
+ * @since 8.0.1
10
+ */
11
+ trait Memoize {
12
+ /**
13
+ * Store results of the memoize methods.
14
+ *
15
+ * @var array
16
+ */
17
+ protected $memoize_cache = [];
18
+
19
+
20
+ /**
21
+ * Pass me a callback, a method identifier, and some optional arguments and
22
+ * and I will return the same result every time.
23
+ *
24
+ * The passed function will only be called once no matter where it called from
25
+ * and what the arguments are.
26
+ * I will always return the value received from the callback on its first run.
27
+ *
28
+ * @param callable $fn - Callback.
29
+ * @param string $identifier - Something unique to identify the the method being used
30
+ * so we can determine the difference in the cache.
31
+ * `__METHOD__` works nicely here.
32
+ * @param mixed $args - Arguments will be passed to the callback..
33
+ *
34
+ * @return mixed
35
+ */
36
+ public function once( callable $fn, $identifier, $args ) {
37
+ if ( ! array_key_exists( "{$identifier}::once", $this->memoize_cache ) ) {
38
+ $this->memoize_cache[ "{$identifier}::once" ] = $fn( $args );
39
+ }
40
+
41
+ return $this->memoize_cache[ "{$identifier}::once" ];
42
+ }
43
+
44
+
45
+ /**
46
+ * Pass me a callback, a method identifier, and some arguments and
47
+ * I will return the same result every time the arguments are the same.
48
+ *
49
+ * If the arguments change, I will return a result matching the change.
50
+ * I will only call the callback one time for the same set of arguments.
51
+ *
52
+ * @param callable $fn - Callback.
53
+ * @param string $identifier - Something unique to identify the the method being used
54
+ * so we can determine the difference in the cache.
55
+ * `__METHOD__` works nicely here.
56
+ * @param mixed $args - Arguments will be passed to the callback as well as determine
57
+ * if we can reuse a result.
58
+ *
59
+ * @return mixed
60
+ */
61
+ public function memoize( callable $fn, $identifier, $args ) {
62
+ //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
63
+ $key = md5( serialize( [ $args, $identifier ] ) );
64
+ if ( ! array_key_exists( $key, $this->memoize_cache ) ) {
65
+ $this->memoize_cache[ $key ] = $fn( $args );
66
+ }
67
+
68
+ return $this->memoize_cache[ $key ];
69
+ }
70
+
71
+
72
+ /**
73
+ * Clear all caches on this class.
74
+ * Typically used during unit testing.
75
+ *
76
+ * @return void
77
+ */
78
+ public function clear_memoize_cache() {
79
+ $this->memoize_cache = [];
80
+ }
81
+ }
src/Traits/Singleton.php CHANGED
@@ -17,6 +17,15 @@ trait Singleton {
17
  */
18
  protected static $instance;
19
 
 
 
 
 
 
 
 
 
 
20
 
21
  /**
22
  * Create the instance of the class
@@ -29,6 +38,24 @@ trait Singleton {
29
  if ( method_exists( static::$instance, 'hook' ) ) {
30
  static::$instance->hook();
31
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
 
17
  */
18
  protected static $instance;
19
 
20
+ /**
21
+ * Tracks if init has been called.
22
+ *
23
+ * @since 8.0.1
24
+ *
25
+ * @var bool
26
+ */
27
+ protected static $inited = false;
28
+
29
 
30
  /**
31
  * Create the instance of the class
38
  if ( method_exists( static::$instance, 'hook' ) ) {
39
  static::$instance->hook();
40
  }
41
+ static::$inited = true;
42
+ }
43
+
44
+
45
+ /**
46
+ * Call this method as many times as needed and the
47
+ * class will only init() one time.
48
+ *
49
+ * @static
50
+ *
51
+ * @since 8.0.1
52
+ *
53
+ * @return void
54
+ */
55
+ public static function init_once() {
56
+ if ( ! static::$inited ) {
57
+ static::init();
58
+ }
59
  }
60
 
61
 
src/Widget/Category.php CHANGED
@@ -70,6 +70,12 @@ class Category extends Widget_Abstract {
70
  * @return void
71
  */
72
  protected function hook() {
 
 
 
 
 
 
73
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_display' ], 5, 2 );
74
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_display_on_single_posts' ], 15, 2 );
75
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_exclude' ], 20, 2 );
70
  * @return void
71
  */
72
  protected function hook() {
73
+ static $hooked;
74
+ if ( null !== $hooked ) {
75
+ return;
76
+ }
77
+ $hooked = true;
78
+
79
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_display' ], 5, 2 );
80
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_display_on_single_posts' ], 15, 2 );
81
  add_action( 'advanced-sidebar-menu/widget/category/left-column', [ $this, 'box_exclude' ], 20, 2 );
src/Widget/Page.php CHANGED
@@ -66,6 +66,12 @@ class Page extends Widget_Abstract {
66
  * @return void
67
  */
68
  protected function hook() {
 
 
 
 
 
 
69
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_display' ], 5, 2 );
70
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_order' ], 15, 2 );
71
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_exclude' ], 20, 2 );
66
  * @return void
67
  */
68
  protected function hook() {
69
+ static $hooked;
70
+ if ( null !== $hooked ) {
71
+ return;
72
+ }
73
+ $hooked = true;
74
+
75
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_display' ], 5, 2 );
76
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_order' ], 15, 2 );
77
  add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_exclude' ], 20, 2 );