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