mirror of
https://github.com/10h30/wp-strava.git
synced 2026-06-05 15:10:01 +09:00
Move shortcode adds to main class.
Fixed to avoid undefined index/property with abridged club activity data.
This commit is contained in:
@@ -14,11 +14,13 @@ class WPStrava {
|
||||
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' ) );
|
||||
|
||||
}
|
||||
|
||||
public static function get_instance() {
|
||||
@@ -82,4 +84,11 @@ class WPStrava {
|
||||
register_widget( 'WPStrava_LatestActivitiesWidget' );
|
||||
register_widget( 'WPStrava_LatestMapWidget' );
|
||||
}
|
||||
|
||||
public function register_shortcodes() {
|
||||
add_shortcode( 'ride', array( 'WPStrava_ActivityShortcode', 'handler' ) ); // @deprecated 1.1
|
||||
add_shortcode( 'activity', array( 'WPStrava_ActivityShortcode', 'handler' ) );
|
||||
add_shortcode( 'activities', array( 'WPStrava_LatestActivitiesShortcode', 'handler' ) );
|
||||
add_shortcode( 'route', array( 'WPStrava_RouteShortcode', 'handler' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ class WPStrava_ActivityShortcode {
|
||||
private static $add_script;
|
||||
|
||||
public static function init() {
|
||||
add_shortcode( 'ride', array( __CLASS__, 'handler' ) ); // @deprecated 1.1
|
||||
add_shortcode( 'activity', array( __CLASS__, 'handler' ) );
|
||||
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,22 @@ class WPStrava_LatestActivities {
|
||||
$response = "<ul id='activities'>";
|
||||
foreach ( $activities as $activity ) {
|
||||
$response .= "<li class='activity'>";
|
||||
$response .= "<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity->id . "'>" . $activity->name . '</a>';
|
||||
$response .= empty( $activity->id ) ?
|
||||
$activity->name :
|
||||
"<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity->id . "'>" . $activity->name . '</a>';
|
||||
$response .= "<div class='activity-item'>";
|
||||
$unixtime = strtotime( $activity->start_date_local );
|
||||
// Translators: Shows something like "On <date> <[went 10 miles] [during 2 hours] [climbing 100 feet]>."
|
||||
$response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
|
||||
|
||||
if ( ! empty( $activity->start_date_local ) ) {
|
||||
$unixtime = strtotime( $activity->start_date_local );
|
||||
// Translators: Shows something like "On <date> <[went 10 miles] [during 2 hours] [climbing 100 feet]>."
|
||||
$response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
|
||||
}
|
||||
|
||||
if ( is_numeric( $args['strava_club_id'] ) ) {
|
||||
$response .= " <a href='" . WPStrava_Activity::ATHLETES_URL . $activity->athlete->id . "'>" . $activity->athlete->firstname . ' ' . $activity->athlete->lastname . '</a>';
|
||||
$name = $activity->athlete->firstname . ' ' . $activity->athlete->lastname;
|
||||
$response .= empty( $activity->athlete->id ) ?
|
||||
" {$name}" :
|
||||
" <a href='" . WPStrava_Activity::ATHLETES_URL . $activity->athlete->id . "'>" . $name . '</a>';
|
||||
}
|
||||
|
||||
// Translators: "went 10 miles"
|
||||
|
||||
@@ -4,7 +4,6 @@ class WPStrava_LatestActivitiesShortcode {
|
||||
private static $add_script;
|
||||
|
||||
public static function init() {
|
||||
add_shortcode( 'activities', array( __CLASS__, 'handler' ) );
|
||||
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ 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 _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,11 +36,11 @@ 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 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>
|
||||
<label for="<?php echo $this->get_field_id( 'strava_club_id' ); ?>"><?php esc_html_e( 'Club ID (leave blank to show Athlete):', 'wp-strava' ); ?></label>
|
||||
<label for="<?php echo $this->get_field_id( 'strava_club_id' ); ?>"><?php esc_html_e( 'Club ID (leave blank to show Athlete):', 'wp-strava' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'strava_club_id' ); ?>" name="<?php echo $this->get_field_name( 'strava_club_id' ); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
|
||||
</p>
|
||||
<?php
|
||||
@@ -78,7 +78,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
|
||||
$activity = $activity_transient ? $activity_transient : null;
|
||||
|
||||
if ( ! $activity ) {
|
||||
if ( ! $activity || empty( $activity->map ) ) {
|
||||
$strava_activity = WPStrava::get_instance()->activity;
|
||||
$activities = $strava_activity->get_activities( $athlete_token, $strava_club_id );
|
||||
|
||||
@@ -127,9 +127,11 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
echo $args['before_title'] . $title . $args['after_title'];
|
||||
}
|
||||
|
||||
echo "<a title='{$activity->name}' href='" . WPStrava_Activity::ACTIVITIES_URL . "{$activity->id}'>";
|
||||
echo $this->get_static_image( $id, $activity, $build_new );
|
||||
echo '</a>';
|
||||
echo empty( $activity->map ) ?
|
||||
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 ) .
|
||||
'</a>';
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ class WPStrava_RouteShortcode {
|
||||
private static $add_script;
|
||||
|
||||
public static function init() {
|
||||
add_shortcode( 'route', array( __CLASS__, 'handler' ) );
|
||||
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ If your API key works with other Google Maps plugins but not WP Strava, you may
|
||||
|
||||
= 1.5.0 =
|
||||
|
||||
Added additional checks for abridged club data to avoid undefined index/property errors https://wordpress.org/support/topic/club-activities-bugs-strava/
|
||||
Added composer with PSR-0 autoloader (will switch to PSR-4 once WP's PHP 5.2 requirement goes away).
|
||||
Moved files into appropriate place to support autoloader.
|
||||
Added WordPress-Extra coding standards rule definition to project
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: WP Strava
|
||||
* Plugin URI: https://wordpress.org/plugins/wp-strava/
|
||||
* Description: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license.
|
||||
* Version: 1.5.0-r1
|
||||
* Version: 1.5.0-rc2
|
||||
* Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott
|
||||
* License: GPL2
|
||||
* Text Domain: wp-strava
|
||||
|
||||
Reference in New Issue
Block a user