views = Views::get_instance(); add_filter( 'archive_template', [ $this, 'archive_template' ] ); add_filter( 'single_template', [ $this, 'single_template' ] ); add_filter( 'taxonomy_template', [ $this, 'taxonomy_template' ] ); add_filter( 'theme_page_templates', [ $this, 'add_page_template' ] ); add_filter( 'template_include', [ $this, 'load_page_template' ], 99 ); } public function add_page_template( $templates ) { $templates['acumenon-kb-template.php'] = __( 'Acumenon KB', 'acumenon' ); return $templates; } public function load_page_template( $template ) { global $post; if ( ! $post ) { return $template; } $page_template = get_post_meta( $post->ID, '_wp_page_template', true ); if ( 'acumenon-kb-template.php' === $page_template ) { $plugin_template = $this->views->get_template_path( 'archive' ); if ( $plugin_template ) { return $plugin_template; } } return $template; } public function archive_template( $template ) { $post_type = PostType::get_instance(); if ( is_post_type_archive( $post_type->post_type ) ) { // Check if theme overrides it via `archive-acmn_docs.php` or `acumenon/archive.php` $theme_template = locate_template( [ 'archive-' . $post_type->post_type . '.php', 'acumenon/archive.php' ] ); if ( $theme_template ) { return $theme_template; } // Fallback to plugin template $plugin_template = $this->views->get_template_path( 'archive' ); if ( $plugin_template ) { return $plugin_template; } } return $template; } public function single_template( $template ) { $post_type = PostType::get_instance(); if ( is_singular( $post_type->post_type ) ) { $theme_template = locate_template( [ 'single-' . $post_type->post_type . '.php', 'acumenon/single.php' ] ); if ( $theme_template ) { return $theme_template; } $plugin_template = $this->views->get_template_path( 'single' ); if ( $plugin_template ) { return $plugin_template; } } return $template; } public function taxonomy_template( $template ) { $post_type = PostType::get_instance(); if ( is_tax( $post_type->category ) || is_tax( $post_type->tag ) || ( property_exists( $post_type, 'knowledge_base' ) && is_tax( $post_type->knowledge_base ) ) ) { $taxonomy = get_query_var( 'taxonomy' ); $theme_template = locate_template( [ 'taxonomy-' . $taxonomy . '.php', 'acumenon/category.php' ] ); if ( $theme_template ) { return $theme_template; } if ( is_tax( $post_type->knowledge_base ) ) { $plugin_template = $this->views->get_template_path( 'archive' ); if ( $plugin_template ) { return $plugin_template; } } else { $plugin_template = $this->views->get_template_path( 'category' ); if ( $plugin_template ) { return $plugin_template; } } } return $template; } }