<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/**
 * Sifency Digital Single Render
 * Dynamically replaces the default digital single template with an Elementor one.
 */
if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {
final class Sifency_Digital_Single_Render {

    public function __construct() {
        if ( is_admin() ) return;

        add_filter( 'template_include', [ $this, 'override_digital_single_template' ], 9999 );
    }

    /**
     * Replace the default single template for 'documentation' CPT if a custom Elementor one exists.
     */
    public function override_digital_single_template( $template ) {
        if ( ! is_singular( 'digital' ) ) {
            return $template;
        }
        remove_filter( 'template_include', [ Sifency_Addons_Theme_Builder_Master::$sifency_addons_frontend_render, 'load_canvas_template' ], 999 );
        $sifency_addons_template_id = Sifency_Frontend_Helper::find_matching_template( 'digital' );
        if ( empty( $sifency_addons_template_id ) ) {
            return $template;
        }
        set_query_var( 'sifency_digital_single_template_id', $sifency_addons_template_id );
        $canvas_path = defined( 'SIFENCY_TB_PATH' )
            ? trailingslashit( SIFENCY_TB_PATH ) . 'post-type/digital/templates/sifency-digital-single-canvas.php'
            : plugin_dir_path( __FILE__ ) . 'templates/sifency-digital-single-canvas.php';

        return file_exists( $canvas_path ) ? $canvas_path : $template;
    }
}
new Sifency_Digital_Single_Render();
}