| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
class WPC_Shipment_History_Map{ |
| 6 |
function __construct(){ |
| 7 |
add_action( 'admin_enqueue_scripts', array( $this,'admin_scripts' ) ); |
| 8 |
//** Settings |
| 9 |
add_action( 'admin_menu', array($this, 'admin_menu') ); |
| 10 |
add_action( 'admin_init', array($this, 'plugin_init') ); |
| 11 |
add_action( 'wpc_add_settings_nav', array( $this, 'settings_navigation' ) ); |
| 12 |
} |
| 13 |
function admin_menu(){ |
| 14 |
add_submenu_page( |
| 15 |
'wpcargo-settings', |
| 16 |
wpcargo_map_settings_label(), |
| 17 |
wpcargo_map_settings_label(), |
| 18 |
'manage_options', |
| 19 |
'admin.php?page=wpc-shmap-settings' |
| 20 |
); |
| 21 |
add_submenu_page( |
| 22 |
'wpc-shmap-settings', |
| 23 |
wpcargo_map_settings_label(), |
| 24 |
wpcargo_map_settings_label(), |
| 25 |
'manage_options', |
| 26 |
'wpc-shmap-settings', |
| 27 |
array( $this, 'map_settings_callback' ) |
| 28 |
); |
| 29 |
} |
| 30 |
function plugin_init(){ |
| 31 |
register_setting( 'wpc_shmap_option_group', 'shmap_api' ); |
| 32 |
register_setting( 'wpc_shmap_option_group', 'shmap_active' ); |
| 33 |
register_setting( 'wpc_shmap_option_group', 'shmap_type' ); |
| 34 |
register_setting( 'wpc_shmap_option_group', 'shmap_zoom' ); |
| 35 |
register_setting( 'wpc_shmap_option_group', 'shmap_result' ); |
| 36 |
register_setting( 'wpc_shmap_option_group', 'shmap_label_color' ); |
| 37 |
register_setting( 'wpc_shmap_option_group', 'shmap_label_size' ); |
| 38 |
register_setting( 'wpc_shmap_option_group', 'shmap_marker' ); |
| 39 |
register_setting( 'wpc_shmap_option_group', 'shmap_country_restrict' ); |
| 40 |
register_setting( 'wpc_shmap_option_group', 'shmap_longitude' ); |
| 41 |
register_setting( 'wpc_shmap_option_group', 'shmap_latitude' ); |
| 42 |
register_setting( 'wpc_shmap_option_group', 'shmap_origin_marker' ); |
| 43 |
} |
| 44 |
function settings_navigation(){ |
| 45 |
$view = sanitize_text_field($_GET['page']); |
| 46 |
?> |
| 47 |
<a class="nav-tab <?php echo ( $view == 'wpc-shmap-settings') ? 'nav-tab-active' : '' ; ?>" href="<?php echo esc_url(admin_url().'admin.php?page=wpc-shmap-settings'); ?>" ><?php echo esc_html(wpcargo_map_settings_label()); ?></a> |
| 48 |
<?php |
| 49 |
} |
| 50 |
function map_settings_callback(){ |
| 51 |
$shmap_api = get_option('shmap_api'); |
| 52 |
$shmap_active = get_option('shmap_active'); |
| 53 |
$shmap_type = get_option('shmap_type'); |
| 54 |
$shmap_zoom = get_option('shmap_zoom'); |
| 55 |
$shmap_result = get_option('shmap_result'); |
| 56 |
$shmap_label_color = get_option('shmap_label_color'); |
| 57 |
$shmap_label_size = get_option('shmap_label_size'); |
| 58 |
$shmap_marker = get_option('shmap_marker'); |
| 59 |
$shmap_country_restrict = get_option('shmap_country_restrict'); |
| 60 |
$shmap_longitude = !empty(get_option('shmap_longitude') ) ? get_option('shmap_longitude') : -87.65; |
| 61 |
$shmap_latitude = !empty(get_option('shmap_latitude') ) ? get_option('shmap_latitude') : 41.85; |
| 62 |
$shmap_origin_marker = !empty(get_option('shmap_origin_marker') ) ? get_option('shmap_origin_marker') : ''; |
| 63 |
?> |
| 64 |
<div class="wrap"> |
| 65 |
<h1><?php echo esc_html(wpcargo_map_settings_label()); ?></h1> |
| 66 |
<?php require_once( WPCARGO_PLUGIN_PATH.'admin/templates/admin-navigation.tpl.php' ); ?> |
| 67 |
<div class="postbox"> |
| 68 |
<div class="inside"> |
| 69 |
<?php require_once( WPCARGO_PLUGIN_PATH.'admin/templates/history-map-settings.tpl.php' ); ?> |
| 70 |
</div> |
| 71 |
</div> |
| 72 |
</div> |
| 73 |
<?php |
| 74 |
} |
| 75 |
function admin_scripts(){ |
| 76 |
$screen = get_current_screen(); |
| 77 |
$shmap_active = get_option('shmap_active'); |
| 78 |
if( $screen->post_type == 'wpcargo_shipment' && $screen->base == 'post' && $shmap_active ){ |
| 79 |
wp_enqueue_style( 'wpc-shmap-styles', WPCARGO_PLUGIN_URL.'admin/assets/css/shmap-style.css', array(), WPCARGO_VERSION, true ); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
new WPC_Shipment_History_Map; |