Permalink
Browse files

Re-work settings page to use WordPress Settings API.

  • Loading branch information...
benhuson committed Aug 2, 2012
1 parent 6eec73a commit ec7120ec5b2674fe319b031a942973f79caff6ba
Showing with 226 additions and 149 deletions.
  1. +1 −1 README.txt
  2. +190 −0 admin/settings.php
  3. BIN img/logo/icon32.png
  4. +34 −147 includes/wp-geo.php
  5. +1 −1 wp-geo.php
View
@@ -2,7 +2,7 @@
Contributors: husobj
Donate link: http://www.wpgeo.com/donate
Tags: maps, map, geo, geocoding, google, location, georss
-Requires at least: 2.9
+Requires at least: 3.0
Tested up to: 3.3.1
Stable tag: 3.2.6.4
View
@@ -9,9 +9,199 @@ class WPGeo_Settings {
* Constructor
*/
function WPGeo_Settings() {
+ $this->register_settings();
$this->filter_plugin_action_links();
}
+ /**
+ * Settings API
+ */
+ function register_settings() {
+
+ // General Settings
+ add_settings_section( 'wpgeo_general', __( 'General Settings', 'wp-geo' ), array( $this, 'wp_mailfrom_settings_section' ), 'wp_geo_options' );
+ add_settings_field( 'google_api_key', __( 'Google API Key', 'wp-geo' ), array( $this, 'google_api_key_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'google_map_type', __( 'Map Type', 'wp-geo' ), array( $this, 'google_map_type_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'show_post_map', __( 'Show Post Map', 'wp-geo' ), array( $this, 'show_post_map_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_map_location', __( 'Default Map Location', 'wp-geo' ), array( $this, 'default_map_location_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_map_width', __( 'Default Map Width', 'wp-geo' ), array( $this, 'default_map_width_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_map_height', __( 'Default Map Height', 'wp-geo' ), array( $this, 'default_map_height_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_map_zoom', __( 'Default Map Zoom', 'wp-geo' ), array( $this, 'default_map_zoom_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_map_controls', __( 'Default Map Controls', 'wp-geo' ), array( $this, 'default_map_controls_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'default_post_options', __( 'Default Post Options', 'wp-geo' ), array( $this, 'default_post_options_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'show_polylines', __( 'Polylines', 'wp-geo' ), array( $this, 'show_polylines_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'polyline_colour', __( 'Polyline Colour', 'wp-geo' ), array( $this, 'polyline_colour_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'show_maps_on', __( 'Show Maps On', 'wp-geo' ), array( $this, 'show_maps_on_field' ), 'wp_geo_options', 'wpgeo_general' );
+ add_settings_field( 'feeds', __( 'Feeds', 'wp-geo' ), array( $this, 'feeds_field' ), 'wp_geo_options', 'wpgeo_general' );
+
+ // Register Settings
+ register_setting( 'wp_geo_options', 'wp_geo_options' );
+ }
+
+ /**
+ * Mail From Settings Section
+ */
+ function wp_mailfrom_settings_section() {
+ echo '<p>'
+ . sprintf( __( "For more information and documentation about this plugin please visit the <a %s>WP Geo Plugin</a> home page.", 'wp-geo' ), 'href="http://www.benhuson.co.uk/wordpress-plugins/wp-geo/"' ) . '<br />'
+ . sprintf( __( "If you experience any problems/bugs with the plugin, please <a %s>log it here</a>.", 'wp-geo' ), 'href="http://code.google.com/p/wp-geo/issues/list"' ) .
+ '</p>';
+ }
+
+ /**
+ * Google API Key Field
+ */
+ function google_api_key_field() {
+ $options = get_option( 'wp_geo_options' );
+ echo '<input name="wp_geo_options[google_api_key]" type="text" id="google_api_key" value="' . $options['google_api_key'] . '" class="regular-text" />';
+ }
+
+ /**
+ * Google Map Type Field
+ */
+ function google_map_type_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->google_map_types( 'menu', $options['google_map_type'], array( 'id' => 'google_map_type', 'name' => 'wp_geo_options[google_map_type]' ) );
+ }
+
+ /**
+ * Show Post Map Field
+ */
+ function show_post_map_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->post_map_menu( 'menu', $options['show_post_map'], array( 'id' => 'show_post_map', 'name' => 'wp_geo_options[show_post_map]' ) ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_excerpts]', 'Y', $options['show_maps_on_excerpts'], false, 'show_maps_on_excerpts' ) . ' ' . __( 'Show on excerpts', 'wp-geo' );
+ }
+
+ /**
+ * Default Map Location Field
+ */
+ function default_map_location_field() {
+ $options = get_option( 'wp_geo_options' );
+ echo __( 'When creating a new post, the map will default to focussing on this area for you to position a marker.', 'wp-geo' ) . '<br />';
+ echo '<label for="default_map_latitude" style="width:70px; display:inline-block;">' . __( 'Latitude', 'wp-geo' ) . '</label> <input name="wp_geo_options[default_map_latitude]" type="text" id="default_map_latitude" value="' . $options['default_map_latitude'] . '" size="25" /><br />';
+ echo '<label for="default_map_longitude" style="width:70px; display:inline-block;">' . __( 'Longitude', 'wp-geo' ) . '</label> <input name="wp_geo_options[default_map_longitude]" type="text" id="default_map_longitude" value="' . $options['default_map_longitude'] . '" size="25" />';
+ }
+
+ /**
+ * Default Map Width Field
+ */
+ function default_map_width_field() {
+ $options = get_option( 'wp_geo_options' );
+ echo '<input name="wp_geo_options[default_map_width]" type="text" id="default_map_width" value="' . $options['default_map_width'] . '" size="10" />';
+ }
+
+ /**
+ * Default Map Height Field
+ */
+ function default_map_height_field() {
+ $options = get_option( 'wp_geo_options' );
+ echo '<input name="wp_geo_options[default_map_height]" type="text" id="default_map_height" value="' . $options['default_map_height'] . '" size="10" />';
+ }
+
+ /**
+ * Default Map Height Field
+ */
+ function default_map_zoom_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->selectMapZoom( 'menu', $options['default_map_zoom'], array( 'id' => 'default_map_zoom', 'name' => 'wp_geo_options[default_map_zoom]' ) );
+ }
+
+ /**
+ * Default Map Controls Field
+ */
+ function default_map_controls_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->selectMapControl( 'menu', $options['default_map_control'], array( 'id' => 'default_map_control', 'name' => 'wp_geo_options[default_map_control]' ) ). '<br />';
+ echo '<p style="margin:1em 0 0 0;"><strong>' . __( 'Map Type Controls', 'wp-geo' ) . '</strong></p>';
+ echo '<p style="margin:0;">' . __( 'You must select at least 2 map types for the control to show.', 'wp-geo' ) . '</p>';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_normal]', 'Y', $options['show_map_type_normal'], false, 'show_map_type_normal' ) . ' ' . __( 'Normal map', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_satellite]', 'Y', $options['show_map_type_satellite'], false, 'show_map_type_satellite' ) . ' ' . __( 'Satellite (photographic map)', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_hybrid]', 'Y', $options['show_map_type_hybrid'], false, 'show_map_type_hybrid' ) . ' ' . __( 'Hybrid (photographic map with normal features)', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_physical]', 'Y', $options['show_map_type_physical'], false, 'show_map_type_physical' ) . ' ' . __( 'Physical (terrain map)', 'wp-geo' ) . '<br />';
+ echo '<p style="margin:1em 0 0 0;"><strong>' . __( 'Other Controls', 'wp-geo' ) . '</strong></p>';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_scale]', 'Y', $options['show_map_scale'], false, 'show_map_scale' ) . ' ' . __( 'Show map scale', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_overview]', 'Y', $options['show_map_overview'], false, 'show_map_overview' ) . ' ' . __( 'Show collapsible overview map (in the corner of the map)', 'wp-geo' );
+ }
+
+ /**
+ * Default Post Options Field
+ */
+ function default_post_options_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_zoom]', 'Y', $options['save_post_zoom'], false, 'save_post_zoom' ) . ' ' . __( 'Save custom map zoom for this post', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_map_type]', 'Y', $options['save_post_map_type'], false, 'save_post_map_type' ) . ' ' . __( 'Save custom map type for this post', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_centre_point]', 'Y', $options['save_post_centre_point'], false, 'save_post_centre_point' ) . ' ' . __( 'Save map centre point for this post', 'wp-geo' );
+
+ }
+
+ /**
+ * Show Polylines Field
+ */
+ function show_polylines_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_polylines]', 'Y', $options['show_polylines'], false, 'show_polylines' ) . ' ' . __( 'Show polylines (to connect multiple points on a single map)', 'wp-geo' );
+
+ }
+
+ /**
+ * Polyline Colour Field
+ */
+ function polyline_colour_field() {
+ $options = get_option( 'wp_geo_options' );
+ echo '<input name="wp_geo_options[polyline_colour]" type="text" id="polyline_colour" value="' . $options['polyline_colour'] . '" size="7" />';
+ }
+
+ /**
+ * Show Maps On Field
+ */
+ function show_maps_on_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_pages]', 'Y', $options['show_maps_on_pages'], false, 'show_maps_on_pages' ) . ' ' . __( 'Pages', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_posts]', 'Y', $options['show_maps_on_posts'], false, 'show_maps_on_posts' ) . ' ' . __( 'Posts (single posts)', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_home]', 'Y', $options['show_maps_on_home'], false, 'show_maps_on_home' ) . ' ' . __( 'Posts home page', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_datearchives]', 'Y', $options['show_maps_in_datearchives'], false, 'show_maps_in_datearchives' ) . ' ' . __( 'Posts in date archives', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_categoryarchives]', 'Y', $options['show_maps_in_categoryarchives'], false, 'show_maps_in_categoryarchives' ) . ' ' . __( 'Posts in category archives', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_tagarchives]', 'Y', $options['show_maps_in_tagarchives'], false, 'show_maps_in_tagarchives' ) . ' ' . __( 'Posts in tag archives', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_taxarchives]', 'Y', $options['show_maps_in_taxarchives'], false, 'show_maps_in_taxarchives' ) . ' ' . __( 'Posts in taxonomy archives', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_authorarchives]', 'Y', $options['show_maps_in_authorarchives'], false, 'show_maps_in_authorarchives' ) . ' ' . __( 'Posts in author archives', 'wp-geo' ) . '<br />';
+ echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_searchresults]', 'Y', $options['show_maps_in_searchresults'], false, 'show_maps_in_searchresults' ) . ' ' . __( 'Search Results', 'wp-geo' ) . '<br />';
+
+ // Custom Post Types
+ // Only works in WordPress 3.0+
+ if ( function_exists( 'get_post_types' ) && function_exists( 'post_type_supports' ) ) {
+ $custom_post_type_checkboxes = '';
+ $post_types = get_post_types( array( '_builtin' => false ), 'objects' );
+ foreach ( $post_types as $post_type ) {
+ if ( post_type_supports( $post_type->query_var, 'wpgeo' )) {
+ $custom_post_type_checkboxes .= $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_customposttypes][' . $post_type->query_var . ']', 'Y', 'Y', true ) . ' ' . __( $post_type->label, 'wp-geo' ) . '<br />';
+ } elseif ( $post_type->show_ui ) {
+ $custom_post_type_checkbox_value = isset( $options['show_maps_on_customposttypes'][$post_type->query_var] ) ? $options['show_maps_on_customposttypes'][$post_type->query_var] : '';
+ $custom_post_type_checkboxes .= $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_customposttypes][' . $post_type->query_var . ']', 'Y', $custom_post_type_checkbox_value, false ) . ' ' . __( $post_type->label, 'wp-geo' ) . '<br />';
+ }
+ }
+ if ( ! empty( $custom_post_type_checkboxes ) ) {
+ echo '<strong>Custom Post Types</strong><br />' . $custom_post_type_checkboxes;
+ }
+ }
+ }
+
+ /**
+ * Feeds Field
+ */
+ function feeds_field() {
+ global $wpgeo;
+ $options = get_option( 'wp_geo_options' );
+ echo $wpgeo->options_checkbox( 'wp_geo_options[add_geo_information_to_rss]', 'Y', $options['add_geo_information_to_rss'], false, 'add_geo_information_to_rss' ) . ' ' . __( 'Add geographic information', 'wp-geo' );
+ }
+
/**
* Filter Plugin Action Links
*/
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit ec7120e

Please sign in to comment.