In my plugin, I would like to load css only when the front-end current page is using one of my plugin shortcodes.
All my shortcodes are classes extending Shortcode class. Shortcode class helps me to automate the callback function.
Shortcode abstract class
namespace PluginFoo\Shortcodes;
abstract class Shortcode {
public $tag;
public $attrs;
public $function;
public function __construct($tag) {
$this->attrs = array();
$this->tag = $tag;
$this->function = static::className().'::getCallBack';
add_shortcode( $this->tag, $this->function );
}
abstract public static function className();
abstract public static function getCallBack( $attrs );
}
FooShortcode class
namespace PluginFoo\Shortcodes;
class FooShortcode extends Shortcode {
public static function getCallBack( $attrs = null ){
add_action('wp_enqueue_scripts', array( __CLASS__, 'set_bootstrap' ) ); // <-- Here - function set_bootstrap not called !
$output = '';
ob_start();
//HTML Template
include_once 'shortcode-view.php';
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
public static function set_bootstrap() {
wp_enqueue_style( 'bootstrapstyle', PLUGIN_DIR_URL . 'css/bootstrap.min.css' );
}
public static function className(){
return __CLASS__;
}
}
How can I call correcty the static function set_bootstrap() in add_action() inside an another static function ?