我想用自定义的模板替换类函数包含的第三方插件中的模板。我试图通过扩展父类来重写该类函数,但目前这只是预期输出的两倍。如何删除原始功能?我需要删除父类中添加的筛选器?如何做到这一点?
主类如下所示:
class Import_Some_Events_Cpt {
public function __construct() {
add_filter( \'the_content\', array( $this, \'some_events_meta_before_content\' ) );
}
function some_events_meta_before_content( $content ) {
$event_details = $this->some_events_get_event_meta( get_the_ID() );
$content = $event_details . $content;
return $content;
}
function some_events_get_event_meta() {
//here is included the original plugin template
}
}
我的扩展类如下所示:
class Import_Some_Events_Cpt_Ext extends Import_Some_Events_Cpt {
function some_events_meta_before_content( $content ) {
$event_details = $this->some_events_get_event_meta( get_the_ID() );
$content = $event_details . $content;
return $content;
}
function some_events_get_event_meta() {
//here is included the customized template
}
}
UPDATE
原始类Import\\u Some\\u Events\\u Cpt在另一个类中实例化:
class Import_Some_Events{
private static $instance;
public static function instance() {
if( ! isset( self::$instance ) && ! (self::$instance instanceof Import_Some_Events ) ) {
self::$instance = new Import_Some_Events;
self::$instance->setup_constants();
add_action( \'plugins_loaded\', array( self::$instance, \'load_textdomain\' ) );
self::$instance->cpt = new Import_Some_Events_Cpt();
}
return self::$instance;
}
}
此类从单独的函数实例化:
function run_import_some_events() {
return Import_Some_Events::instance();
}
上述函数设置为变量:
$ife_events = run_import_some_events();
所有代码都位于我要重写的类以外的其他文件中。
对不起,如果我犯了错误,我不是程序员。