diff --git a/readme.txt b/readme.txt
index 8d389ca..6d896b3 100755
--- a/readme.txt
+++ b/readme.txt
@@ -118,10 +118,15 @@ On the WP-Strava settings page you cannot currently remove and add another athle
== Changelog ==
+= 2.7.0 =
+Add setting to choose API cache interval (1 hour / 15 minutes) https://wordpress.org/support/topic/decrease-update-time-for-group-recent-activities/
+
+
= 2.6.0 =
Make reusable components for embed screens and SOMOverride
Add Route Block
+
= 2.5.1 =
Fix latest_map class replacing echo with return https://wordpress.org/support/topic/latest-activity-map-shortcode-wrong-placed-on-page/
@@ -130,6 +135,7 @@ Fix broken water pace on activity.
Fix pace types and remove 'other' - making 'speed' default.
Fix to remove map link in editor so you don't leave the editor.
+
= 2.5.0 =
Fix missing translation domain on "Save Changes" in settings. https://wordpress.org/support/topic/small-fix-in-settings-php-function-print_clear_input
@@ -340,6 +346,7 @@ Initial version.
Adds API caching - speed up your page loads 8^)
+
= 2.0.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.
diff --git a/src/WPStrava/API.php b/src/WPStrava/API.php
index 4821f6e..52ec826 100755
--- a/src/WPStrava/API.php
+++ b/src/WPStrava/API.php
@@ -95,7 +95,11 @@ class WPStrava_API {
$data = $this->remote_get( $uri, $args );
- set_transient( $transient_key, $data, HOUR_IN_SECONDS );
+ // Default to 1 hour of transient cache unless set otherwise.
+ $settings = WPStrava::get_instance()->settings;
+ $cache_time = $settings->cache_time ? absint( $settings->cache_time ) : HOUR_IN_SECONDS;
+
+ set_transient( $transient_key, $data, $cache_time );
return $data;
}
diff --git a/src/WPStrava/Settings.php b/src/WPStrava/Settings.php
index 8ab8794..174d053 100644
--- a/src/WPStrava/Settings.php
+++ b/src/WPStrava/Settings.php
@@ -99,9 +99,13 @@ class WPStrava_Settings {
register_setting( $this->option_page, 'strava_no_link', array( $this, 'sanitize_no_link' ) );
add_settings_field( 'strava_no_link', __( 'Links', 'wp-strava' ), array( $this, 'print_no_link_input' ), 'wp-strava', 'strava_options' );
+ // Cache lifetime.
+ register_setting( $this->option_page, 'strava_cache_time', array( $this, 'sanitize_cache_time' ) );
+ add_settings_section( 'strava_cache', __( 'Cache', 'wp-strava' ), null, 'wp-strava' );
+ add_settings_field( 'strava_cache_time', __( 'Cache time', 'wp-strava' ), array( $this, 'print_cache_input' ), 'wp-strava', 'strava_cache' );
+
// 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', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' );
}
@@ -530,6 +534,35 @@ class WPStrava_Settings {
return null;
}
+ /**
+ * Print dropdown to select cache lifetime.
+ *
+ * @author Justin Foell
+ * @since 2.7.0
+ */
+ public function print_cache_input() {
+ $fifteen_min = 15 * MINUTE_IN_SECONDS;
+ ?>
+
+
+
+ * @since 2.7.0
+ */
+ public function sanitize_cache_time( $cache_time ) {
+ return absint( $cache_time );
+ }
+
/**
* Gets all saved strava ids as an array.
*
@@ -598,7 +631,7 @@ class WPStrava_Settings {
* @author Justin Foell
* @since 1.2.0
*
- * @param integer $number Athlete number (default 1).
+ * @param int $number Athlete number (default 1).
* @return string
*/
private function get_default_nickname( $number = 1 ) {