1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The admin-specific functionality of the plugin. |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/maab16 |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
* |
9
|
|
|
* @package WPB |
10
|
|
|
* @subpackage WPB/admin |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The admin-specific functionality of the plugin. |
15
|
|
|
* |
16
|
|
|
* Defines the plugin name, version, and two examples hooks for how to |
17
|
|
|
* enqueue the admin-specific stylesheet and JavaScript. |
18
|
|
|
* |
19
|
|
|
* @package WPB |
20
|
|
|
* @subpackage WPB/admin |
21
|
|
|
* @author Md Abu Ahsan basir <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class WPB_Admin_SubMenu { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The menu page title. |
27
|
|
|
* |
28
|
|
|
* @since 1.0.0 |
29
|
|
|
* @access public |
30
|
|
|
* @var string $page_title The string used to set menu page title. |
31
|
|
|
*/ |
32
|
|
|
public $page_title; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The menu title. |
36
|
|
|
* |
37
|
|
|
* @since 1.0.0 |
38
|
|
|
* @access public |
39
|
|
|
* @var string $menu_title The string used to set menu title. |
40
|
|
|
*/ |
41
|
|
|
public $menu_title; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The menu capability. |
45
|
|
|
* |
46
|
|
|
* @since 1.0.0 |
47
|
|
|
* @access public |
48
|
|
|
* @var string $capability The string used to set menu capability. |
49
|
|
|
*/ |
50
|
|
|
public $capability; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The menu slug. |
54
|
|
|
* |
55
|
|
|
* @since 1.0.0 |
56
|
|
|
* @access public |
57
|
|
|
* @var string $slug The string used to set menu slug. |
58
|
|
|
*/ |
59
|
|
|
public $slug; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The callback to render content. |
63
|
|
|
* |
64
|
|
|
* @since 1.0.0 |
65
|
|
|
* @access public |
66
|
|
|
* @var callback $callback The callback used to render content. |
67
|
|
|
*/ |
68
|
|
|
public $callback; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The menu icon. |
72
|
|
|
* |
73
|
|
|
* @since 1.0.0 |
74
|
|
|
* @access public |
75
|
|
|
* @var string $icon The string used to set menu icon. |
76
|
|
|
*/ |
77
|
|
|
public $icon; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* The menu position. |
81
|
|
|
* |
82
|
|
|
* @since 1.0.0 |
83
|
|
|
* @access public |
84
|
|
|
* @var int $position The string used to set menu position. |
85
|
|
|
*/ |
86
|
|
|
public $position; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The menu plugin name. |
90
|
|
|
* |
91
|
|
|
* @since 1.0.0 |
92
|
|
|
* @access private |
93
|
|
|
* @var string $plugin_name The string used to uniquely identify this plugin. |
94
|
|
|
*/ |
95
|
|
|
private $plugin_name; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Boot Menu. |
99
|
|
|
* |
100
|
|
|
* @param string $plugin_name The string used to uniquely identify this plugin. |
101
|
|
|
* @since 1.0.0 |
102
|
|
|
* @access public |
103
|
|
|
*/ |
104
|
|
|
public function __construct( $plugin_name ) { |
105
|
|
|
$this->plugin_name = $plugin_name; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Create a new menu page. |
110
|
|
|
* |
111
|
|
|
* @since 1.0.0 |
112
|
|
|
* @access public |
113
|
|
|
*/ |
114
|
|
|
public function save() { |
115
|
|
|
add_action( 'admin_menu', array( $this, 'create_submenu' ) ); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Create a new submenu page. |
120
|
|
|
* |
121
|
|
|
* @since 1.0.0 |
122
|
|
|
* @param array $options Pass proprties as an array. |
123
|
|
|
* @access public |
124
|
|
|
*/ |
125
|
|
|
public function make( $options = array() ) { |
126
|
|
|
foreach ( $options as $property => $value ) { |
127
|
|
|
if ( property_exists( $this, $property ) ) { |
128
|
|
|
$this->{$property} = $value; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
add_action( 'admin_menu', array( $this, 'create_submenu' ) ); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Register new submenu page. |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
public function create_submenu() { |
140
|
|
|
if ( current_user_can( $this->capability ) ) { |
|
|
|
|
141
|
|
|
$hook = add_submenu_page( |
|
|
|
|
142
|
|
|
$this->parent_slug, |
|
|
|
|
143
|
|
|
$this->page_title, |
144
|
|
|
$this->menu_title, |
145
|
|
|
$this->capability, |
146
|
|
|
$this->slug, |
147
|
|
|
$this->callback, |
148
|
|
|
$this->icon |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
add_action( 'load-' . $hook, array( $this, 'init_hooks' ) ); |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Initialize hooks for the admin page. |
157
|
|
|
* |
158
|
|
|
* @return void |
159
|
|
|
*/ |
160
|
|
|
public function init_hooks() { |
161
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Load scripts and styles for the submenu page. |
166
|
|
|
* |
167
|
|
|
* @return void |
168
|
|
|
*/ |
169
|
|
|
public function enqueue_scripts() { |
170
|
|
|
wp_enqueue_style( $this->plugin_name . '-vendors' ); |
|
|
|
|
171
|
|
|
wp_enqueue_style( $this->plugin_name . '-admin' ); |
172
|
|
|
wp_enqueue_script( $this->plugin_name . '-admin' ); |
|
|
|
|
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|