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:
Steps:
+