admin管理员组文章数量:1406222
I'm using a plugin that adds this filter :
$this->base = 'hotel-room';
$this->taxBase = 'hotel-room-category';
add_filter( 'single_template', array( $this, 'registerSingleTemplate' ) );
I want to remove this filter because I want to be able to manage this file in my child-theme.
The filter is part of this class :
class HotelRoomRegister implements Lib\PostTypeInterface {
/**
* @var string
*/
private $base;
/**
* @var string
*/
private $taxBase;
public function __construct() {
$this->base = 'hotel-room';
$this->taxBase = 'hotel-room-category';
add_action( 'admin_menu', array( $this, 'removeLocationTagMetaBox' ) );
add_action( 'admin_menu', array( $this, 'removeExtraServicesTagMetaBox' ) );
add_action( 'admin_menu', array( $this, 'removeReviewTagMetaBox' ) );
add_filter( 'single_template', array( $this, 'registerSingleTemplate' ) );
}
I added the following to my functions.php in my child theme, but it doesn't change anything:
global $HotelRoomRegister;
remove_filter( 'single_template', array( 'hotel-room', 'registerSingleTemplate' ) );
How can I manage this ?
Also, in case it's helpful, here is the function linked to this filter in the same class:
public function registerSingleTemplate( $single ) {
global $post;
if ( isset( $post ) && $post->post_type == $this->base ) {
if ( ! file_exists( get_template_directory() . '/single-' . $this->base . '.php' ) ) {
return MIKADO_HOTEL_CPT_PATH . '/hotel-room/templates/single-' . $this->base . '.php';
}
}
return $single;
}
I'm using a plugin that adds this filter :
$this->base = 'hotel-room';
$this->taxBase = 'hotel-room-category';
add_filter( 'single_template', array( $this, 'registerSingleTemplate' ) );
I want to remove this filter because I want to be able to manage this file in my child-theme.
The filter is part of this class :
class HotelRoomRegister implements Lib\PostTypeInterface {
/**
* @var string
*/
private $base;
/**
* @var string
*/
private $taxBase;
public function __construct() {
$this->base = 'hotel-room';
$this->taxBase = 'hotel-room-category';
add_action( 'admin_menu', array( $this, 'removeLocationTagMetaBox' ) );
add_action( 'admin_menu', array( $this, 'removeExtraServicesTagMetaBox' ) );
add_action( 'admin_menu', array( $this, 'removeReviewTagMetaBox' ) );
add_filter( 'single_template', array( $this, 'registerSingleTemplate' ) );
}
I added the following to my functions.php in my child theme, but it doesn't change anything:
global $HotelRoomRegister;
remove_filter( 'single_template', array( 'hotel-room', 'registerSingleTemplate' ) );
How can I manage this ?
Also, in case it's helpful, here is the function linked to this filter in the same class:
public function registerSingleTemplate( $single ) {
global $post;
if ( isset( $post ) && $post->post_type == $this->base ) {
if ( ! file_exists( get_template_directory() . '/single-' . $this->base . '.php' ) ) {
return MIKADO_HOTEL_CPT_PATH . '/hotel-room/templates/single-' . $this->base . '.php';
}
}
return $single;
}
Share
Improve this question
edited Nov 21, 2019 at 15:19
butlerblog
5,1213 gold badges28 silver badges44 bronze badges
asked Nov 21, 2019 at 14:55
GregoryGregory
6025 silver badges20 bronze badges
1 Answer
Reset to default 2So after some digging managed to find the asnwer and instead of removing the filter you can overrid the single_template filter to add your own custom template.
add_filter( 'single_template', 'my_custom_single_template', 99, 1 );
function my_custom_single_template( $single ) {
global $post;
if ( isset( $post ) && $post->post_type == 'hotel-room' ) {
$single = require_once( STYLESHEETPATH . '/single-hotel-room.php');
}
return $single;
}
本文标签: phpRemove a filter added by a plugin
版权声明:本文标题:php - Remove a filter added by a plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744981648a2635851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论