我正在用短代码做一个插件。我有一些类扩展了一个称为Shortcode的抽象类。
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 );
$this->init();
}
protected function init(){
if( !is_admin() ){
//Front-end
error_log(\'test 1\');
add_action(\'wp\', array( $this , \'check_page\' ) );
}
}
abstract public function check_page();
abstract public static function className();
abstract public static function getCallBack( $attrs );
}
My Shortcode class
class MyShortcode extends Shortcode {
public function check_page(){
error_log( "test 2" );
global $post;
$pattern = \'/(\\[\'.$this->tag.\'\\])/\';
if( !empty( $post->post_content ) && preg_match( $pattern, $post->post_content ) ){
add_action(\'wp_enqueue_scripts\', array( $this , \'set_styles\'));
}
}
public static function getCallBack( $attrs = null ){
...
}
//CSS stylesheets
public function set_styles() {
//wp_enqueue_style( \'wgsstyle\', PLUGIN_DIR_URL . \'front-end/views/css/wgs-front-end.css\' );
//wp_enqueue_style( \'wgscardsstyle\', PLUGIN_DIR_URL . \'front-end/views/css/wgs-cards.css\' );
}
public static function className(){
return __CLASS__;
}
}
发生的事情很奇怪。。。正在调试中。日志,它写的是“测试1”,但不是“测试2”,css样式表仍在加载。
是否有用于短代码的缓存?如何重新初始化此代码?