From fca88020a5c47f8953d909090e56e8a9b65169ac Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Mon, 11 May 2015 22:28:33 -0500 Subject: [PATCH 1/8] Updated version to 1.1 Added Lance Willet Tested WP 4.2 Check for WP error on Strava POST Fix static method in RideShortcode Add Title to Latest Map Widget --- lib/API.class.php | 3 +++ lib/LatestMapWidget.class.php | 12 ++++++++++-- lib/LatestRidesWidget.class.php | 9 ++------- lib/RideShortcode.class.php | 15 ++++++++------- readme.txt | 16 +++++++++++----- wp-strava.php | 16 ++++++++-------- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/lib/API.class.php b/lib/API.class.php index 44dd657..5d87f9f 100755 --- a/lib/API.class.php +++ b/lib/API.class.php @@ -26,6 +26,9 @@ class WPStrava_API { $response = wp_remote_post( $url . $uri, $args ); + if ( is_wp_error( $response ) ) + return $response; + if ( $response['response']['code'] != 200 ) { //see if there's useful info in the body $body = json_decode( $response['body'] ); diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index ec40b16..0115c12 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -16,6 +16,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { public function form( $instance ) { // outputs the options form on admin + $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity', 'wp-strava' ); $distance_min = isset( $instance['distance_min'] ) ? esc_attr( $instance['distance_min'] ) : ''; $strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : ''; @@ -23,6 +24,10 @@ class WPStrava_LatestMapWidget extends WP_Widget { //$ride_index_params = $ride_index_params ? $ride_index_params : 'athleteId=21'; ?> +

+ + +

@@ -37,6 +42,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { public function update( $new_instance, $old_instance ) { // processes widget options to be saved from the admin $instance = $old_instance; + $instance['title'] = strip_tags( $new_instance['title'] ); $instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] ); $instance['distance_min'] = strip_tags( $new_instance['distance_min'] ); return $instance; @@ -44,6 +50,8 @@ class WPStrava_LatestMapWidget extends WP_Widget { public function widget( $args, $instance ) { extract( $args ); + + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity', 'wp-strava' ) : $instance['title'] ); $distance_min = $instance['distance_min']; $strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id']; $build_new = false; @@ -92,8 +100,8 @@ class WPStrava_LatestMapWidget extends WP_Widget { if ( $ride ): echo $before_widget; - ?>

Latest Ride

- getStaticImage( $ride->id, $build_new ); ?> - strava_request_handler( $strava_club_id, $strava_som_option, $quantity ); ?> + strava_request_handler( $strava_club_id, $quantity ); ?> rides; diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php index 8113310..5353519 100644 --- a/lib/RideShortcode.class.php +++ b/lib/RideShortcode.class.php @@ -1,16 +1,17 @@ @@ -70,7 +71,7 @@ class WPStrava_RideShortcode { } } // handler - static function printScripts() { + public static function printScripts() { if (self::$add_script) { wp_enqueue_style('wp-strava-style'); diff --git a/readme.txt b/readme.txt index d42fe9e..2e49fbb 100755 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Plugin Name === -Contributors: cmanon, jrfoell +Contributors: cmanon, jrfoell, lancewillett Donate link: http://cmanon.com/ Tags: strava, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin -Requires at least: 3.0 -Tested up to: 4.0 -Stable tag: 1.0 +Requires at least: 4.0 +Tested up to: 4.2 +Stable tag: 1.1 License: GPLv2 or later Show your Strava activity on your WordPress site. @@ -17,7 +17,7 @@ widgets and shortcodes for showing maps and activity summaries. = Shortcodes = -[ride id=NUMBER] - add to any page or post. Also takes the following +[activity id=NUMBER] - add to any page or post. Also takes the following optional parameters: * som - english/metric (system of measure - override from default setting) @@ -33,6 +33,12 @@ latest map to activities of a certain minimum distance == Changelog == += 1.1 = +Added [activity] short code to deprecate [ride] in the future +Fixed static method call error in shortcode +Added title to Strava Latest Map Widget +Added Lance Willet to contributors + = 1.0 = Change to Strava API V3 Switch ride shortcode to use static map diff --git a/wp-strava.php b/wp-strava.php index 372f8cb..d52d441 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -1,13 +1,13 @@ -Author URI: http://cmanon.com -License: GPL2 -*/ + * Plugin Name: WP Strava + * Plugin URI: http://cmanon.com + * Description: Plugin to show your strava.com information in your wordpress blog. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. + * Version: 1.1 + * Author: Carlos Santa Cruz, Justin Foell, Lance Willet + * License: GPL2 + */ + /* Copyright 2011 Carlos Santa Cruz (email : cmanon at gmail dot com) This program is free software; you can redistribute it and/or modify From d4984588fb249965307f5f764af156c523b9e68a Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 10:43:31 -0500 Subject: [PATCH 2/8] Fixed spelling in readme.txt --- readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 2e49fbb..cfb4ab5 100755 --- a/readme.txt +++ b/readme.txt @@ -34,10 +34,10 @@ latest map to activities of a certain minimum distance == Changelog == = 1.1 = -Added [activity] short code to deprecate [ride] in the future +Added [activity] shortcode to deprecate [ride] in the future Fixed static method call error in shortcode Added title to Strava Latest Map Widget -Added Lance Willet to contributors +Added Lance Willett to contributors = 1.0 = Change to Strava API V3 From ded3929a445f409cfb58b6cb4dcee4ccf2344246 Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 12:17:25 -0500 Subject: [PATCH 3/8] Revise setup instructions Fix some formatting --- lib/Settings.class.php | 45 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/Settings.class.php b/lib/Settings.class.php index f1d7a42..7a4fb34 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -2,7 +2,7 @@ /** * 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 * Get redirected back to this settings page with ?code= or ?error= @@ -15,7 +15,7 @@ class WPStrava_Settings { private $token; private $page_name = 'wp-strava-options'; private $option_page = 'wp-strava-settings-group'; - + //register admin menus public function hook() { add_action( 'admin_init', array( $this, 'register_strava_settings' ) ); @@ -41,7 +41,7 @@ class WPStrava_Settings { //user is clearing to start-over, don't oauth if ( isset( $_POST['strava_token'] ) && empty( $_POST['strava_token'] ) ) return; - + $client_id = get_option( 'strava_client_id' ); $client_secret = get_option( 'strava_client_secret' ); @@ -55,7 +55,7 @@ class WPStrava_Settings { } return $value; } - + public function add_strava_menu() { add_options_page( __( 'Strava Settings', 'wp-strava' ), __( 'Strava', 'wp-strava' ), @@ -79,13 +79,13 @@ class WPStrava_Settings { add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'Error authenticating at Strava: %s', 'wp-strava' ), str_replace( '_', ' ', $_GET['error'] ) ) ); } } - - $this->token = get_option( 'strava_token' ); + + $this->token = get_option( 'strava_token' ); } - + public function register_strava_settings() { $this->init(); - + add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); //NULL / NULL no section label needed if ( ! $this->token ) { @@ -98,7 +98,7 @@ class WPStrava_Settings { register_setting( $this->option_page, 'strava_token', array( $this, 'sanitize_token' ) ); add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' ); } - + register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) ); add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), NULL, 'wp-strava' ); @@ -110,29 +110,28 @@ class WPStrava_Settings { $signup_url = 'http://www.strava.com/developers'; $settings_url = 'https://www.strava.com/settings/api'; $blog_name = get_bloginfo( 'name' ); - $app_name = $blog_name . ' Strava'; - $url_parts = parse_url( site_url() ); - $site_url = $url_parts['host']; //strip http/https for copying/pasting into strava + $app_name = sprintf( esc_html( '%s Strava', 'wp-strava' ), $blog_name ); + $site_url = site_url(); $description = 'WP-Strava for ' . $blog_name; printf( __( "

Steps:

    -
  1. Create your API Application here: %s using the following information:
  2. +
  3. Create your API Application/Connection here: %s using the following information:
    • Application Name: %s
    • Website: %s
    • Application Description: %s
    • Authorization Callback Domain: %s
    -
  4. Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can be found at %s
  5. +
  6. 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.
  7. 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.
  8. If you need to re-authorize your API Application, erase your Strava Token here and click 'Save Changes' to start over.
  9. -
", 'wp-strava' ), $signup_url, $signup_url, $app_name, $site_url, $description, $site_url, $settings_url, $settings_url ); + ", 'wp-strava' ), $settings_url, $settings_url, $app_name, $site_url, $description, $site_url ); } - + public function print_strava_options() { ?>
-

+

@@ -200,9 +199,9 @@ class WPStrava_Settings { } else { $this->feedback .= __( 'Missing Client ID or Client Secret.', 'wp-strava' ); return false; - } + } } - + public function print_som_input() { $strava_som = get_option( 'strava_som' ); ?> @@ -220,10 +219,10 @@ class WPStrava_Settings { public function __get( $name ) { return get_option( "strava_{$name}" ); } - - public function settings_link( $links ) { - $settings_link = 'page_name}" ) . '">' . __( 'Settings' ) . ''; - $links[] = $settings_link; + + public function settings_link( $links ) { + $settings_link = 'page_name}" ) . '">' . __( 'Settings' ) . ''; + $links[] = $settings_link; return $links; } From d9399b14af0bddbdc08b2c377a5a29ea7276d513 Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 13:50:39 -0500 Subject: [PATCH 4/8] Added Google Maps Static Key setting --- lib/Settings.class.php | 58 +++++++++++++++++++++++++++++------------ lib/StaticMap.class.php | 33 ++++++++++++++++++----- 2 files changed, 68 insertions(+), 23 deletions(-) diff --git a/lib/Settings.class.php b/lib/Settings.class.php index 7a4fb34..c1811f4 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -35,21 +35,25 @@ class WPStrava_Settings { * This runs after options are saved */ public function maybe_oauth( $value ) { - //redirect only if all the right options are in place - if ( isset( $value[0]['type'] ) && $value[0]['type'] == 'updated' ) { //make sure there were no settings errors - if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) { //make sure we're on our settings page - //user is clearing to start-over, don't oauth + // Redirect only if all the right options are in place. + if ( isset( $value[0]['type'] ) && $value[0]['type'] == 'updated' ) { // Make sure there were no settings errors. + if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) { // Make sure we're on our settings page. + + // User is clearing to start-over, don't oauth. if ( isset( $_POST['strava_token'] ) && empty( $_POST['strava_token'] ) ) return; - $client_id = get_option( 'strava_client_id' ); - $client_secret = get_option( 'strava_client_secret' ); + // Only re-auth if client ID and secret were shown. + if ( ! empty( $_POST['strava_client_id'] ) && ! empty( $_POST['strava_client_secret'] ) ) { + $client_id = get_option( 'strava_client_id' ); + $client_secret = get_option( 'strava_client_secret' ); - if ( $client_id && $client_secret ) { - $redirect = admin_url( "options-general.php?page={$this->page_name}" ); - $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force"; - wp_redirect( $url ); - exit(); + if ( $client_id && $client_secret ) { + $redirect = admin_url( "options-general.php?page={$this->page_name}" ); + $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force"; + wp_redirect( $url ); + exit(); + } } } } @@ -86,7 +90,7 @@ class WPStrava_Settings { public function register_strava_settings() { $this->init(); - add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); //NULL / NULL no section label needed + add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); if ( ! $this->token ) { register_setting( $this->option_page, 'strava_client_id', array( $this, 'sanitize_client_id' ) ); @@ -99,10 +103,14 @@ class WPStrava_Settings { add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' ); } - register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) ); - - add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), NULL, 'wp-strava' ); + // Google Maps API. + register_setting( $this->option_page, 'strava_gmaps_key', array( $this, 'sanitize_gmaps_key' ) ); + add_settings_section( 'strava_gmaps', __( 'Google Maps', 'wp-strava' ), array( $this, 'print_gmaps_instructions' ), 'wp-strava' ); + add_settings_field( 'strava_gmaps_key', __( 'Static Maps Key', 'wp-strava' ), array( $this, 'print_gmaps_key_input' ), 'wp-strava', 'strava_gmaps' ); + // System of Measurement. + register_setting( $this->option_page, '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' ); } @@ -115,7 +123,7 @@ class WPStrava_Settings { $description = 'WP-Strava for ' . $blog_name; printf( __( "

Steps:

    -
  1. Create your API Application/Connection here: %s using the following information:
  2. +
  3. Create your free API Application/Connection here: %s using the following information:
    • Application Name: %s
    • Website: %s
    • @@ -128,6 +136,16 @@ class WPStrava_Settings {
", 'wp-strava' ), $settings_url, $settings_url, $app_name, $site_url, $description, $site_url ); } + public function print_gmaps_instructions() { + $maps_url = 'https://developers.google.com/maps/documentation/static-maps/'; + printf( __( "

Steps:

+
    +
  1. To use Google map images, you must create a Static Maps API Key. Create a free key by going here: %s and clicking Get a Key
  2. +
  3. Once you've created your Google Static Maps API Key, enter the key below. +
", 'wp-strava' ), $maps_url, $maps_url ); + + } + public function print_strava_options() { ?>
@@ -202,6 +220,14 @@ class WPStrava_Settings { } } + public function print_gmaps_key_input() { + ?> diff --git a/lib/StaticMap.class.php b/lib/StaticMap.class.php index 8a3be0b..bb214c9 100644 --- a/lib/StaticMap.class.php +++ b/lib/StaticMap.class.php @@ -1,18 +1,37 @@ settings->gmaps_key; + + // Short circuit if missing key or ride object doesn't have the data we need. + if ( empty( $key ) || empty( $ride->map ) ) { + return ''; + } + + $url = "https://maps.googleapis.com/maps/api/staticmap?maptype=terrain&size={$width}x{$height}&sensor=false&key={$key}&path=color:0xFF0000BF|weight:2|enc:"; $url_len = strlen( $url ); $max_chars = 1865; - if ( $url_len + strlen( $ride->map->polyline ) < $max_chars ) + if ( ! empty( $ride->map->polyline ) && ( $url_len + strlen( $ride->map->polyline ) < $max_chars ) ) { $url .= $ride->map->polyline; - else + } else { $url .= $ride->map->summary_polyline; - - return ""; + } + + return ""; } -} \ No newline at end of file +} From f165d9a4d52ba367b4d218086723dc5965610b00 Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 13:52:49 -0500 Subject: [PATCH 5/8] Formatting, added target="_blank" to widget hrefs --- lib/LatestMapWidget.class.php | 35 ++++++++++++++++----------------- lib/LatestRidesWidget.class.php | 2 +- lib/SOM.class.php | 6 +++--- lib/Strava.class.php | 27 ++++++++++++++----------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index 0115c12..63e4cf3 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -3,17 +3,17 @@ class WPStrava_LatestMapWidget extends WP_Widget { private $som; - + public function __construct() { $this->som = WPStrava_SOM::get_som(); - + parent::__construct( false, 'Strava Latest Map', // Name array( 'description' => __( 'Strava latest ride using static google map image', 'wp-strava' ), ) // Args ); } - + public function form( $instance ) { // outputs the options form on admin $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity', 'wp-strava' ); @@ -21,7 +21,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { $strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : ''; //provide some defaults - //$ride_index_params = $ride_index_params ? $ride_index_params : 'athleteId=21'; + //$ride_index_params = $ride_index_params ?: 'athleteId=21'; ?>

@@ -36,9 +36,9 @@ class WPStrava_LatestMapWidget extends WP_Widget {

- rides; @@ -81,7 +80,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { } if ( ! empty( $rides ) ) { - + if ( ! empty( $distance_min ) ) $rides = $strava_rides->getRidesLongerThan( $rides, $distance_min ); @@ -93,25 +92,26 @@ class WPStrava_LatestMapWidget extends WP_Widget { update_option( 'strava_latest_map_ride', $ride ); } - if ( $ride->id != $ride_transient->id ) - set_transient( 'strava_latest_map_ride', $ride, 60 * 60 ); //one hour + if ( $ride->id != $ride_transient->id ) { + set_transient( 'strava_latest_map_ride', $ride, HOUR_IN_SECONDS ); + } } } - if ( $ride ): + if ( $ride ) { echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; - ?>getStaticImage( $ride->id, $build_new ); ?>rides->getRide( $ride_id ); $img = WPStrava_StaticMap::get_image_tag( $ride ); @@ -120,5 +120,4 @@ class WPStrava_LatestMapWidget extends WP_Widget { return $img; } - } \ No newline at end of file diff --git a/lib/LatestRidesWidget.class.php b/lib/LatestRidesWidget.class.php index d82e6f6..c112169 100644 --- a/lib/LatestRidesWidget.class.php +++ b/lib/LatestRidesWidget.class.php @@ -80,7 +80,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget { $response = "
    "; foreach( $rides as $ride ) { $response .= "
  • "; - $response .= "" . $ride->name . ""; + $response .= "" . $ride->name . ""; $response .= "
    "; $unixtime = strtotime( $ride->start_date_local ); $response .= sprintf( __("On %s %s", "wp-strava"), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) ); diff --git a/lib/SOM.class.php b/lib/SOM.class.php index 4bd8ee0..1453a24 100644 --- a/lib/SOM.class.php +++ b/lib/SOM.class.php @@ -11,9 +11,9 @@ abstract class WPStrava_SOM { require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php'; return new WPStrava_SOMMetric(); } - + } - + abstract public function distance( $m ); abstract public function distance_inverse( $dist ); abstract public function get_distance_label(); @@ -29,4 +29,4 @@ abstract class WPStrava_SOM { public function get_time_label() { return __( 'hours', 'wp-strava' ); } -} \ No newline at end of file +} diff --git a/lib/Strava.class.php b/lib/Strava.class.php index 0cb1b2d..e907c52 100644 --- a/lib/Strava.class.php +++ b/lib/Strava.class.php @@ -9,11 +9,11 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php'; class WPStrava { - private static $instance = NULL; - private $settings = NULL; - private $api = NULL; - private $rides = NULL; - + private static $instance = null; + private $settings = null; + private $api = null; + private $rides = null; + private function __construct() { $this->settings = new WPStrava_Settings(); @@ -24,8 +24,8 @@ class WPStrava { } // Register StravaLatestRidesWidget widget - add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestRidesWidget" );') ); - add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestMapWidget" );' ) ); + add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestRidesWidget" );' ) ); + add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestMapWidget" );' ) ); } public static function get_instance() { @@ -38,16 +38,19 @@ class WPStrava { public function __get( $name ) { //on-demand classes - if ( $name == 'api' ) + if ( $name == 'api' ) { return $this->get_api(); + } - if ( $name == 'rides' ) + if ( $name == 'rides' ) { return $this->get_rides(); + } - if ( isset( $this->{$name} ) ) + if ( isset( $this->{$name} ) ) { return $this->{$name}; + } - return NULL; + return null; } public function get_api() { @@ -58,7 +61,7 @@ class WPStrava { return $this->api; } - + public function get_rides() { if ( ! $this->rides ) { require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php'; From 5cd0a60649b723b35034ff82f1acee6bc4bbb51b Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 13:58:46 -0500 Subject: [PATCH 6/8] Updated readme.txt --- readme.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index cfb4ab5..1835676 100755 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,8 @@ === Plugin Name === Contributors: cmanon, jrfoell, lancewillett -Donate link: http://cmanon.com/ Tags: strava, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin Requires at least: 4.0 -Tested up to: 4.2 +Tested up to: 4.7 Stable tag: 1.1 License: GPLv2 or later @@ -38,6 +37,9 @@ Added [activity] shortcode to deprecate [ride] in the future Fixed static method call error in shortcode Added title to Strava Latest Map Widget Added Lance Willett to contributors +Added target="_blank" to widget hrefs +Added Google Maps Key to settings (required for map images) +Cleaned up formatting = 1.0 = Change to Strava API V3 From 37816d12b8a4069732f9ac30dbc6fe2d0eef8bed Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 14:23:11 -0500 Subject: [PATCH 7/8] Avoid errors on first run --- lib/LatestMapWidget.class.php | 6 +++--- wp-strava.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index 63e4cf3..3534807 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -56,7 +56,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { $strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id']; $build_new = false; - //try our transient first + // Try our transient first. $ride_transient = get_transient( 'strava_latest_map_ride' ); $ride_option = get_option( 'strava_latest_map_ride' ); @@ -87,12 +87,12 @@ class WPStrava_LatestMapWidget extends WP_Widget { $ride = current( $rides ); //update transients & options - if ( $ride->id != $ride_option->id ) { + if ( empty( $ride_option->id ) || $ride->id != $ride_option->id ) { $build_new = true; update_option( 'strava_latest_map_ride', $ride ); } - if ( $ride->id != $ride_transient->id ) { + if ( empty( $ride_transient->id ) || $ride->id != $ride_transient->id ) { set_transient( 'strava_latest_map_ride', $ride, HOUR_IN_SECONDS ); } } diff --git a/wp-strava.php b/wp-strava.php index d52d441..7128fb7 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -28,7 +28,7 @@ define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); define( 'WPSTRAVA_PLUGIN_NAME', plugin_basename(__FILE__) ); -define( 'WPSTRAVA_DEBUG', false ); +if ( ! defined( 'WPSTRAVA_DEBUG' ) ) define( 'WPSTRAVA_DEBUG', false ); // Load the multilingual support. if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) { From 3bb9faace60196162ab19bd230ac5872fe992bca Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Wed, 10 May 2017 14:39:00 -0500 Subject: [PATCH 8/8] Added option to clear cache --- lib/Settings.class.php | 21 ++++++++++++++++++++- lib/Strava.class.php | 4 ++-- readme.txt | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Settings.class.php b/lib/Settings.class.php index c1811f4..2936ec8 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -20,7 +20,7 @@ class WPStrava_Settings { public function hook() { add_action( 'admin_init', array( $this, 'register_strava_settings' ) ); add_action( 'admin_menu', array( $this, 'add_strava_menu' ) ); - add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ), 10 ); + add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ) ); add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) ); //for process debugging //add_action( 'all', array( $this, 'hook_debug' ) ); @@ -112,6 +112,11 @@ class WPStrava_Settings { register_setting( $this->option_page, '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' ); + + // Clear cache. + register_setting( $this->option_page, 'strava_cache_clear', array( $this, 'sanitize_cache_clear' ) ); + add_settings_section( 'strava_cache', __( 'Cache', 'wp-strava' ), null, 'wp-strava' ); + add_settings_field( 'strava_cache_clear', __( 'Clear cache (images & transient data)', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' ); } public function print_api_instructions() { @@ -242,6 +247,20 @@ class WPStrava_Settings { return $som; } + public function print_clear_input() { + ?>get_api(); } @@ -56,7 +56,7 @@ class WPStrava { public function get_api() { if ( ! $this->api ) { require_once WPSTRAVA_PLUGIN_DIR . 'lib/API.class.php'; - $this->api = new WPStrava_API( get_option('strava_token') ); + $this->api = new WPStrava_API( get_option( 'strava_token' ) ); } return $this->api; diff --git a/readme.txt b/readme.txt index 1835676..8fcfe79 100755 --- a/readme.txt +++ b/readme.txt @@ -39,6 +39,7 @@ Added title to Strava Latest Map Widget Added Lance Willett to contributors Added target="_blank" to widget hrefs Added Google Maps Key to settings (required for map images) +Added cache clear option to remove transient & image data Cleaned up formatting = 1.0 =