Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can now be found on that same strava API Settings page.
-
After saving your Client ID and Secret, you'll be redirected to strava to authorize your API Application. If successful, your Strava Token will display instead of Client ID and Client Secret.
-
If you need to re-authorize your API Application, erase your Strava Token here and click 'Save Changes' to start over.
+
After saving your Client ID and Secret, you'll be redirected to strava to authorize your API Application. If successful, your Strava ID will display in a table, next to your nickname.
+
If you need to re-authorize your API Application, erase your Strava ID next to your nickname and click 'Save Changes' to start over.
To use Google map images, you must create a Static Maps API Key. Create a free key by going here: %2\$s and clicking Get a Key
Once you've created your Google Static Maps API Key, enter the key below.
", 'wp-strava' ), $maps_url, $maps_url );
-
}
/**
@@ -232,21 +177,7 @@ class WPStrava_Settings {
* @since 0.62
*/
public function print_strava_options() {
- ?>
-
-
-
-
-
-
- tokens_empty( $this->tokens ) ? __( 'Default', 'wp-strava' ) : '';
+ $nickname = $this->ids_empty( $this->ids ) ? __( 'Default', 'wp-strava' ) : '';
?>
- * @since 0.62
+ * @since 2.0
*/
- public function print_token_input() {
- foreach ( $this->get_all_tokens() as $token => $nickname ) {
+ public function print_id_input() {
+ foreach ( $this->get_all_ids() as $id => $nickname ) {
?>
-
-
+
+
adding_athlete ) {
- // Chop $nicknames to same size as tokens.
- $nicknames = array_slice( $nicknames, 0, count( $_POST['strava_token'] ) );
+ // Chop $nicknames to same size as ids.
+ $nicknames = array_slice( $nicknames, 0, count( $_POST['strava_id'] ) );
- // Remove indexes from $nicknames that have empty tokens.
- foreach ( $_POST['strava_token'] as $index => $token ) {
- $token = trim( $token );
- if ( empty( $token ) ) {
+ // Remove indexes from $nicknames that have empty ids.
+ foreach ( $_POST['strava_id'] as $index => $id ) {
+ $id = trim( $id );
+ if ( empty( $id ) ) {
unset( $nicknames[ $index ] );
}
}
@@ -378,55 +311,17 @@ class WPStrava_Settings {
}
/**
- * Sanitize the token.
+ * Sanitize the ID.
+ *
+ * Renamed from sanitize_token().
*
* @param string $token
* @return string
* @author Justin Foell
- * @since 0.62
+ * @since 2.0
*/
- public function sanitize_token( $token ) {
- return $token;
- }
-
- /**
- * Fetch the access token from Strava - previously get_token()
- *
- * @param string $code
- * @return mixed Boolean false if there was a problem, token string otherwise.
- * @author Justin Foell
- * @since 1.0
- */
- private function fetch_token( $code ) {
- $client_id = $this->client_id;
- $client_secret = $this->client_secret;
-
- delete_option( 'strava_client_id' );
- delete_option( 'strava_client_secret' );
-
- if ( $client_id && $client_secret ) {
- $api = new WPStrava_API();
- $data = array(
- 'client_id' => $client_id,
- 'client_secret' => $client_secret,
- 'code' => $code,
- );
-
- $strava_info = $api->post( 'oauth/token', $data );
-
- if ( isset( $strava_info->access_token ) ) {
- $this->feedback .= __( 'Successfully authenticated.', 'wp-strava' );
- return $strava_info->access_token;
- }
-
- // Translators: error message from Strava
- $this->feedback .= sprintf( __( 'There was an error receiving data from Strava:
%s
', 'wp-strava' ), print_r( $strava_info, true ) ); // phpcs:ignore -- Debug output.
- return false;
-
- }
-
- $this->feedback .= __( 'Missing Client ID or Client Secret.', 'wp-strava' );
- return false;
+ public function sanitize_id( $id ) {
+ return $id;
}
/**
@@ -561,61 +456,63 @@ class WPStrava_Settings {
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE '_transient_timeout_strava_latest_map_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE '_transient_strava_latest_map_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE 'strava_latest_map%'" );
+
+ delete_option( 'strava_token' );
}
return null;
}
/**
- * Gets all saved strava tokens as an array.
+ * Gets all saved strava ids as an array.
*
* @return array
* @author Justin Foell
- * @since 1.2.0
+ * @since 2.0.0
*/
- public function get_tokens() {
- $tokens = get_option( 'strava_token' );
- if ( ! is_array( $tokens ) ) {
- $tokens = array( $tokens );
+ public function get_ids() {
+ $ids = get_option( 'strava_id' );
+ if ( ! is_array( $ids ) ) {
+ $ids = array( $ids );
}
- foreach ( $tokens as $index => $token ) {
- if ( empty( $token ) ) {
- unset( $tokens[ $index ] );
- $tokens = array_values( $tokens ); // Rebase array keys after unset @see https://stackoverflow.com/a/5943165/2146022
+ foreach ( $ids as $index => $id ) {
+ if ( empty( $id ) ) {
+ unset( $ids[ $index ] );
+ $ids = array_values( $ids ); // Rebase array keys after unset @see https://stackoverflow.com/a/5943165/2146022
}
}
- return $tokens;
+ return $ids;
}
/**
- * Returns first (default) token saved.
+ * Returns first (default) ID saved.
*
* @return string|null
* @author Justin Foell
* @since 1.2.0
*/
- public function get_default_token() {
- $tokens = $this->get_tokens();
- return isset( $tokens[0] ) ? $tokens[0] : null;
+ public function get_default_id() {
+ $ids = $this->get_ids();
+ return isset( $ids[0] ) ? $ids[0] : null;
}
/**
- * Get all tokens and their nicknames in one array.
+ * Get all IDs and their nicknames in one array.
*
* @return void
* @author Justin Foell
- * @since 1.2.0
+ * @since 2.0.0
*/
- public function get_all_tokens() {
- $tokens = $this->get_tokens();
+ public function get_all_ids() {
+ $ids = $this->get_ids();
$nicknames = $this->nickname;
$all = array();
$number = 1;
- foreach ( $tokens as $index => $token ) {
+ foreach ( $ids as $index => $id ) {
if ( ! empty( $nicknames[ $index ] ) ) {
- $all[ $token ] = $nicknames[ $index ];
+ $all[ $id ] = $nicknames[ $index ];
} else {
- $all[ $token ] = $this->get_default_nickname( $number );
+ $all[ $id ] = $this->get_default_nickname( $number );
}
$number++;
}
@@ -637,22 +534,22 @@ class WPStrava_Settings {
}
/**
- * Checks for valid tokens.
+ * Checks for valid IDs.
*
* @author Justin Foell
* @since 1.2.0
*
- * @param string|array Single token or array of tokens.
+ * @param string|array Single ID or array of IDs.
* @return boolean True if empty.
*/
- public function tokens_empty( $tokens ) {
- if ( empty( $tokens ) ) {
+ public function ids_empty( $ids ) {
+ if ( empty( $ids ) ) {
return true;
}
- if ( is_array( $tokens ) ) {
- foreach ( $tokens as $token ) {
- if ( ! empty( $token ) ) {
+ if ( is_array( $ids ) ) {
+ foreach ( $ids as $id ) {
+ if ( ! empty( $id ) ) {
return false;
}
}
@@ -662,19 +559,120 @@ class WPStrava_Settings {
}
/**
- * Only add a token if it's not already there.
+ * Add an ID if it's not already there, and save to the DB.
*
- * @param string $token
+ * @param string $id
*
* @author Justin Foell
- * @since 1.2.0
+ * @since 2.0.0
*/
- public function add_token( $token ) {
- if ( false === array_search( $token, $this->tokens, true ) ) {
- $this->tokens[] = $token;
+ public function add_id( $id ) {
+ if ( false === array_search( $id, $this->ids, true ) ) {
+ $this->ids[] = $id;
+ update_option( 'strava_id', $this->ids );
}
}
+ /**
+ * Undocumented function
+ *
+ * @param int $id Strava API Client ID
+ * @param string $secret Strava API Client Secret
+ * @param stdClass $info
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function save_info( $id, $secret, $info ) {
+ $infos = get_option( 'strava_info', array() );
+ $infos = array_filter( $infos, array( $this, 'filter_by_id' ), ARRAY_FILTER_USE_KEY ); // Remove old IDs.
+ $info->client_secret = $secret;
+ $infos[ $id ] = $info;
+ update_option( 'strava_info', $infos );
+ }
+
+ /**
+ * array_filter() callback to remove info for IDs we no longer have.
+ *
+ * @param int $key Strava Client ID
+ * @return boolean True if Client ID is in $this->ids, false otherwise.
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function filter_by_id( $key ) {
+ if ( in_array( $key, $this->ids ) ) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @return void
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function delete_id_secret() {
+ delete_option( 'strava_client_id' );
+ delete_option( 'strava_client_secret' );
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @param [type] $value
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function is_settings_updated( $value ) {
+ return isset( $value[0]['type'] ) && 'updated' === $value[0]['type'];
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function is_option_page() {
+ return isset( $_POST['option_page'] ) && $_POST['option_page'] === $this->option_page;
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function is_settings_page() {
+ return isset( $_GET['page'] ) && $_GET['page'] === $this->page_name;
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @return string
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ public function get_page_name() {
+ return $this->page_name;
+ }
+
+ /**
+ * Undocumented function
+ *
+ * @return boolean
+ * @author Justin Foell
+ * @since 2.0.0
+ */
+ private function is_adding_athlete() {
+ return ! ( empty( $_POST['strava_client_id'] ) && empty( $_POST['strava_client_secret'] ) );
+ }
+
/**
* Getter for Strava settings in wp_options.
*
diff --git a/lib/WPStrava/StaticMap.php b/includes/WPStrava/StaticMap.php
similarity index 97%
rename from lib/WPStrava/StaticMap.php
rename to includes/WPStrava/StaticMap.php
index d84e5b8..762e9f3 100644
--- a/lib/WPStrava/StaticMap.php
+++ b/includes/WPStrava/StaticMap.php
@@ -66,7 +66,7 @@ class WPStrava_StaticMap {
* }
*/
private static function decode_start_finish( $enc ) {
- require_once WPSTRAVA_PLUGIN_DIR . 'lib/Polyline.php';
+ require_once WPSTRAVA_PLUGIN_DIR . 'includes/Polyline.php';
$points = Polyline::decode( $enc );
$points = Polyline::pair( $points );
$start = $points[0];
diff --git a/lib/autoload.php b/includes/autoload.php
similarity index 87%
rename from lib/autoload.php
rename to includes/autoload.php
index c1a9a6c..863d5df 100644
--- a/lib/autoload.php
+++ b/includes/autoload.php
@@ -16,7 +16,7 @@ function wpstrava_autoload_classes( $class_name ) {
}
// @TODO Add directory searching if they get created.
- $file = WPSTRAVA_PLUGIN_DIR . '/lib/' . implode( '/', $parts ) . '.php';
+ $file = WPSTRAVA_PLUGIN_DIR . '/includes/' . implode( '/', $parts ) . '.php';
if ( file_exists( $file ) ) {
include_once $file;
}
diff --git a/includes/template-tags.php b/includes/template-tags.php
new file mode 100644
index 0000000..a4abe2d
--- /dev/null
+++ b/includes/template-tags.php
@@ -0,0 +1,2 @@
+
- ./lib
+ ./includes./wp-strava.php*/vendor/*
diff --git a/phpunit.xml b/phpunit.xml
index 45eedc3..5cb52bb 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -16,7 +16,7 @@
- lib
+ includes
diff --git a/readme.txt b/readme.txt
index 2259e15..ee0512e 100755
--- a/readme.txt
+++ b/readme.txt
@@ -4,13 +4,12 @@ Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb
Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin
Requires at least: 4.6
Tested up to: 5.1
-Stable tag: 1.7.3
+Stable tag: 2.0
Requires PHP: 5.2
License: GPLv2 or later
Show your Strava activity on your WordPress site.
-
== Description ==
This plugin uses the Strava API to embed maps and activity for athletes and clubs on your WordPress site. Included are several widgets and shortcodes for showing maps and activity summaries.
@@ -32,7 +31,7 @@ Also takes the following optional parameters:
* som - english/metric (system of measure - override from default setting).
* map_width - width (width of image in pixels). Note both width and height parameters are limited to 640px except on premium API plans: https://developers.google.com/maps/documentation/maps-static/dev-guide#Imagesizes
* map_height - height (height of image in pixels). See note above on max height.
-* athlete_token - specify a different athlete (you can copy this value from https://www.strava.com/settings/api or the wp-strava settings page at /wp-admin/options-general.php?page=wp-strava-options).
+* client_id - specify a different athlete (you can copy this value from https://www.strava.com/settings/api or the wp-strava settings page at /wp-admin/options-general.php?page=wp-strava-options).
* markers - Display markers at the start/finish point (true/false, defaults to false).
* image_only - Display only the map image and not the table (true/false, defaults to false).
@@ -48,7 +47,7 @@ This also takes the same optional parameters as the [activity] shortcode above.
* som - english/metric (system of measure - override from default setting).
* quantity - number of activities to show.
-* athlete_token - specify a different athlete (you can copy this value from https://www.strava.com/settings/api or the wp-strava settings page at /wp-admin/options-general.php?page=wp-strava-options).
+* client_id - specify a different athlete (you can copy this value from https://www.strava.com/settings/api or the wp-strava settings page at /wp-admin/options-general.php?page=wp-strava-options).
* strava_club_id - Will display activity from the specified Strava club ID instead of an athlete.
@@ -58,20 +57,24 @@ Strava Latest Activity List - shows a list of the last few activities.
Strava Latest Map - shows map of latest activity with option to limit latest map to activities of a certain minimum distance.
+
== Frequently Asked Questions ==
= Why am I getting "ERROR 401 Unauthorized"? =
-When you have multiple athletes saved, the first is considered to be the default athlete. If you use a shortcode to display activity from anyone other than the default athlete, you must add the athlete token (found on the wp-strava settings page) to the shortcode, such as athlete_token=c764a2b199cff281e39f24671760c1b9c9fe005e. If you've recently had to re-authorize with Strava, your athlete token may have changed and will need to be updated in your shortcodes and widgets. For widgets, re-select the athlete you'd like to display and click Save.
+When you have multiple athletes saved, the first is considered to be the default athlete. If you use a shortcode to display activity from anyone other than the default athlete, you must add the athlete token (found on the wp-strava settings page) to the shortcode, such as client_id=17791. If you've recently had to re-authorize with Strava, your athlete token may have changed and will need to be updated in your shortcodes and widgets. For widgets, re-select the athlete you'd like to display and click Save.
+
= Why is my Google Map not showing up? =
If your API key works with other Google Maps plugins but not WP Strava, you may need to enable the "Static Maps" functionality on your google account. This is especially true for people using G Suite accounts (not just a @gmail.com address). While logged into your G Suite email, visit https://console.developers.google.com/apis/library/static-maps-backend.googleapis.com/?q=static and make sure the "Static Maps API" is enabled. For more details see https://wordpress.org/support/topic/no-data-errors/
+
= I recently uploaded an activity, why is it not showing on my site? =
WP-Strava caches activity for one hour so your site doesn't hit the Strava API on every page load. If you recently uploaded activity and want to see it right away, go to the Settings -> Strava in the wp-admin dashboard, check the checkbox labeled "Clear cache (images & transient data)" and then click Save Changes.
+
== Screenshots ==
1. WP Strava settings - this walks you through connecting the WP Strava plugin to your strava account. You can connect multiple accounts by authenticating each one here. Add your Google Maps key for map display here. You can also set the system of measurement (miles/kilometers) and clear any saved data.
@@ -80,18 +83,25 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o
4. Latest Map Widget - shows a map of your most recent activity.
5. Latest Map Widget Settings - settings for the Latest Map Widget. You can limit your activity by minimum distance to show only longer efforts.
6. Activity Shortcode - Shows a map of activity with some statistics.
-7. Activity Shortcode Settings - An example activity shortcode. The athlete_token parameter is only needed if your site is connected to multiple athlete accounts.
+7. Activity Shortcode Settings - An example activity shortcode. The client_id parameter is only needed if your site is connected to multiple athlete accounts.
8. Route Shortcode - Shows a map of a route.
9. Route Shortcode Settings - An example route shortcode. Add markers=true to show green/red start/stop points.
10. Activities Shortcode - Shows latest athlete activity in a page or post.
-11. Activities Shortcode Settings - An example activities shortcode. The athlete_token parameter is only needed if your site is connected to multiple athlete accounts.
+11. Activities Shortcode Settings - An example activities shortcode. The client_id parameter is only needed if your site is connected to multiple athlete accounts.
+
== Changelog ==
+= 2.0.0 =
+
+Added new Strava "refresh tokens" ala https://developers.strava.com/docs/oauth-updates/#migration-instructions
+
+
= 1.7.3 =
Added update notice.
+
= 1.7.2 =
Added setting to hide elevation.
@@ -106,6 +116,7 @@ Fixed swimpace calculation.
Fixed seconds display on pace.
Added Hide Activity Time option to hide time display from Latest Activities List.
+
= 1.7.0 =
Added Sebastian Erb to contributors.
@@ -235,6 +246,11 @@ Initial version.
== Upgrade Notice ==
+= 2.0 =
+
+Version 2.0 is mandatory after October 15th, 2019. 2.0 settings upgrade instructions: https://github.com/cmanon/wp-strava/wiki/2.0-Upgrade.
+
+
= 1.7.3 =
-Version 2.0 will be mandatory after October 15th, 2019. Try the 2.0 beta: https://github.com/cmanon/wp-strava/releases. 2.0 settings upgrade instructions: https://github.com/cmanon/wp-strava/wiki/2.0-Upgrade.
+Version 2.0 is mandatory after October 15th, 2019. Try the 2.0 beta: https://github.com/cmanon/wp-strava/releases. 2.0 settings upgrade instructions: https://github.com/cmanon/wp-strava/wiki/2.0-Upgrade.
diff --git a/templates/admin-settings.php b/templates/admin-settings.php
new file mode 100644
index 0000000..762de55
--- /dev/null
+++ b/templates/admin-settings.php
@@ -0,0 +1,13 @@
+