* @since 1.6.0
*/
public function __construct() {
add_shortcode( 'route', array( $this, 'handler' ) );
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
}
/**
* Shortcode handler for [route].
*
* [route id=id som=metric map_width="100%" map_height="400px" markers=false]
*
* @param array $atts Array of attributes (id, map_width, etc.).
* @return string Shortcode output
* @author Daniel Lintott
* @since 1.3.0
*/
public function handler( $atts ) {
$this->add_script = true;
$defaults = array(
'id' => 0,
'som' => WPStrava::get_instance()->settings->som,
'map_width' => '480',
'map_height' => '320',
'client_id' => WPStrava::get_instance()->settings->get_default_id(),
'markers' => false,
'image_only' => false,
);
$atts = shortcode_atts( $defaults, $atts, 'route' );
if ( isset( $atts['athlete_token'] ) ) {
// Translators: Message shown when using deprecated athlete_token parameter.
return __( 'The athlete_token parameter is deprecated as of WP-Strava version 2 and should be replaced with client_id.', 'wp-strava' );
}
/* Make sure boolean values are actually boolean
* @see https://wordpress.stackexchange.com/a/119299
*/
$atts['markers'] = filter_var( $atts['markers'], FILTER_VALIDATE_BOOLEAN );
$atts['image_only'] = filter_var( $atts['image_only'], FILTER_VALIDATE_BOOLEAN );
$route = WPStrava::get_instance()->routes;
$route_details = null;
try {
$route_details = $route->get_route( $atts['id'] );
} catch ( WPStrava_Exception $e ) {
return $e->to_html();
}
$route_output = '';
if ( $route_details ) {
$route_output = '
| ' . __( 'Est. Moving Time', 'wp-strava' ) . ' | ' . __( 'Distance', 'wp-strava' ) . ' | ' . $elevation_title . '
|---|---|
| ' . $strava_som->time( $route_details->estimated_moving_time ) . ' | ' . $strava_som->distance( $route_details->distance ) . ' | ' . $elevation . '
| ' . $strava_som->get_time_label() . ' | ' . $strava_som->get_distance_label() . ' | ' . $elevation_label . '