Added WPStrava Exception

Consolidated error handling
This commit is contained in:
Justin Foell
2018-04-27 21:19:27 -05:00
parent 7ad681cd1b
commit 50865bbbd2
9 changed files with 268 additions and 99 deletions
+49 -13
View File
@@ -1,25 +1,61 @@
<?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 {
private static $add_script;
public static function init() {
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
/**
* 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 function
// [activities som=metric quantity=5 athlete_token=xxx|strava_club_id=yyy]
public static function handler( $atts ) {
self::$add_script = true;
/**
* 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 );
} // handler
}
public static function print_scripts() {
if ( self::$add_script ) {
/**
* 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' );
}
}
}
// Initialize short code
WPStrava_LatestActivitiesShortcode::init();