Added system of measurement to settings page

This commit is contained in:
Justin Foell
2013-02-17 22:14:10 -06:00
parent cfa7b083f9
commit 8d511f72ec
4 changed files with 51 additions and 22 deletions
+6 -12
View File
@@ -18,10 +18,12 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
//$widget_id = $args['widget_id'];
$title = apply_filters('widget_title', empty($instance['title']) ? _e('Rides', 'wp-strava') : $instance['title']);
$strava_search_option = empty($instance['strava_search_option']) ? 'athlete' : $instance['strava_search_option'];
$strava_som_option = empty($instance['strava_som_option']) ? 'metric' : $instance['strava_som_option'];
$strava_search_id = empty($instance['strava_search_id']) ? '' : $instance['strava_search_id'];
$quantity = empty($instance['quantity']) ? '5' : $instance['quantity'];
$wpstrava = WPStrava::get_instance();
$strava_som_option = $wpstrava->settings->som;
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
@@ -54,7 +56,6 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
public function form($instance) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : _e('Rides', 'wp-strava');
$strava_search_option = isset($instance['strava_search_option']) ? esc_attr($instance['strava_search_option']) : "athlete";
$strava_som_option = isset($instance['strava_som_option']) ? esc_attr($instance['strava_som_option']) : "metric";
$strava_search_id = isset($instance['strava_search_id']) ? esc_attr($instance['strava_search_id']) : "";
$quantity = isset($instance['quantity']) ? absint($instance['quantity']) : 5;
@@ -71,13 +72,6 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
<option value="club" <?php selected($strava_search_option, 'club'); ?>><?php _e("Club", "wp-strava")?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('strava_som_option'); ?>"><?php _e('System of Measurement:'); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('strava_som_option'); ?>" name="<?php echo $this->get_field_name('strava_som_option'); ?>">
<option value="metric" <?php selected($strava_som_option, 'metric'); ?>><?php _e("Metric", "wp-strava")?></option>
<option value="english" <?php selected($strava_som_option, 'english'); ?>><?php _e("English", "wp-strava")?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('strava_search_id'); ?>"><?php _e('Search Id:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('strava_search_id'); ?>" name="<?php echo $this->get_field_name('strava_search_id'); ?>" type="text" value="<?php echo $strava_search_id; ?>" />
@@ -117,8 +111,8 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
'elapsedTime' => __('hours','wp-strava'),
'movingTime' => __('hours','wp-strava'),
'distance' => __('miles','wp-strava'),
'averageSpeed' => __('miles/h','wp-strava'),
'maximumSpeed' => __('miles/h','wp-strava'),
'averageSpeed' => __('mph','wp-strava'),
'maximumSpeed' => __('mph','wp-strava'),
'elevationGain' => __('feet','wp-strava')
);
}
+35 -7
View File
@@ -18,24 +18,32 @@ class WPStrava_Settings {
public function register_strava_settings() {
register_setting('wp-strava-settings-group','strava_email', array( $this, 'sanitize_email' ) );
register_setting('wp-strava-settings-group','strava_password', '__return_null' );
register_setting('wp-strava-settings-group','strava_password', NULL );
register_setting('wp-strava-settings-group','strava_token', array( $this, 'sanitize_token' ) );
add_settings_section( 'strava_api', NULL, '__return_null', 'wp-strava' ); //NULL / __return_null no section label needed
add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); //NULL / NULL no section label needed
add_settings_field( 'strava_email', __( 'Strava Email', 'wp-strava' ), array( $this, 'print_email_input' ), 'wp-strava', 'strava_api' );
add_settings_field( 'strava_password', __( 'Strava Password', 'wp-strava' ), array( $this, 'print_password_input' ), 'wp-strava', 'strava_api' );
add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' );
register_setting('wp-strava-settings-group','strava_som', array( $this, 'sanitize_som' ) );
add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), NULL, 'wp-strava' );
add_settings_field( 'strava_som', __( 'System of Measurement', 'wp-strava' ), array( $this, 'print_som_input' ), 'wp-strava', 'strava_options' );
}
public function print_api_instructions() {
?><p><?php _e( 'Please specify the options below in order to obtain an authentication token, this will work with the Strava shortcodes supported by this plugin, the widget options are independant.', 'wp-strava');?> </p><?php
}
public function print_strava_options() {
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div>
<h2><?php _e( 'Strava Options', 'wp-strava' ); ?></h2>
<p><?php _e( 'Please specify the options below in order to obtain an authentication token, this will work with the Strava shortcodes supported by this plugin, the widget options are independant.', 'wp-strava');?> </p>
<h2><?php _e( 'Strava Settings', 'wp-strava' ); ?></h2>
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
<?php settings_fields( 'wp-strava-settings-group' ); ?>
<?php do_settings_sections( 'wp-strava' ); ?>
@@ -88,5 +96,25 @@ class WPStrava_Settings {
return $token;
}
}
public function print_options_label() {
?><p>Options</p><?php
}
public function print_som_input() {
$strava_som = get_option( 'strava_som' );
?>
<select id="strava_som" name="strava_som">
<option value="metric" <?php selected( $strava_som, 'metric' ); ?>><?php _e( 'Metric', 'wp-strava' )?></option>
<option value="english" <?php selected( $strava_som, 'english' ); ?>><?php _e( 'English', 'wp-strava' )?></option>
</select>
<?php
}
public function sanitize_som( $som ) {
return $som;
}
public function __get( $name ) {
return get_option( "strava_{$name}" );
}
}
+9 -2
View File
@@ -6,7 +6,7 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestRidesWidget.class.php';
class WPStrava {
private static $instance = NULL;
public $settings = NULL;
private $settings = NULL;
private function __construct() {
$this->settings = new WPStrava_Settings();
@@ -16,7 +16,7 @@ class WPStrava {
}
// Register StravaLatestRidesWidget widget
add_action('widgets_init', function() { return register_widget('WPStrava_LatestRidesWidget'); });
add_action( 'widgets_init', function() { return register_widget( 'WPStrava_LatestRidesWidget' ); } );
}
@@ -25,4 +25,11 @@ class WPStrava {
self::$instance = new WPStrava();
return self::$instance;
}
public function __get( $name ) {
if ( isset( $this->{$name} ) )
return $this->{$name};
return NULL;
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
$wpstrava = WPStrava::get_instance();
//@TODO only load these when needed
//@TODO only load these when needed using is_active_widget()
function load_styles() {
// Register a personalized stylesheet
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );