1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodexShaper\WP\Admin\Menus; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Admin Pages Handler. |
7
|
|
|
*/ |
8
|
|
|
class Admin |
9
|
|
|
{ |
10
|
|
|
public function __construct() |
11
|
|
|
{ |
12
|
|
|
add_action('admin_menu', [$this, 'admin_menu']); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Register our menu page. |
17
|
|
|
* |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
|
|
public function admin_menu() |
21
|
|
|
{ |
22
|
|
|
global $submenu; |
23
|
|
|
|
24
|
|
|
$capability = 'manage_options'; |
25
|
|
|
$slug = 'wp-oauth'; |
26
|
|
|
|
27
|
|
|
$hook = add_menu_page(__('WP OAuth2 Server', 'textdomain'), __('WP OAuth2 Server', 'textdomain'), $capability, $slug, [$this, 'plugin_page'], 'dashicons-text'); |
28
|
|
|
|
29
|
|
|
if (current_user_can($capability)) { |
30
|
|
|
$submenu[$slug][] = [__('Clients', 'textdomain'), $capability, 'admin.php?page='.$slug.'#/clients']; |
31
|
|
|
$submenu[$slug][] = [__('Settings', 'textdomain'), $capability, 'admin.php?page='.$slug.'#/settings']; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
add_action('load-'.$hook, [$this, 'init_hooks']); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Initialize our hooks for the admin page. |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function init_hooks() |
43
|
|
|
{ |
44
|
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Load scripts and styles for the app. |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function enqueue_scripts() |
53
|
|
|
{ |
54
|
|
|
wp_enqueue_style('wpb-vendors'); |
55
|
|
|
wp_enqueue_style('wpb-admin'); |
56
|
|
|
wp_enqueue_script('wpb-admin'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Render our admin page. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function plugin_page() |
65
|
|
|
{ |
66
|
|
|
echo '<div class="wrap"><div id="wpb-admin" csrf-token="'.csrf_token().'"></div></div>'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|