Added some missing 'Translators:' comments

Added class documentation
Changed phpcs ignores to new style
This commit is contained in:
Justin Foell
2018-03-23 16:52:06 -05:00
parent c1fc8fc2d9
commit 702febcc8c
6 changed files with 84 additions and 11 deletions
+71 -5
View File
@@ -1,13 +1,43 @@
<?php
/*
* Main Strava plugin class.
*/
class WPStrava {
/**
* Instance of this class (singleton).
* @var WPStrava
*/
private static $instance = null;
private $settings = null;
private $api = array(); // Holds an array of APIs.
private $activity = null;
private $routes = null;
/**
* Settings object to access settings.
* @var WPStrava_Settings
*/
private $settings = null;
/**
* Array of WPStrava_API objects (one for each athlete).
*
* @var array
*/
private $api = array();
/**
* Activity object to get activities.
* @var WPStrava_Activity
*/
private $activity = null;
/**
* Route object to get routes.
* @var WPStrava_Routes
*/
private $routes = null;
/**
* Private constructor (singleton).
*/
private function __construct() {
$this->settings = new WPStrava_Settings();
@@ -23,6 +53,11 @@ class WPStrava {
}
/**
* Get a singleton instance.
*
* @return WPStrava
*/
public static function get_instance() {
if ( ! self::$instance ) {
$class = __CLASS__;
@@ -31,6 +66,12 @@ class WPStrava {
return self::$instance;
}
/**
* Magic method to access activity, routes, settings, etc.
*
* @param string $name One of activity, routes, settings.
* @return mixed|null
*/
public function __get( $name ) {
// On-demand classes.
if ( 'activity' === $name ) {
@@ -48,6 +89,12 @@ class WPStrava {
return null;
}
/**
* Get an API object for the given athelete token.
*
* @param string $token Athlete token.
* @return WPStrava_API
*/
public function get_api( $token = null ) {
if ( ! $token ) {
$token = $this->settings->get_default_token();
@@ -60,6 +107,11 @@ class WPStrava {
return $this->api[ $token ];
}
/**
* Get the activity object.
*
* @return WPStrava_Activity
*/
public function get_activity() {
if ( ! $this->activity ) {
$this->activity = new WPStrava_Activity();
@@ -68,6 +120,11 @@ class WPStrava {
return $this->activity;
}
/**
* Get the routes object.
*
* @return WPStrava_Routes
*/
public function get_routes() {
if ( ! $this->routes ) {
$this->routes = new WPStrava_Routes();
@@ -75,16 +132,25 @@ class WPStrava {
return $this->routes;
}
/**
* Register the wp-strava stylesheet.
*/
public function register_scripts() {
// Register a personalized stylesheet.
wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
}
/**
* Register the widgets.
*/
public function register_widgets() {
register_widget( 'WPStrava_LatestActivitiesWidget' );
register_widget( 'WPStrava_LatestMapWidget' );
}
/**
* Register the shortcodes.
*/
public function register_shortcodes() {
add_shortcode( 'ride', array( 'WPStrava_ActivityShortcode', 'handler' ) ); // @deprecated 1.1
add_shortcode( 'activity', array( 'WPStrava_ActivityShortcode', 'handler' ) );
+1 -1
View File
@@ -38,7 +38,7 @@ class WPStrava_API {
if ( ! empty( $body->error ) ) {
$error = $body->error;
} else {
$error = print_r( $response, true ); // @codingStandardsIgnoreLine
$error = print_r( $response, true ); // phpcs:ignore -- Debug output.
}
return new WP_Error(
+1 -1
View File
@@ -29,7 +29,7 @@ class WPStrava_ActivityShortcode {
if ( is_wp_error( $activity_details ) ) {
if ( WPSTRAVA_DEBUG ) {
return '<pre>' . print_r( $activity_details, true ) . '</pre>'; // @codingStandardsIgnoreLine
return '<pre>' . print_r( $activity_details, true ) . '</pre>'; // phpcs:ignore -- Debug output.
} else {
return $activity_details->get_error_message();
}
+9 -2
View File
@@ -24,7 +24,10 @@ class WPStrava_LatestMapWidget extends WP_Widget {
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-strava' ); ?></label>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
<?php // Translator: Widget Title. ?>
<?php esc_html_e( 'Title:', 'wp-strava' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
@@ -36,7 +39,10 @@ class WPStrava_LatestMapWidget extends WP_Widget {
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'distance_min' ); ?>"><?php echo sprintf( __( 'Min. Distance (%s):', 'wp-strava' ), $this->som->get_distance_label() ); ?></label>
<label for="<?php echo $this->get_field_id( 'distance_min' ); ?>">
<?php // Translators: Label for minimum distance input. ?>
<?php echo sprintf( __( 'Min. Distance (%s):', 'wp-strava' ), $this->som->get_distance_label() ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'distance_min' ); ?>" name="<?php echo $this->get_field_name( 'distance_min' ); ?>" type="text" value="<?php echo $distance_min; ?>" />
</p>
<p>
@@ -128,6 +134,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
}
echo empty( $activity->map ) ?
// Translators: Text with activity name shown in place of image if not available.
sprintf( __( 'Map not available for activity "%s"', 'wp-strava' ), $activity->name ) :
"<a title='{$activity->name}' href='" . WPStrava_Activity::ACTIVITIES_URL . "{$activity->id}'>" .
$this->get_static_image( $id, $activity, $build_new ) .
+1 -1
View File
@@ -35,7 +35,7 @@ class WPStrava_RouteShortcode {
if ( is_wp_error( $route_details ) ) {
if ( WPSTRAVA_DEBUG ) {
return '<pre>' . print_r( $route_details, true ) . '</pre>'; // @codingStandardsIgnoreLine
return '<pre>' . print_r( $route_details, true ) . '</pre>'; // phpcs:ignore -- Debug output.
} else {
return $route_details->get_error_message();
}
+1 -1
View File
@@ -308,7 +308,7 @@ class WPStrava_Settings {
}
} else {
// Translators: error message from Strava
$this->feedback .= sprintf( __( 'There was an error receiving data from Strava: %s', 'wp-strava' ), print_r( $strava_info, true ) ); // @codingStandardsIgnoreLine
$this->feedback .= sprintf( __( 'There was an error receiving data from Strava: %s', 'wp-strava' ), print_r( $strava_info, true ) ); // phpcs:ignore -- Debug output.
return false;
}
} else {