mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-17 13:43:50 +09:00
Fixed Activity filter and added Activity Unit Test
This commit is contained in:
+21
-13
@@ -47,19 +47,6 @@ class WPStrava {
|
||||
private function __construct() {
|
||||
$this->settings = new WPStrava_Settings();
|
||||
$this->auth = WPStrava_Auth::get_auth( 'refresh' );
|
||||
|
||||
$this->auth->hook();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->settings->hook();
|
||||
} else {
|
||||
add_action( 'init', array( $this, 'register_shortcodes' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
|
||||
}
|
||||
|
||||
// Register widgets.
|
||||
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +62,27 @@ class WPStrava {
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to install hooks at WP runtime.
|
||||
*
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function hook() {
|
||||
$this->auth->hook();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->settings->hook();
|
||||
} else {
|
||||
add_action( 'init', array( $this, 'register_shortcodes' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
|
||||
}
|
||||
|
||||
// Register widgets.
|
||||
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to access activity, routes, settings, etc.
|
||||
*
|
||||
|
||||
@@ -78,7 +78,7 @@ abstract class WPStrava_Auth {
|
||||
return rawurlencode( admin_url( "options-general.php?page={$page_name}" ) );
|
||||
}
|
||||
|
||||
// was fetch_token();
|
||||
// Was fetch_token();
|
||||
private function token_exchange_initial( $code ) {
|
||||
$settings = WPStrava::get_instance()->settings;
|
||||
$client_id = $settings->client_id;
|
||||
|
||||
@@ -111,7 +111,6 @@ class WPStrava_RouteShortcode {
|
||||
private function get_table( $route_details, $som ) {
|
||||
$strava_som = WPStrava_SOM::get_som( $som );
|
||||
|
||||
|
||||
$elevation_title = '<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>';
|
||||
$elevation = '<td>' . $strava_som->elevation( $route_details->elevation_gain ) . '</td>';
|
||||
$elevation_label = '<td>' . $strava_som->get_elevation_label() . '</td>';
|
||||
|
||||
@@ -14,17 +14,17 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
|
||||
* @return string Distance in miles.
|
||||
*/
|
||||
public function distance( $m ) {
|
||||
return number_format( $m / 1609.344, 2 );
|
||||
return number_format_i18n( $m / 1609.344, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change miles to meters.
|
||||
*
|
||||
* @param float|string $dist Distance in miles.
|
||||
* @return string Distance in meters.
|
||||
* @param float $dist Distance in miles.
|
||||
* @return float Distance in meters.
|
||||
*/
|
||||
public function distance_inverse( $dist ) {
|
||||
return number_format( $dist * 1609.344, 2 );
|
||||
return (float) number_format( $dist * 1609.344, 2, '.', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
|
||||
* @return string Miles per hour.
|
||||
*/
|
||||
public function speed( $mps ) {
|
||||
return number_format( $mps * 2.2369, 2 );
|
||||
return number_format_i18n( $mps * 2.2369, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
|
||||
* @return string Elevation in feet.
|
||||
*/
|
||||
public function elevation( $m ) {
|
||||
return number_format( $m / 0.3048, 2 );
|
||||
return number_format_i18n( $m / 0.3048, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,17 +14,17 @@ class WPStrava_SOMMetric extends WPStrava_SOM {
|
||||
* @return string Distance in kilometers.
|
||||
*/
|
||||
public function distance( $m ) {
|
||||
return number_format( $m / 1000, 2 );
|
||||
return number_format_i18n( $m / 1000, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change kilometers to meters.
|
||||
*
|
||||
* @param float|string $dist Distance in kilometers.
|
||||
* @return string Distance in meters.
|
||||
* @param float $dist Distance in kilometers.
|
||||
* @return float Distance in meters.
|
||||
*/
|
||||
public function distance_inverse( $dist ) {
|
||||
return number_format( $dist * 1000, 2 );
|
||||
return (float) number_format( $dist * 1000, 2, '.', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class WPStrava_SOMMetric extends WPStrava_SOM {
|
||||
* @return string Kilometers per hour.
|
||||
*/
|
||||
public function speed( $mps ) {
|
||||
return number_format( $mps * 3.6, 2 );
|
||||
return number_format_i18n( $mps * 3.6, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ class WPStrava_SOMMetric extends WPStrava_SOM {
|
||||
* @return string Elevation in meters.
|
||||
*/
|
||||
public function elevation( $m ) {
|
||||
return number_format( $m, 2 );
|
||||
return number_format_i18n( $m, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,17 +16,6 @@ class WPStrava_Settings {
|
||||
private $option_page = 'wp-strava-settings-group';
|
||||
private $adding_athlete = true;
|
||||
|
||||
|
||||
/**
|
||||
* Settings constructor.
|
||||
*
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->ids = $this->get_ids();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register actions & filters for menus and authentication.
|
||||
*
|
||||
@@ -34,6 +23,9 @@ class WPStrava_Settings {
|
||||
* @since 0.62
|
||||
*/
|
||||
public function hook() {
|
||||
// Load IDs for any subsequent actions.
|
||||
$this->ids = $this->get_ids();
|
||||
|
||||
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
|
||||
add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
|
||||
@@ -260,7 +252,7 @@ class WPStrava_Settings {
|
||||
*
|
||||
* @param string $client_secret
|
||||
* @return string
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public function sanitize_client_secret( $client_secret ) {
|
||||
@@ -574,12 +566,12 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Update options with new Client ID and Info.
|
||||
*
|
||||
* @param int $id Strava API Client ID
|
||||
* @param string $secret Strava API Client Secret
|
||||
* @param stdClass $info
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function save_info( $id, $secret, $info ) {
|
||||
@@ -595,7 +587,7 @@ class WPStrava_Settings {
|
||||
*
|
||||
* @param int $key Strava Client ID
|
||||
* @return boolean True if Client ID is in $this->ids, false otherwise.
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function filter_by_id( $key ) {
|
||||
@@ -606,10 +598,9 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Remove the client ID and Secret (they're saved in the strava_info option).
|
||||
*
|
||||
* @return void
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function delete_id_secret() {
|
||||
@@ -618,11 +609,11 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Check to see if settings have been updated.
|
||||
*
|
||||
* @param [type] $value
|
||||
* @param array $value Data array from pre_set_transient_settings_errors filter.
|
||||
* @return boolean
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function is_settings_updated( $value ) {
|
||||
@@ -630,10 +621,10 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Whether or not we're on the options page.
|
||||
*
|
||||
* @return boolean
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function is_option_page() {
|
||||
@@ -641,10 +632,10 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Whether or not we're on the WP-Strava settings page.
|
||||
*
|
||||
* @return boolean
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function is_settings_page() {
|
||||
@@ -652,10 +643,10 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Get the WP-Strava settings page name.
|
||||
*
|
||||
* @return string
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_page_name() {
|
||||
@@ -663,10 +654,10 @@ class WPStrava_Settings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Whether or not we're adding a new athlete.
|
||||
*
|
||||
* @return boolean
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private function is_adding_athlete() {
|
||||
@@ -707,7 +698,7 @@ class WPStrava_Settings {
|
||||
*
|
||||
* @param array $data Plugin data with readme additions.
|
||||
* @param array $response Response from wp.org.
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 1.7.3
|
||||
*/
|
||||
public function plugin_update_message( $data, $response ) {
|
||||
@@ -721,7 +712,7 @@ class WPStrava_Settings {
|
||||
*
|
||||
* @param string $file Relative path to plugin, i.e. wp-strava/wp-strava.php.
|
||||
* @param array $plugin Plugin data with readme additions.
|
||||
* @author Justin Foell <justin.foell@webdevstudios.com>
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 1.7.3
|
||||
*/
|
||||
public function ms_plugin_update_message( $file, $plugin ) {
|
||||
|
||||
Reference in New Issue
Block a user