Added option to clear cache

This commit is contained in:
Justin Foell
2017-05-10 14:39:00 -05:00
parent 37816d12b8
commit 3bb9faace6
3 changed files with 23 additions and 3 deletions
+20 -1
View File
@@ -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() {
?><input type="checkbox" id="strava_cache_clear" name="strava_cache_clear" /><?php
}
public function sanitize_cache_clear( $checked ) {
if ( 'on' === $checked ) {
// Clear these values:
delete_transient( 'strava_latest_map_ride' );
delete_option( 'strava_latest_map_ride' );
delete_option( 'strava_latest_map' );
}
return null;
}
public function __get( $name ) {
return get_option( "strava_{$name}" );
}
+2 -2
View File
@@ -37,7 +37,7 @@ class WPStrava {
}
public function __get( $name ) {
//on-demand classes
// On-demand classes.
if ( $name == 'api' ) {
return $this->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;
+1
View File
@@ -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 =