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 protected |
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 protected |
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 protected |
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 protected |
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 protected |
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 protected |
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 protected |
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 protected |
93
|
|
|
* @var string $plugin_name The string used to uniquely identify this plugin. |
94
|
|
|
*/ |
95
|
|
|
public $plugin_name; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Create a new menu page. |
99
|
|
|
* |
100
|
|
|
* @since 1.0.0 |
101
|
|
|
* @access public |
102
|
|
|
*/ |
103
|
|
|
public function save() { |
104
|
|
|
add_action( 'admin_menu', array( $this, 'create_submenu' ) ); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Create a new submenu page. |
109
|
|
|
* |
110
|
|
|
* @since 1.0.0 |
111
|
|
|
* @param array $options Pass proprties as an array. |
112
|
|
|
* @access public |
113
|
|
|
*/ |
114
|
|
|
public function make( $options = array() ) { |
115
|
|
|
foreach ( $options as $property => $value ) { |
116
|
|
|
if ( property_exists( $this, $property ) ) { |
117
|
|
|
$this->{$property} = $value; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
add_action( 'admin_menu', array( $this, 'create_submenu' ) ); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Register new submenu page. |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
|
public function create_submenu() { |
129
|
|
|
if ( current_user_can( $this->capability ) ) { |
|
|
|
|
130
|
|
|
$hook = add_submenu_page( |
|
|
|
|
131
|
|
|
$this->parent_slug, |
|
|
|
|
132
|
|
|
$this->page_title, |
133
|
|
|
$this->menu_title, |
134
|
|
|
$this->capability, |
135
|
|
|
$this->slug, |
136
|
|
|
$this->callback, |
137
|
|
|
$this->icon |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
add_action( 'load-' . $hook, array( $this, 'init_hooks' ) ); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Initialize hooks for the admin page. |
146
|
|
|
* |
147
|
|
|
* @return void |
148
|
|
|
*/ |
149
|
|
|
public function init_hooks() { |
150
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Load scripts and styles for the submenu page. |
155
|
|
|
* |
156
|
|
|
* @return void |
157
|
|
|
*/ |
158
|
|
|
public function enqueue_scripts() { |
159
|
|
|
wp_enqueue_style( $this->plugin_name . '-vendors' ); |
|
|
|
|
160
|
|
|
wp_enqueue_style( $this->plugin_name . '-admin' ); |
161
|
|
|
wp_enqueue_script( $this->plugin_name . '-admin' ); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|