Use template function and load as needed
This commit is contained in:
125
includes/class-sp-shortcodes.php
Normal file
125
includes/class-sp-shortcodes.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* SP_Shortcodes class.
|
||||
*
|
||||
* @class SP_Shortcodes
|
||||
* @version 0.7
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
class SP_Shortcodes {
|
||||
|
||||
/**
|
||||
* Init shortcodes
|
||||
*/
|
||||
public static function init() {
|
||||
// Define shortcodes
|
||||
$shortcodes = array(
|
||||
'countdown' => __CLASS__ . '::countdown',
|
||||
'event_list' => __CLASS__ . '::event_list',
|
||||
'event_calendar' => __CLASS__ . '::event_calendar',
|
||||
'league_table' => __CLASS__ . '::league_table',
|
||||
'player_list' => __CLASS__ . '::player_list',
|
||||
'player_gallery' => __CLASS__ . '::player_gallery',
|
||||
);
|
||||
|
||||
foreach ( $shortcodes as $shortcode => $function ) {
|
||||
add_shortcode( $shortcode, $function );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode Wrapper
|
||||
*
|
||||
* @param mixed $function
|
||||
* @param array $atts (default: array())
|
||||
* @return string
|
||||
*/
|
||||
public static function shortcode_wrapper(
|
||||
$function,
|
||||
$atts = array(),
|
||||
$wrapper = array(
|
||||
'class' => 'sportspress',
|
||||
'before' => null,
|
||||
'after' => null
|
||||
)
|
||||
) {
|
||||
ob_start();
|
||||
|
||||
$before = empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
|
||||
$after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
|
||||
|
||||
echo $before;
|
||||
call_user_func( $function, $atts );
|
||||
echo $after;
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Countdown shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function countdown( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Countdown', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Event calendar shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function event_calendar( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_Calendar', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Event list shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function event_list( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_List', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* League table shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function league_table( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_League_Table', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Player list shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function player_list( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Player_List', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Player gallery shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function player_gallery( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Player_Gallery', 'output' ), $atts );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user