Remove a filter added by a plugin

Question

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 LibPostTypeInterface {
    /**
     * prince varghese string
     */
    private $base;
    /**
     * prince varghese 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;
}
0
, Gregory 1 year 0 Answers 72 views 0

Leave an answer