| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
* Used to generate an admin for Leaflet Map |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly |
| 9 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 10 |
|
| 11 |
class Leaflet_Map_Admin { |
| 12 |
/** |
| 13 |
* @var Leaflet_Map_Admin |
| 14 |
**/ |
| 15 |
private static $instance = null; |
| 16 |
|
| 17 |
/** |
| 18 |
* Singleton |
| 19 |
* @static |
| 20 |
*/ |
| 21 |
public static function init() { |
| 22 |
if ( !self::$instance ) { |
| 23 |
self::$instance = new self; |
| 24 |
} |
| 25 |
|
| 26 |
return self::$instance; |
| 27 |
} |
| 28 |
|
| 29 |
private function __construct () { |
| 30 |
add_action('admin_init', array($this, 'admin_init')); |
| 31 |
add_action('admin_menu', array($this, 'admin_menu')); |
| 32 |
add_action('admin_enqueue_scripts', array('Leaflet_Map', 'enqueue_and_register')); |
| 33 |
|
| 34 |
/* add settings to plugin page */ |
| 35 |
add_filter('plugin_action_links_' . plugin_basename(LEAFLET_MAP__PLUGIN_FILE), array($this, 'plugin_action_links')); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Admin init registers styles |
| 40 |
* |
| 41 |
*/ |
| 42 |
|
| 43 |
public function admin_init () { |
| 44 |
wp_register_style('leaflet_admin_stylesheet', plugins_url('style.css', LEAFLET_MAP__PLUGIN_FILE)); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Add admin menu page when user in admin area |
| 49 |
* |
| 50 |
*/ |
| 51 |
|
| 52 |
public function admin_menu () { |
| 53 |
if (current_user_can('manage_options')) { |
| 54 |
$main_link = 'leaflet-map'; |
| 55 |
} else { |
| 56 |
$main_link = 'leaflet-get-shortcode'; |
| 57 |
} |
| 58 |
|
| 59 |
add_menu_page("Leaflet Map", "Leaflet Map", 'manage_options', $main_link, array($this, "settings_page"), plugins_url('images/leaf.png', LEAFLET_MAP__PLUGIN_FILE)); |
| 60 |
add_submenu_page("leaflet-map", "Default Values", "Default Values", 'manage_options', "leaflet-map", array($this, "settings_page")); |
| 61 |
add_submenu_page("leaflet-map", "Shortcode Helper", "Shortcode Helper", 'edit_posts', "leaflet-get-shortcode", array($this, "shortcode_page")); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Main settings page includes form inputs |
| 66 |
* |
| 67 |
*/ |
| 68 |
|
| 69 |
public function settings_page () { |
| 70 |
wp_enqueue_style( 'leaflet_admin_stylesheet' ); |
| 71 |
|
| 72 |
$settings = Leaflet_Map_Plugin_Settings::init(); |
| 73 |
$plugin_data = get_plugin_data(LEAFLET_MAP__PLUGIN_FILE); |
| 74 |
include 'templates/settings.php'; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Shortcode page shows example shortcodes and an interactive generator |
| 79 |
* |
| 80 |
*/ |
| 81 |
public function shortcode_page () { |
| 82 |
wp_enqueue_style( 'leaflet_admin_stylesheet' ); |
| 83 |
wp_enqueue_script('custom_plugin_js', plugins_url('scripts/get-shortcode.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false); |
| 84 |
|
| 85 |
include 'templates/shortcode-helper.php'; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Add settings link to the plugin on Installed Plugins page |
| 90 |
* |
| 91 |
*/ |
| 92 |
public function plugin_action_links ( $links ) { |
| 93 |
$links[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=leaflet-map') ) .'">Settings</a>'; |
| 94 |
return $links; |
| 95 |
} |
| 96 |
} |