mirror of
https://github.com/10h30/wp-strava.git
synced 2026-06-05 15:10:01 +09:00
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Latest Activities Shortcode [activities].
|
|
* @package WPStrava
|
|
*/
|
|
|
|
/**
|
|
* Latest Activities Shortcode class (converted from LatestRides).
|
|
*
|
|
* @author Justin Foell <justin@foell.org>
|
|
* @since 1.3.0
|
|
*/
|
|
class WPStrava_LatestActivitiesShortcode {
|
|
|
|
/**
|
|
* Whether or not to enqueue styles (if shortcode is present).
|
|
*
|
|
* @var boolean
|
|
* @author Justin Foell <justin@foell.org>
|
|
* @since 1.3.0
|
|
*/
|
|
private $add_script = false;
|
|
|
|
/**
|
|
* Constructor (converted from static init()).
|
|
*
|
|
* @author Justin Foell <justin@foell.org>
|
|
* @since 1.3.0
|
|
*/
|
|
public function __construct() {
|
|
add_shortcode( 'activities', array( $this, 'handler' ) );
|
|
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
|
|
}
|
|
|
|
/**
|
|
* Shortcode handler for [activities].
|
|
*
|
|
* [activities som=metric quantity=5 athlete_token=xxx|strava_club_id=yyy]
|
|
*
|
|
* @param array $atts Array of attributes (id, som, etc.).
|
|
* @return string Shortcode output
|
|
* @author Justin Foell <justin@foell.org>
|
|
* @since 1.3.0
|
|
*/
|
|
public function handler( $atts ) {
|
|
$this->add_script = true;
|
|
return WPStrava_LatestActivities::get_activities_html( $atts );
|
|
}
|
|
|
|
/**
|
|
* Enqueue style if shortcode is being used.
|
|
*
|
|
* @author Justin Foell <justin@foell.org>
|
|
* @since 1.3.0
|
|
*/
|
|
public function print_scripts() {
|
|
if ( $this->add_script ) {
|
|
wp_enqueue_style( 'wp-strava-style' );
|
|
}
|
|
}
|
|
}
|