Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class SC_Album_Main{
function __construct() {
add_action( 'init', array( __CLASS__, 'init_shortcode' ) );
}
public static function init_shortcode() {
add_shortcode( 'shortcode-album', array( __CLASS__, 'shortcode' ) );
}
/**
* Shortcode method
*
* @param array $atts
* @param string $content
*
* @return bool|string
* @author Nicolas Juen
*/
public static function shortcode( $atts = array() ) {
// On parse les attributs avec une version par défaut
$atts = shortcode_atts( array(
'id' => 0,
'display_artist' => false,
'add_link' => false
), $atts, 'shortcode-album' );
if( absint( $atts['id'] ) <= 0 ) {
return '';
}
// Récupération du template
$tpl = self::get_component_template_path( 'shortcode-album' );
// Vérification de la présence de celui-ci
if ( empty( $tpl ) ) {
return false;
}
}
/**
* Get the template_path for includes
*
* @param string $tpl
*
* @return bool|string
* @author Nicolas Juen
*
*/
public static function get_component_template_path( $tpl = '' ) {
if ( empty( $tpl ) ) {
return false;
}
// Display the form, allow take template from child or parent theme
if ( is_file( STYLESHEETPATH . '/views/shortcode/' . $tpl . '.php' ) ) {// Use custom template from child theme
return ( STYLESHEETPATH . '/views/shortcode/' . $tpl . '.php' );
} elseif ( is_file( TEMPLATEPATH . '/views/shortcode/' . $tpl . '.php' ) ) {// Use custom template from parent theme
return (TEMPLATEPATH . '/views/shortcode/' . $tpl . '.php' );
} elseif ( is_file( SC_ALBUM_DIR . 'views/' . $tpl . '.php' ) ) {// Use builtin template
return ( SC_ALBUM_DIR . 'views/' . $tpl . '.php' );
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment