Skip to content

Commit

Permalink
Added option to clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfoell committed May 10, 2017
1 parent 37816d1 commit 3bb9faa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion lib/Settings.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down Expand Up @@ -112,6 +112,11 @@ public function register_strava_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() {
Expand Down Expand Up @@ -242,6 +247,20 @@ public function sanitize_som( $som ) {
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}" );
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Strava.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function get_instance() {
}

public function __get( $name ) {
//on-demand classes
// On-demand classes.
if ( $name == 'api' ) {
return $this->get_api();
}
Expand All @@ -56,7 +56,7 @@ public function __get( $name ) {
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;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 3bb9faa

Please sign in to comment.