/mkgd-admin.php

  1. <?php 
  2. /** 
  3. * Register Admin Menu 
  4. */ 
  5. add_action('admin_menu', 'register_mkgd_menu_page'); 
  6.  
  7. function register_mkgd_menu_page() { 
  8. add_menu_page('MK Google Directions Settings', 'MK Google Directions', 'add_users', 'mkgdAdminPage', 'mkgd_admin_page', plugins_url('google-distance-calculator/images/mk16.png'), 99); 
  9.  
  10. /** 
  11. * Register settings for the plugin 
  12. */ 
  13. add_action('admin_init', 'mkgd_register_settings'); 
  14.  
  15. function mkgd_register_settings() { 
  16. //register our settings 
  17. register_setting('mkgd-settings-group', 'mkgd_latitude'); 
  18. register_setting('mkgd-settings-group', 'mkgd_longitude'); 
  19. register_setting('mkgd-settings-group', 'mkgd_default_start_point'); 
  20. register_setting('mkgd-settings-group', 'mkgd_show_start_point'); 
  21. register_setting('mkgd-settings-group', 'mkgd_default_destination_point'); 
  22. register_setting('mkgd-settings-group', 'mkgd_show_destination_point'); 
  23. register_setting('mkgd-settings-group', 'mkgd_language'); 
  24. register_setting('mkgd-settings-group', 'mkgd_units'); 
  25. register_setting('mkgd-settings-group', 'mkgd_width'); 
  26. register_setting('mkgd-settings-group', 'mkgd_height'); 
  27.  
  28. /** 
  29. * Load Admin Scripts 
  30. */ 
  31. add_action('admin_enqueue_scripts', 'mkgd_admin_scripts'); 
  32.  
  33. function mkgd_admin_scripts() { 
  34. wp_enqueue_script('mkgd-google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places', array(), '3.0', true); 
  35. wp_enqueue_script('mkgd-admin-google-maps', plugins_url('google-distance-calculator/js/mkgd-admin-google-map.js'), array(), '1.0', true); 
  36. wp_register_style('mkgd-google-maps-css', 'https://fonts.googleapis.com/css?family=Roboto:300, 400, 500', false, '1.0.0'); 
  37. wp_enqueue_style('mkgd-google-maps-css'); 
  38.  
  39. /** 
  40. * Define Options Page 
  41. */ 
  42.  
  43. function mkgd_admin_page() { 
  44. $languages = array( 
  45. 'ARABIC' => 'ar',  
  46. 'BASQUE' => 'eu',  
  47. 'BULGARIAN' => 'bg',  
  48. 'BENGALI' => 'bn',  
  49. 'CATALAN' => 'ca',  
  50. 'CZECH' => 'cs',  
  51. 'DANISH' => 'da',  
  52. 'GERMAN' => 'de',  
  53. 'GREEK' => 'el',  
  54. 'ENGLISH' => 'en',  
  55. 'ENGLISH (AUSTRALIAN)' => 'en-AU',  
  56. 'ENGLISH (GREAT BRITAIN)' => 'en-GB',  
  57. 'SPANISH' => 'es',  
  58. 'BASQUE' => 'eu',  
  59. 'FARSI' => 'fa',  
  60. 'FINNISH' => 'fi',  
  61. 'FILIPINO' => 'fil',  
  62. 'FRENCH' => 'fr',  
  63. 'GALICIAN' => 'gl',  
  64. 'GUJARATI' => 'gu',  
  65. 'HINDI' => 'hi',  
  66. 'CROATIAN' => 'hr',  
  67. 'HUNGARIAN' => 'hu',  
  68. 'INDONESIAN' => 'id',  
  69. 'ITALIAN' => 'it',  
  70. 'HEBREW' => 'iw',  
  71. 'JAPANESE' => 'ja',  
  72. 'KANNADA' => 'kn',  
  73. 'KOREAN' => 'ko',  
  74. 'LITHUANIAN' => 'lt',  
  75. 'LATVIAN' => 'lv',  
  76. 'MALAYALAM' => 'ml',  
  77. 'MARATHI' => 'mr',  
  78. 'DUTCH' => 'nl',  
  79. 'NORWEGIAN' => 'no',  
  80. 'POLISH' => 'pl',  
  81. 'PORTUGUESE' => 'pt',  
  82. 'PORTUGUESE (BRAZIL)' => 'pt-BR',  
  83. 'PORTUGUESE (PORTUGAL)' => 'pt-PT',  
  84. 'ROMANIAN' => 'ro',  
  85. 'RUSSIAN' => 'ru',  
  86. 'SLOVAK' => 'sk',  
  87. 'SLOVENIAN' => 'sl',  
  88. 'SERBIAN' => 'sr',  
  89. 'SWEDISH' => 'sv',  
  90. 'TAGALOG' => 'tl',  
  91. 'TAMIL' => 'ta',  
  92. 'TELUGU' => 'te',  
  93. 'THAI' => 'th',  
  94. 'TURKISH' => 'tr',  
  95. 'UKRAINIAN' => 'uk',  
  96. 'VIETNAMESE' => 'vi',  
  97. 'CHINESE (SIMPLIFIED)' => 'zh-CN',  
  98. 'CHINESE (TRADITIONAL)' => 'zh-TW',  
  99. ); 
  100. $units = array( 
  101. 'Metric (Kilometers & Meters)' => 'metric',  
  102. 'Imperial (Miles & Feet)' => 'imperial',  
  103. ); 
  104. ?> 
  105. <div class="wrap"> 
  106. <h2><img src="<?php echo plugins_url('mk-google-directions/images/mk32.png'); ?>"/> MK Google Directions Settings</h2>  
  107. <form method="post" action="options.php">  
  108. <?php settings_fields('mkgd-settings-group'); ?> 
  109. <?php do_settings_fields('mkgdAdminPage', 'mkgd-settings-group'); ?> 
  110. <table class="widefat"> 
  111. <thead> 
  112. <tr> 
  113. <th>MK Google Directions Configurations</th> 
  114. </tr> 
  115. </thead> 
  116. <tbody> 
  117. <tr> 
  118. <td> 
  119. <table> 
  120. <tr> 
  121. <td><label for="latitude">Latitude: </label></td> 
  122. <td><input type="text" value="<?php echo get_option('mkgd_latitude', '43.6525'); ?>" size="33" name="mkgd_latitude"></td> 
  123. <td><small>Default latitudes for the Google Map <a href="http://itouchmap.com/latlong.html" title="Help" target="_blank" rel="nofollow"><strong>Help?</strong></a></small></td> 
  124. </tr> 
  125. <tr> 
  126. <td><label for="longitude">Longitude: </label></td> 
  127. <td><input type="text" value="<?php echo get_option('mkgd_longitude', '-79.3816667'); ?>" size="33" name="mkgd_longitude"></td> 
  128. <td><small>Default longitudes for the Google Map <a href="http://itouchmap.com/latlong.html" title="Help" target="_blank" rel="nofollow"><strong>Help?</strong></a></small></td> 
  129. </tr> 
  130. <tr> 
  131. <td><label for="mkgd_default_start_point">Set Start Location: </label></td> 
  132. <td> 
  133. <input id="autocomplete_1" placeholder="Enter start location" onFocus="geolocate()" type="text" name="mkgd_default_start_point" value="<?php echo get_option('mkgd_default_start_point'); ?>" size="33" /> 
  134. </td> 
  135. <td><small>This will be used as default start location.</small></td> 
  136. </tr> 
  137. <tr> 
  138. <td><label for="mkgd_show_start_point">Hide Start Location: </label></td> 
  139. <td>  
  140. <input type="checkbox" name="mkgd_show_start_point" value="1" <?php echo get_option('mkgd_show_start_point') == 1 ? 'checked="checked"' : ''; ?>/> 
  141. </td> 
  142. <td><small>Hide start location field.</small></td> 
  143. </tr> 
  144. <tr> 
  145. <td><label for="mkgd_default_destination_point">Set Destination Location: </label></td> 
  146. <td> 
  147. <input id="autocomplete_2" placeholder="Enter destination location" onFocus="geolocate()" type="text" name="mkgd_default_destination_point" value="<?php echo get_option('mkgd_default_destination_point'); ?>" size="33" /> 
  148. </td> 
  149. <td><small>This will be used as default destination location.</small></td> 
  150. </tr>  
  151. <tr> 
  152. <td><label for="mkgd_show_destination_point">Hide Destination Location: </label></td> 
  153. <td>  
  154. <input type="checkbox" name="mkgd_show_destination_point" value="1" <?php echo get_option('mkgd_show_destination_point') == 1 ? 'checked="checked"' : ''; ?>/> 
  155. </td> 
  156. <td><small>Hide destination location field.</small></td> 
  157. </tr> 
  158. <tr> 
  159. <td><label for="language">Language: </label></td> 
  160. <td> 
  161. <select name="mkgd_language"> 
  162. <option value="">-- Select --</option> 
  163. <?php foreach ($languages as $language => $code) { ?> 
  164.  
  165. <option <?php echo get_option('mkgd_language') === $code ? 'selected="selected"' : ''; ?> value="<?php echo $code; ?>"><?php echo $language; ?></option> 
  166. <?php } ?> 
  167. </select> 
  168. </td> 
  169. <td><small>Default language for the Google Map</small></td> 
  170. </tr> 
  171. <tr> 
  172. <td><label for="language">Unit System: </label></td> 
  173. <td> 
  174. <select name="mkgd_units"> 
  175. <option value="">-- Select --</option> 
  176. <?php foreach ($units as $key => $value) { ?> 
  177. <option <?php echo get_option('mkgd_units') === $value ? 'selected="selected"' : ''; ?> value="<?php echo $value; ?>"><?php echo $key; ?></option> 
  178. <?php } ?> 
  179. </select> 
  180. </td> 
  181. <td><small>Default unit system for the Google Map</small></td> 
  182. </tr> 
  183. <tr> 
  184. <td><label for="map-width">Map Width: </label></td> 
  185. <td><input type="text" value="<?php echo get_option('mkgd_width', '500'); ?>" size="33" name="mkgd_width"></td> 
  186. <td><small>Default width for the Google Map</small></td> 
  187. </tr> 
  188. <tr> 
  189. <td><label for="map-width">Map Height: </label></td> 
  190. <td><input type="text" value="<?php echo get_option('mkgd_height', '300'); ?>" size="33" name="mkgd_height"></td> 
  191. <td><small>Default height for the Google Map</small></td> 
  192. </tr> 
  193. </table> 
  194. </td> 
  195. </tr> 
  196. </tbody> 
  197. <tfoot> 
  198. <tr> 
  199. <th>MK Google Directions Configurations</th> 
  200. </tr> 
  201. </tfoot> 
  202. </table> 
  203.  
  204. <?php submit_button(); ?> 
  205.  
  206. </form> 
  207. <table class="widefat"> 
  208. <thead> 
  209. <tr> 
  210. <th>Donate to MK Google Directions</th> 
  211. </tr> 
  212. </thead> 
  213. <tbody> 
  214. <tr> 
  215. <td> 
  216. <h2>If you like the plugin, you can buy me a beer</h2> 
  217. <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7N283YV4KLEQ2" title="Donate" target="_blank"><img src="https://www.paypalobjects.com/en_GB/i/btn/btn_donateCC_LG.gif" alt="Donate" title="Donate" /></a> 
  218. </td> 
  219. </tr> 
  220. </tbody> 
  221. <thead> 
  222. <tr> 
  223. <th>Donate to MK Google Directions</th> 
  224. </tr> 
  225. </thead> 
  226. </table> 
  227. </div><!-- .wrap --> 
  228. <?php 
.