forked from bozdoz/wp-plugin-leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.admin.php
121 lines (105 loc) · 3.97 KB
/
class.admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Used to generate an admin for Leaflet Map
*
* PHP Version 5.5
*
* @category Admin
* @author Benjamin J DeLong <[email protected]>
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* Leaflet_Map_Admin class
*/
class Leaflet_Map_Admin
{
/**
* Singleton Instance
*
* @var Leaflet_Map_Admin $_instance
*/
private static $_instance = null;
/**
* Singleton
*
* @static
*
* @return Leaflet_Map_Admin
*/
public static function init()
{
if (!self::$_instance) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Instantiate the class
*/
private function __construct()
{
add_action('admin_init', array($this, 'admin_init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_enqueue_scripts', array('Leaflet_Map', 'enqueue_and_register'));
/* add settings to plugin page */
add_filter('plugin_action_links_' . plugin_basename(LEAFLET_MAP__PLUGIN_FILE), array($this, 'plugin_action_links'));
}
/**
* Admin init registers styles
*/
public function admin_init()
{
wp_register_style('leaflet_admin_stylesheet', plugins_url('style.css', LEAFLET_MAP__PLUGIN_FILE));
}
/**
* Add admin menu page when user in admin area
*/
public function admin_menu()
{
$leaf = 'data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgZm9jdXNhYmxlPSJmYWxzZSIgZGF0YS1wcmVmaXg9ImZhcyIgZGF0YS1pY29uPSJsZWFmIiBjbGFzcz0ic3ZnLWlubGluZS0tZmEgZmEtbGVhZiBmYS13LTE4IiByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDU3NiA1MTIiPjxwYXRoIGZpbGw9ImN1cnJlbnRDb2xvciIgZD0iTTU0Ni4yIDkuN2MtNS42LTEyLjUtMjEuNi0xMy0yOC4zLTEuMkM0ODYuOSA2Mi40IDQzMS40IDk2IDM2OCA5NmgtODBDMTgyIDk2IDk2IDE4MiA5NiAyODhjMCA3IC44IDEzLjcgMS41IDIwLjVDMTYxLjMgMjYyLjggMjUzLjQgMjI0IDM4NCAyMjRjOC44IDAgMTYgNy4yIDE2IDE2cy03LjIgMTYtMTYgMTZDMTMyLjYgMjU2IDI2IDQxMC4xIDIuNCA0NjhjLTYuNiAxNi4zIDEuMiAzNC45IDE3LjUgNDEuNiAxNi40IDYuOCAzNS0xLjEgNDEuOC0xNy4zIDEuNS0zLjYgMjAuOS00Ny45IDcxLjktOTAuNiAzMi40IDQzLjkgOTQgODUuOCAxNzQuOSA3Ny4yQzQ2NS41IDQ2Ny41IDU3NiAzMjYuNyA1NzYgMTU0LjNjMC01MC4yLTEwLjgtMTAyLjItMjkuOC0xNDQuNnoiLz48L3N2Zz4=';
$admin = "manage_options";
$author = "edit_posts";
if (current_user_can($admin)) {
$main_link = 'leaflet-map';
$main_page = array($this, "settings_page");
} else {
$main_link = 'leaflet-shortcode-helper';
$main_page = array($this, "shortcode_page");
}
add_menu_page("Leaflet Map", "Leaflet Map", $author, $main_link, $main_page, $leaf);
add_submenu_page("leaflet-map", "Default Values", "Default Values", $admin, "leaflet-map", array($this, "settings_page"));
add_submenu_page("leaflet-map", "Shortcode Helper", "Shortcode Helper", $author, "leaflet-shortcode-helper", array($this, "shortcode_page"));
}
/**
* Main settings page includes form inputs
*/
public function settings_page()
{
wp_enqueue_style('leaflet_admin_stylesheet');
$settings = Leaflet_Map_Plugin_Settings::init();
$plugin_data = get_plugin_data(LEAFLET_MAP__PLUGIN_FILE);
include 'templates/settings.php';
}
/**
* Shortcode page shows example shortcodes and an interactive generator
*/
public function shortcode_page()
{
wp_enqueue_style('leaflet_admin_stylesheet');
wp_enqueue_script('custom_plugin_js', plugins_url('scripts/shortcode-helper.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);
include 'templates/shortcode-helper.php';
}
/**
* Add settings link to the plugin on Installed Plugins page
*
* @return array
*/
public function plugin_action_links($links)
{
$links[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=leaflet-map') ) .'">Settings</a>';
return $links;
}
}