settings menu */ 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 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')); } 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')); } 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) { /* * additional link on plugin list page */ $links[] = 'Read Me'; return $links; } function agm_settings_page() { /* * get settings page from this separate file */ require('agm_options_page.php'); } 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_height_unit' => 1, '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){ /** * 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', ); return $path[$id]; } /* ********* 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' : '%'; $h_unit = ($options["div_height_unit"] === 1) ? 'px' : '%'; echo '
'; } function agm_write_css(){ /* * Special fixes for google map controls. * They appears 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'; } } ?> 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() { ob_start(); $this->agm_write_css(); //write css fixes $this->agm_write_html(); //write html add_action('wp_footer', array($this, 'agm_write_js')); //put js code in footer return ob_get_clean(); } } //end class new Ank_Google_Map(); //use [ank_google_map] short code ?>