PluginProbe
Leaflet Map / 2.22.0
Leaflet Map v2.22.0
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / class.admin.php

class.admin.php in Leaflet Map 2.22.0, at class.admin.php

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