settings menu->ank google map */ add_action('admin_menu', array($this, 'agm_settings_menu')); /* * Additional link */ add_filter('plugin_row_meta', array($this, 'agm_set_plugin_meta'), 10, 2); /* * Save settings if first time */ if (false == get_option('ank_google_map')) { $this->agm_settings_init(); } /* * Register our short-code [ank_google_map] */ add_shortcode('ank_google_map', array($this, 'agm_shortCode')); /* * Some (Notice) text on top of option page */ add_action( 'admin_notices', array($this, 'agm_notice') ) ; }/*end constructor*/ private function agm_settings_page_url() { return add_query_arg('page', 'agm_settings', 'options-general.php'); } function agm_settings_menu() { $page_hook_suffix =add_submenu_page('options-general.php', 'Ank Google Map', 'Ank Google Map', 'manage_options', 'agm_settings', array($this, 'agm_settings_page')); /* * load color picker on plugin options page only */ add_action('admin_print_scripts-'. $page_hook_suffix, array($this, 'agm_add_color_picker')); /* * add help drop down menu on option page */ if ( version_compare( $GLOBALS['wp_version'], '3.3', '>=' ) ) { add_action( "load-$page_hook_suffix", array( $this, 'agm_help_menu' ) ); } } function agm_plugin_actions_links($links, $file) { static $plugin; $plugin = plugin_basename(__FILE__); if ($file == $plugin && current_user_can('manage_options')) { array_unshift( $links, sprintf('%s', esc_attr($this->agm_settings_page_url()), __('Settings')) ); } return $links; } function agm_set_plugin_meta($links,$file) { /* * additional link on plugin list page */ static $plugin; $plugin = plugin_basename( __FILE__ ); if ( $file == $plugin ) { $links[] = 'Read Me'; $links[] = 'GitHub'; } return $links; } function agm_settings_page() { /* * get settings page from this separate file */ if(is_file(__DIR__.'/agm_options_page.php')){ require('agm_options_page.php'); }else{ wp_die(__('A required file not found on server. Reinstall this plugin.
If problem persist, contact plugin developer.')); } } /* * Add a help tab at top of plugin option page */ public static function agm_help_menu(){ /*get current screen obj*/ $curr_screen = get_current_screen(); $curr_screen->add_help_tab( array( 'id' => 'agm-overview', 'title' => 'Overview', 'content' =>'

Thanks for using "Ank Google Map"
'. 'This plugin allows you to put a custom Google Map on your website. Just configure options below and'. 'save your settings. Copy/paste [ank_google_map] short-code on your page/post/widget to view your map.

' ) ); $curr_screen->add_help_tab( array( 'id' => 'agm-troubleshoot', 'title' => 'Troubleshoot', 'content' =>'

Things to remember
'. '

' ) ); $curr_screen->add_help_tab( array( 'id' => 'agm-more-info', 'title' => 'More', 'content' =>'

Need more information ?
'. 'A brief FAQ is available on plugin's official website.'. 'Click here for more.
'. 'You can report a bug at plugin's GitHub page.'. 'I will try to reply as soon as possible.

' ) ); /*help sidebar links */ $curr_screen->set_help_sidebar( '

Quick Links

' . '

Plugin FAQ

' . '

Plugin Home

' ); } function agm_notice(){ /* * Print notice text on top of our option page only */ $dir = is_rtl() ? 'left' : 'right'; if(strpos( get_current_screen()->id, 'agm_settings' ) !== false) echo "

Need help ? Just click here ⟹

"; } function agm_settings_init() { /* * these are default settings * save settings in array for faster access */ $new_options = array( 'div_width' => '100', 'div_width_unit' => 2, 'div_height' => '300', 'div_border_color' => '#ccc', 'map_Lat' => '29.6969365', 'map_Lng' => '77.6766793', 'map_zoom' => 2, 'map_control_1' => '0', 'map_control_2' => '0', 'map_control_3' => '0', 'map_control_4' => '0', 'map_control_5' => '0', 'map_lang_code' => 'en', 'map_type' => 1, 'marker_on' => '1', 'marker_title' => 'I am here', 'marker_anim' => 1, 'marker_color' => 1, 'info_on' => '1', 'info_text' => 'Your Destination', 'info_state' => '0' ); /* * save default settings to wp_options table * */ add_option('ank_google_map', $new_options); } function agm_add_color_picker() { /* * Add the color picker js + css file (for settings page only) * Available for wp v3.5+ only */ if(version_compare($GLOBALS['wp_version'],3.5)>=0){ wp_enqueue_style('wp-color-picker'); wp_enqueue_script('wp-color-picker'); } } function agm_marker_url($id){ /** * We depends on Google server for maker images * @source http://ex-ample.blogspot.in/2011/08/all-url-of-markers-used-by-google-maps.html */ $path=array( /* 1 is reserved for default */ '2'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker.png', '3'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_black.png', '4'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_grey.png', '5'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_orange.png', '6'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_white.png', '7'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_yellow.png', '8'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_purple.png', '9'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_green.png', ); if(array_key_exists($id,$path)){ return $path[$id]; }else{ return false; } } /* ********* front end started ********* */ function agm_write_html() { $options = get_option('ank_google_map'); /* * Decide some options here */ $w_unit = ($options["div_width_unit"] === 1) ? 'px' : '%'; $b_color=(esc_attr($options["div_border_color"])==='')? '' : 'border:1px solid '.esc_attr($options["div_border_color"]); echo '
'; } function agm_write_css(){ /* * Special fixes for google map controls. * They may appear incorrectly due to theme style */ echo ""; } function agm_write_js() { $options = get_option('ank_google_map'); /* * Decide some options here */ $mapType = 'ROADMAP'; if ($options['map_type'] === 1) { $mapType = 'ROADMAP'; } elseif ($options['map_type'] === 2) { $mapType = 'SATELLITE'; } elseif ($options['map_type'] === 3) { $mapType = 'HYBRID'; } elseif ($options['map_type'] === 4) { $mapType = 'TERRAIN'; } $marker_anim = 'DROP'; if ($options['marker_on'] === '1') { if ($options['marker_anim'] == 2) { $marker_anim = 'BOUNCE'; } elseif ($options['marker_anim'] == 3) { $marker_anim = 'DROP'; } } /* * let browser+google decide the map language if no lang code specified by user */ $lang_code=(esc_attr($options['map_lang_code'])==='')? '' : '?language='.esc_attr($options['map_lang_code']); ?> agm_trim_js(ob_get_clean()); } function agm_trim_js($buffer) { /*we don't try to remove comments- can cause malfunction*/ /* remove tabs, spaces, newlines, etc. */ $buffer = str_replace(array("\r\n", "\r", "\t", "\n", ' ', ' ', ' '), '', $buffer); /* remove other spaces before/after ) */ $buffer = preg_replace(array('(( )+\))', '(\)( )+)'), ')', $buffer); return $buffer; } function agm_shortCode($params) { /* * Merge user parameters with default */ $params=shortcode_atts(array( 'css_fix'=>1 ),$params); ob_start();/* ob_start is here for a reason */ /* * We accept one parameter in our short-code * [ank_google_map css_fix=0] will disable css-fixes */ if($params['css_fix']==1){ /*write css fixes*/ $this->agm_write_css(); } /*write html*/ $this->agm_write_html(); /* * put js at footer, also prevent duplicate inclusion */ add_action('wp_footer', array($this, 'agm_write_js')); return ob_get_clean(); } } /*end class ank_google_map*/ } /*end if class exists*/ if ( class_exists( 'Ank_Google_Map' ) ) { /*Init class */ new Ank_Google_Map(); } /* * use [ank_google_map] short code (default) * OR * use [ank_google_map css_fix=0] to disable writing of css-fixes */ ?>