Version Description
- Enable accordion previews when editing via Beaver Builder.
- Greatly improve widget styles and UI when using Elementor.
- Overall third party page builder improvements.
- Move scripts and styles into new Scripts class.
- Introduce a new Singleton trait.
Download this release
Release Info
Developer | Mat Lipe |
Plugin | Advanced Sidebar Menu |
Version | 7.7.0 |
Comparing to | |
See all releases |
Code changes from version 7.6.6 to 7.7.0
- advanced-sidebar-menu.php +18 -56
- readme.txt +15 -2
- resources/css/advanced-sidebar-menu.css +27 -0
- src/Core.php +1 -35
- src/Scripts.php +82 -0
- src/Traits/Singleton.php +49 -0
advanced-sidebar-menu.php
CHANGED
@@ -4,19 +4,22 @@
|
|
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: 7.
|
8 |
* Author URI: https://onpointplugins.com
|
9 |
* Text Domain: advanced-sidebar-menu
|
10 |
*
|
11 |
* @package advanced-sidebar-menu
|
12 |
*/
|
13 |
|
|
|
|
|
14 |
if ( defined( 'ADVANCED_SIDEBAR_BASIC_VERSION' ) ) {
|
15 |
return;
|
16 |
}
|
17 |
|
18 |
-
define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.
|
19 |
define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
|
|
|
20 |
|
21 |
if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
|
22 |
/**
|
@@ -28,6 +31,7 @@ if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
|
|
28 |
Advanced_Sidebar_Menu_Core::init();
|
29 |
Advanced_Sidebar_Menu_Cache::init();
|
30 |
Advanced_Sidebar_Menu_Debug::init();
|
|
|
31 |
}
|
32 |
|
33 |
add_action( 'plugins_loaded', 'advanced_sidebar_menu_load' );
|
@@ -55,14 +59,18 @@ function advanced_sidebar_menu_autoload( $class ) {
|
|
55 |
'Advanced_Sidebar_Menu_List_Pages' => 'List_Pages.php',
|
56 |
'Advanced_Sidebar_Menu_Menu' => 'Menu.php',
|
57 |
'Advanced_Sidebar_Menu_Page_Walker' => 'Page_Walker.php',
|
|
|
58 |
|
59 |
// menus.
|
60 |
'Advanced_Sidebar_Menu_Menus_Category' => 'Menus/Category.php',
|
61 |
'Advanced_Sidebar_Menu_Menus_Abstract' => 'Menus/Abstract.php',
|
62 |
'Advanced_Sidebar_Menu_Menus_Page' => 'Menus/Page.php',
|
|
|
|
|
|
|
63 |
);
|
64 |
if ( isset( $classes[ $class ] ) ) {
|
65 |
-
require
|
66 |
}
|
67 |
}
|
68 |
|
@@ -79,66 +87,20 @@ function advanced_sidebar_menu_translate() {
|
|
79 |
load_plugin_textdomain( 'advanced-sidebar-menu', false, 'advanced-sidebar-menu/languages' );
|
80 |
}
|
81 |
|
82 |
-
add_action( 'admin_print_scripts', 'advanced_sidebar_menu_script' );
|
83 |
-
// UGH! Beaver Builder hack.
|
84 |
-
if ( isset( $_GET['fl_builder'] ) ) {
|
85 |
-
add_action( 'wp_enqueue_scripts', 'advanced_sidebar_menu_script' );
|
86 |
-
}
|
87 |
-
/**
|
88 |
-
* Add js and css to the admin and in specific cases the front-end.
|
89 |
-
*
|
90 |
-
* @return void
|
91 |
-
*/
|
92 |
-
function advanced_sidebar_menu_script() {
|
93 |
-
wp_enqueue_script(
|
94 |
-
apply_filters( 'asm_script', 'advanced-sidebar-menu-script' ),
|
95 |
-
plugins_url( 'resources/js/advanced-sidebar-menu.js', __FILE__ ),
|
96 |
-
array( 'jquery' ),
|
97 |
-
ADVANCED_SIDEBAR_BASIC_VERSION,
|
98 |
-
false
|
99 |
-
);
|
100 |
-
|
101 |
-
wp_enqueue_style(
|
102 |
-
apply_filters( 'asm_style', 'advanced-sidebar-menu-style' ),
|
103 |
-
plugins_url( 'resources/css/advanced-sidebar-menu.css', __FILE__ ),
|
104 |
-
array(),
|
105 |
-
ADVANCED_SIDEBAR_BASIC_VERSION
|
106 |
-
);
|
107 |
-
}
|
108 |
|
109 |
-
add_action( 'advanced-sidebar-menu/widget/category/
|
110 |
-
add_action( 'advanced-sidebar-menu/widget/page/
|
111 |
-
add_action( 'advanced-sidebar-menu/widget/navigation-menu/after-form', 'advanced_sidebar_menu_init_widget_js', 1000 );
|
112 |
|
113 |
/**
|
114 |
-
*
|
115 |
-
* This is outputted into the markup for each widget so it may be
|
116 |
-
* trigger whether the widget is loaded on the front-end by
|
117 |
-
* page builders or the backend by standard WordPress or
|
118 |
-
* really anywhere.
|
119 |
*
|
120 |
-
* @
|
121 |
*/
|
122 |
-
function
|
123 |
-
|
124 |
-
|
125 |
-
<!-- <?php echo __FILE__; ?>-->
|
126 |
-
<?php
|
127 |
-
}
|
128 |
-
?>
|
129 |
-
<script>
|
130 |
-
if (typeof (advanced_sidebar_menu) !== 'undefined') {
|
131 |
-
advanced_sidebar_menu.init()
|
132 |
-
}
|
133 |
-
</script>
|
134 |
-
<?php
|
135 |
}
|
136 |
|
137 |
-
|
138 |
-
add_action( 'advanced-sidebar-menu/widget/category/right-column', 'advanced_sidebar_menu_upgrade_notice', 1, 2 );
|
139 |
-
add_action( 'advanced-sidebar-menu/widget/page/right-column', 'advanced_sidebar_menu_upgrade_notice', 1, 2 );
|
140 |
-
|
141 |
-
|
142 |
/**
|
143 |
* Notify widget users about the PRO options
|
144 |
*
|
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: 7.7.0
|
8 |
* Author URI: https://onpointplugins.com
|
9 |
* Text Domain: advanced-sidebar-menu
|
10 |
*
|
11 |
* @package advanced-sidebar-menu
|
12 |
*/
|
13 |
|
14 |
+
use Advanced_Sidebar_Menu\Scripts;
|
15 |
+
|
16 |
if ( defined( 'ADVANCED_SIDEBAR_BASIC_VERSION' ) ) {
|
17 |
return;
|
18 |
}
|
19 |
|
20 |
+
define( 'ADVANCED_SIDEBAR_BASIC_VERSION', '7.7.0' );
|
21 |
define( 'ADVANCED_SIDEBAR_DIR', plugin_dir_path( __FILE__ ) );
|
22 |
+
define( 'ADVANCED_SIDEBAR_MENU_URL', plugin_dir_url( __FILE__ ) );
|
23 |
|
24 |
if ( ! function_exists( 'advanced_sidebar_menu_load' ) ) {
|
25 |
/**
|
31 |
Advanced_Sidebar_Menu_Core::init();
|
32 |
Advanced_Sidebar_Menu_Cache::init();
|
33 |
Advanced_Sidebar_Menu_Debug::init();
|
34 |
+
Scripts::init();
|
35 |
}
|
36 |
|
37 |
add_action( 'plugins_loaded', 'advanced_sidebar_menu_load' );
|
59 |
'Advanced_Sidebar_Menu_List_Pages' => 'List_Pages.php',
|
60 |
'Advanced_Sidebar_Menu_Menu' => 'Menu.php',
|
61 |
'Advanced_Sidebar_Menu_Page_Walker' => 'Page_Walker.php',
|
62 |
+
'Advanced_Sidebar_Menu\Scripts' => 'Scripts.php',
|
63 |
|
64 |
// menus.
|
65 |
'Advanced_Sidebar_Menu_Menus_Category' => 'Menus/Category.php',
|
66 |
'Advanced_Sidebar_Menu_Menus_Abstract' => 'Menus/Abstract.php',
|
67 |
'Advanced_Sidebar_Menu_Menus_Page' => 'Menus/Page.php',
|
68 |
+
|
69 |
+
// Traits.
|
70 |
+
'Advanced_Sidebar_Menu\Traits\Singleton' => 'Traits/Singleton.php',
|
71 |
);
|
72 |
if ( isset( $classes[ $class ] ) ) {
|
73 |
+
require __DIR__ . '/src/' . $classes[ $class ];
|
74 |
}
|
75 |
}
|
76 |
|
87 |
load_plugin_textdomain( 'advanced-sidebar-menu', false, 'advanced-sidebar-menu/languages' );
|
88 |
}
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
add_action( 'advanced-sidebar-menu/widget/category/right-column', 'advanced_sidebar_menu_upgrade_notice', 1, 2 );
|
92 |
+
add_action( 'advanced-sidebar-menu/widget/page/right-column', 'advanced_sidebar_menu_upgrade_notice', 1, 2 );
|
|
|
93 |
|
94 |
/**
|
95 |
+
* Legacy method now deprecated.
|
|
|
|
|
|
|
|
|
96 |
*
|
97 |
+
* @deprecated In favor of \Advanced_Sidebar_Menu\Scripts::instance()->admin_scripts()
|
98 |
*/
|
99 |
+
function advanced_sidebar_menu_script() {
|
100 |
+
_deprecated_function( 'advanced_sidebar_menu_script', '7.8.0', '\Advanced_Sidebar_Menu\Scripts::instance()->admin_scripts()' );
|
101 |
+
\Advanced_Sidebar_Menu\Scripts::instance()->admin_scripts();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
|
|
|
|
|
|
|
|
|
|
104 |
/**
|
105 |
* Notify widget users about the PRO options
|
106 |
*
|
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.3.0
|
8 |
Requires PHP: 5.6.0
|
9 |
-
Stable tag: 7.
|
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.
|
20 |
|
21 |
<h4>Features</h4>
|
22 |
* Page and Category widgets.
|
@@ -155,6 +155,13 @@ Yes. Based on whatever page, post, or category you are on, the menu will change
|
|
155 |
|
156 |
|
157 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
= 7.6.0 =
|
159 |
* Elementor support for multiple widgets of the same type on the same page.
|
160 |
* Automatically increment widget ids under any cases where they would duplicate.
|
@@ -243,6 +250,12 @@ Yes. Based on whatever page, post, or category you are on, the menu will change
|
|
243 |
|
244 |
|
245 |
== Upgrade Notice ==
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
= 7.5.0 =
|
247 |
Update to support PRO version 3.6.0
|
248 |
|
6 |
Requires at least: 4.8.0
|
7 |
Tested up to: 5.3.0
|
8 |
Requires PHP: 5.6.0
|
9 |
+
Stable tag: 7.7.0
|
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 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 |
<h4>Features</h4>
|
22 |
* Page and Category widgets.
|
155 |
|
156 |
|
157 |
== Changelog ==
|
158 |
+
= 7.7.0 =
|
159 |
+
* Enable accordion previews when editing via Beaver Builder.
|
160 |
+
* Greatly improve widget styles and UI when using Elementor.
|
161 |
+
* Overall third party page builder improvements.
|
162 |
+
* Move scripts and styles into new Scripts class.
|
163 |
+
* Introduce a new Singleton trait.
|
164 |
+
|
165 |
= 7.6.0 =
|
166 |
* Elementor support for multiple widgets of the same type on the same page.
|
167 |
* Automatically increment widget ids under any cases where they would duplicate.
|
250 |
|
251 |
|
252 |
== Upgrade Notice ==
|
253 |
+
= 7.7.0 =
|
254 |
+
Update to support PRO version 3.10.0
|
255 |
+
|
256 |
+
= 7.6.6 =
|
257 |
+
Update to support PRO version 3.9.3
|
258 |
+
|
259 |
= 7.5.0 =
|
260 |
Update to support PRO version 3.6.0
|
261 |
|
resources/css/advanced-sidebar-menu.css
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
width: 49%;
|
4 |
}
|
5 |
|
|
|
6 |
.advanced-sidebar-menu-column-right {
|
7 |
margin-left: 2%;
|
8 |
}
|
@@ -24,3 +25,29 @@
|
|
24 |
width: 100%;
|
25 |
}
|
26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
width: 49%;
|
4 |
}
|
5 |
|
6 |
+
|
7 |
.advanced-sidebar-menu-column-right {
|
8 |
margin-left: 2%;
|
9 |
}
|
25 |
width: 100%;
|
26 |
}
|
27 |
}
|
28 |
+
|
29 |
+
/** Elementor specific styles **/
|
30 |
+
.elementor-control-content .advanced-sidebar-menu-column {
|
31 |
+
width: 100%;
|
32 |
+
}
|
33 |
+
.elementor-control-content .advanced-sidebar-menu-column-right {
|
34 |
+
margin-left: 0;
|
35 |
+
}
|
36 |
+
.elementor-control-content .advanced-sidebar-menu-column-box .widefat {
|
37 |
+
width: 100%;
|
38 |
+
}
|
39 |
+
.elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container input[type="text"].wp-color-picker {
|
40 |
+
min-height: auto;
|
41 |
+
padding: 6px 3px;
|
42 |
+
font-weight: 600;
|
43 |
+
}
|
44 |
+
.elementor-control-content .advanced-sidebar-menu-column-box .advanced-sidebar-menu-border-color .wp-color-result {
|
45 |
+
position: relative;
|
46 |
+
top: 7px;
|
47 |
+
}
|
48 |
+
.elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container{
|
49 |
+
float: none;
|
50 |
+
}
|
51 |
+
.elementor-control-content .advanced-sidebar-menu-column-box .wp-picker-container.wp-picker-active {
|
52 |
+
top: auto;
|
53 |
+
}
|
src/Core.php
CHANGED
@@ -9,6 +9,7 @@
|
|
9 |
*
|
10 |
*/
|
11 |
class Advanced_Sidebar_Menu_Core {
|
|
|
12 |
|
13 |
protected function hook() {
|
14 |
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
@@ -56,39 +57,4 @@ class Advanced_Sidebar_Menu_Core {
|
|
56 |
|
57 |
return $file;
|
58 |
}
|
59 |
-
|
60 |
-
//********** SINGLETON FUNCTIONS **********/
|
61 |
-
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Instance of this class for use as singleton
|
65 |
-
*/
|
66 |
-
protected static $instance;
|
67 |
-
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Create the instance of the class
|
71 |
-
*
|
72 |
-
* @static
|
73 |
-
* @return void
|
74 |
-
*/
|
75 |
-
public static function init() {
|
76 |
-
self::instance()->hook();
|
77 |
-
}
|
78 |
-
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Get (and instantiate, if necessary) the instance of the
|
82 |
-
* class
|
83 |
-
*
|
84 |
-
* @static
|
85 |
-
* @return self
|
86 |
-
*/
|
87 |
-
public static function instance() {
|
88 |
-
if ( ! is_a( self::$instance, __CLASS__ ) ) {
|
89 |
-
self::$instance = new self();
|
90 |
-
}
|
91 |
-
|
92 |
-
return self::$instance;
|
93 |
-
}
|
94 |
}
|
9 |
*
|
10 |
*/
|
11 |
class Advanced_Sidebar_Menu_Core {
|
12 |
+
use \Advanced_Sidebar_Menu\Traits\Singleton;
|
13 |
|
14 |
protected function hook() {
|
15 |
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
57 |
|
58 |
return $file;
|
59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
src/Scripts.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace Advanced_Sidebar_Menu;
|
4 |
+
|
5 |
+
use Advanced_Sidebar_Menu\Traits\Singleton;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Scripts and styles.
|
9 |
+
*
|
10 |
+
* @author Mat Lipe
|
11 |
+
* @since 7.8.0
|
12 |
+
*/
|
13 |
+
class Scripts {
|
14 |
+
use Singleton;
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Add various scripts to the cue.
|
19 |
+
*/
|
20 |
+
public function hook() {
|
21 |
+
add_action( 'admin_print_scripts', [ $this, 'admin_scripts' ] );
|
22 |
+
// Elementor support.
|
23 |
+
add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'admin_scripts' ] );
|
24 |
+
// UGH! Beaver Builder hack.
|
25 |
+
if ( isset( $_GET['fl_builder'] ) ) { // phpcs:ignore
|
26 |
+
add_action( 'wp_enqueue_scripts', [ $this, 'admin_scripts' ] );
|
27 |
+
}
|
28 |
+
|
29 |
+
add_action( 'advanced-sidebar-menu/widget/category/after-form', [ $this, 'init_widget_js' ], 1000 );
|
30 |
+
add_action( 'advanced-sidebar-menu/widget/page/after-form', [ $this, 'init_widget_js' ], 1000 );
|
31 |
+
add_action( 'advanced-sidebar-menu/widget/navigation-menu/after-form', [ $this, 'init_widget_js' ], 1000 );
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Add js and css to the admin and in specific cases the front-end.
|
37 |
+
*
|
38 |
+
* @return void
|
39 |
+
*/
|
40 |
+
public function admin_scripts() {
|
41 |
+
wp_enqueue_script(
|
42 |
+
apply_filters( 'asm_script', 'advanced-sidebar-menu-script' ),
|
43 |
+
\trailingslashit( ADVANCED_SIDEBAR_MENU_URL ) . 'resources/js/advanced-sidebar-menu.js',
|
44 |
+
[ 'jquery' ],
|
45 |
+
ADVANCED_SIDEBAR_BASIC_VERSION,
|
46 |
+
false
|
47 |
+
);
|
48 |
+
|
49 |
+
wp_enqueue_style(
|
50 |
+
apply_filters( 'asm_style', 'advanced-sidebar-menu-style' ),
|
51 |
+
\trailingslashit( ADVANCED_SIDEBAR_MENU_URL ) . 'resources/css/advanced-sidebar-menu.css',
|
52 |
+
[],
|
53 |
+
ADVANCED_SIDEBAR_BASIC_VERSION
|
54 |
+
);
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Trigger any JS needed by the widgets.
|
60 |
+
* This is outputted into the markup for each widget so it may be
|
61 |
+
* trigger whether the widget is loaded on the front-end by
|
62 |
+
* page builders or the backend by standard WordPress or
|
63 |
+
* really anywhere.
|
64 |
+
*
|
65 |
+
* @return void
|
66 |
+
*/
|
67 |
+
public function init_widget_js() {
|
68 |
+
if ( WP_DEBUG ) {
|
69 |
+
?>
|
70 |
+
<!-- <?php echo __FILE__; ?>-->
|
71 |
+
<?php
|
72 |
+
}
|
73 |
+
?>
|
74 |
+
<script>
|
75 |
+
if ( typeof ( advanced_sidebar_menu ) !== 'undefined' ) {
|
76 |
+
advanced_sidebar_menu.init();
|
77 |
+
}
|
78 |
+
</script>
|
79 |
+
<?php
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
src/Traits/Singleton.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace Advanced_Sidebar_Menu\Traits;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Trait Singleton
|
7 |
+
*
|
8 |
+
* @author Mat Lipe
|
9 |
+
* @since 7.7.0
|
10 |
+
*/
|
11 |
+
trait Singleton {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Instance of this class for use as singleton
|
15 |
+
*
|
16 |
+
* @var static
|
17 |
+
*/
|
18 |
+
protected static $instance;
|
19 |
+
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Create the instance of the class
|
23 |
+
*
|
24 |
+
* @static
|
25 |
+
* @return void
|
26 |
+
*/
|
27 |
+
public static function init() {
|
28 |
+
static::$instance = static::instance();
|
29 |
+
if ( method_exists( static::$instance, 'hook' ) ) {
|
30 |
+
static::$instance->hook();
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Get (and instantiate, if necessary) the instance of the
|
37 |
+
* class
|
38 |
+
*
|
39 |
+
* @static
|
40 |
+
* @return static
|
41 |
+
*/
|
42 |
+
public static function instance() {
|
43 |
+
if ( ! is_a( static::$instance, __CLASS__ ) ) {
|
44 |
+
static::$instance = new static();
|
45 |
+
}
|
46 |
+
|
47 |
+
return static::$instance;
|
48 |
+
}
|
49 |
+
}
|