Added check for distance_min and make sure it's a positive integer - fixes Issue #7

Revise name/token update settings
Minor formatting
This commit is contained in:
Justin Foell
2017-12-08 12:33:29 -06:00
parent 7f65a6c145
commit 4668b4fc4e
4 changed files with 43 additions and 28 deletions
+14 -7
View File
@@ -40,9 +40,12 @@ class WPStrava_API {
else
$error = print_r( $response, true );
return new WP_Error( 'wp-strava_post',
sprintf( __( 'ERROR %s %s - %s', 'wp-strava'), $response['response']['code'], $response['response']['message'], $error ),
$response );
return new WP_Error(
'wp-strava_post',
// translators: message shown when there's a problem with ab HTTP POST to the Strava API.
sprintf( __( 'ERROR %1$s %2$s - See full error by adding <code>define( \'WP_STRAVA_DEBUG\' true );</code> to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
$error
);
}
return json_decode( $response['body'] );
@@ -53,8 +56,9 @@ class WPStrava_API {
$url .= $uri;
if ( ! empty( $args ) )
if ( ! empty( $args ) ) {
$url = add_query_arg( $args, $url );
}
$get_args = array(
'headers' => array(),
@@ -79,9 +83,12 @@ class WPStrava_API {
else
$error = print_r( $response, true );
return new WP_Error( 'wp-strava_get',
sprintf( __( 'ERROR %s %s - %s', 'wp-strava' ), $response['response']['code'], $response['response']['message'], $error ),
$response );
return new WP_Error(
'wp-strava_get',
// translators: message shown when there's a problem with an HTTP GET to the Strava API.
sprintf( __( 'ERROR %1$s %2$s - See full error by adding <code>define( \'WP_STRAVA_DEBUG\' true );</code> to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
$error
);
}
return json_decode( $response['body'] );
+2 -1
View File
@@ -64,7 +64,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity Map', 'wp-strava' ) : $instance['title'] );
$athlete_token = isset( $instance['athlete_token'] ) ? $instance['athlete_token'] : WPStrava::get_instance()->settings->get_default_token();
$distance_min = $instance['distance_min'];
$distance_min = empty( $instance['distance_min'] ) ? 0 : absint( $instance['distance_min'] );
$strava_club_id = empty( $instance['strava_club_id'] ) ? null : $instance['strava_club_id'];
$build_new = false;
@@ -80,6 +80,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
if ( is_wp_error( $rides ) ) {
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
if ( WPSTRAVA_DEBUG ) {
echo '<pre>';
print_r($rides);
+23 -18
View File
@@ -1,7 +1,7 @@
<?php
/**
* v3 - http://strava.github.io/api/v3/oauth/
* V3 - http://strava.github.io/api/v3/oauth/
*
* Set up an "API Application" at Strava
* Save the Client ID and Client Secret in WordPress - redirect to strava oauth/authorize URL for permission
@@ -61,11 +61,13 @@ class WPStrava_Settings {
}
public function add_strava_menu() {
add_options_page( __( 'Strava Settings', 'wp-strava' ),
__( 'Strava', 'wp-strava' ),
'manage_options',
$this->page_name,
array( $this, 'print_strava_options' ) );
add_options_page(
__( 'Strava Settings', 'wp-strava' ),
__( 'Strava', 'wp-strava' ),
'manage_options',
$this->page_name,
array( $this, 'print_strava_options' )
);
}
public function init() {
@@ -143,7 +145,7 @@ class WPStrava_Settings {
$app_name = sprintf( esc_html( '%s Strava', 'wp-strava' ), $blog_name );
$site_url = site_url();
$description = 'WP-Strava for ' . $blog_name;
printf( __( "<p>Steps:</p>
printf( __( "<p>Steps:</p>
<ol>
<li>Create your free API Application/Connection here: <a href='%1\$s' target='_blank'>%2\$s</a> using the following information:</li>
<ul>
@@ -171,7 +173,7 @@ class WPStrava_Settings {
public function print_gmaps_instructions() {
$maps_url = 'https://developers.google.com/maps/documentation/static-maps/';
printf( __( "<p>Steps:</p>
printf( __( "<p>Steps:</p>
<ol>
<li>To use Google map images, you must create a Static Maps API Key. Create a free key by going here: <a href='%1\$s' target='_blank'>%2\$s</a> and clicking <strong>Get a Key</strong></li>
<li>Once you've created your Google Static Maps API Key, enter the key below.
@@ -184,7 +186,7 @@ class WPStrava_Settings {
<div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div>
<h2><?php esc_html_e( 'Strava Settings', 'wp-strava' ); ?></h2>
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
<?php settings_fields( $this->option_page ); ?>
<?php do_settings_sections( 'wp-strava' ); ?>
@@ -245,18 +247,21 @@ class WPStrava_Settings {
}
public function sanitize_nickname( $nicknames ) {
$second2last = $last = false;
if ( ! $this->adding_athlete ) {
$last = end( $nicknames );
$second2last = prev( $nicknames );
// Chop $nicknames to same size as tokens.
$nicknames = array_slice( $nicknames, 0, count( $_POST['strava_token'] ) );
$token_index = count( $nicknames ) - 1;
if ( $last === '' && $second2last !== '' &&
empty( $_POST['strava_token'][ $token_index ] ) ) {
// Remove last (blank) entry if not trying to add an additional athlete.
array_pop( $nicknames );
// Remove indexes from $nicknames that have empty tokens.
foreach( $_POST['strava_token'] as $index => $token ) {
$token = trim( $token );
if ( empty( $token ) ) {
unset( $nicknames[ $index ] );
}
}
// Process $nicknames so indexes start with zero.
$nicknames = array_merge( $nicknames, array() );
}
foreach ( $nicknames as $index => $nickname ) {
@@ -409,7 +414,7 @@ class WPStrava_Settings {
* @author Justin Foell
* @since 1.2.0
*
* @param integer $number
* @param integer $number Athlete number (default 1).
* @return string
*/
private function get_default_nickname( $number = 1 ) {
+4 -2
View File
@@ -2,8 +2,8 @@
Contributors: cmanon, jrfoell, lancewillett
Tags: strava, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin
Requires at least: 4.6
Tested up to: 4.7
Stable tag: 1.1.1
Tested up to: 4.9
Stable tag: 1.2.0
License: GPLv2 or later
Show your Strava activity on your WordPress site.
@@ -37,6 +37,8 @@ Strava Latest Map - shows map of latest activity with option to limit latest map
Added multi-athlete configuration.
Additional transitions from Ride -> Activity.
Updated setup instructions to reflect latest Strava API set up process.
Backwards Compatibility - removed PHP 5.3+ specific operator (should work with PHP 5.2 now - versions 1.1 and 1.1.1 don't).
Reworked error reporting and formatting.
= 1.1.1 =
Changes to better support translations through https://translate.wordpress.org.