PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / TemplateLoader.php

TemplateLoader.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.2, at includes/TemplateLoader.php

105 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template Loader Class
4 *
5 * @package Easy_Invoice
6 * @subpackage Includes
7 */
8
9 namespace EasyInvoice;
10
11 /**
12 * Template Loader Class
13 *
14 * Handles loading of custom templates for the Easy Invoice plugin.
15 */
16 class TemplateLoader {
17
18 /**
19 * Initialize the template loader
20 */
21 public function init() {
22 add_filter('single_template', [$this, 'loadSingleQuoteTemplate']);
23 add_filter('single_template', [$this, 'loadSingleInvoiceTemplate']);
24 add_filter('template_include', [$this, 'loadCustomTemplates']);
25 }
26
27 /**
28 * Load single quote template
29 *
30 * @param string $template The template path
31 * @return string Modified template path
32 */
33 public function loadSingleQuoteTemplate($template) {
34 global $post;
35
36 if ($post && $post->post_type === \EasyInvoice\Constants\PostTypes::EASY_INVOICE_QUOTE_POST_TYPE) {
37 $custom_template = EASY_INVOICE_PLUGIN_DIR . 'templates/quotes/single.php';
38
39 if (file_exists($custom_template)) {
40 return $custom_template;
41 } else {
42 // Single quote template not found
43 }
44 }
45
46 return $template;
47 }
48
49 /**
50 * Load single invoice template
51 *
52 * @param string $template The template path
53 * @return string Modified template path
54 */
55 public function loadSingleInvoiceTemplate($template) {
56 global $post;
57
58 if ($post && $post->post_type === \EasyInvoice\Constants\PostTypes::EASY_INVOICE_POST_TYPE) {
59 $custom_template = EASY_INVOICE_PLUGIN_DIR . 'templates/invoices/single.php';
60
61 if (file_exists($custom_template)) {
62 return $custom_template;
63 } else {
64 // Single invoice template not found
65 }
66 }
67
68 return $template;
69 }
70
71 /**
72 * Load custom templates for Easy Invoice pages
73 *
74 * @param string $template The template path
75 * @return string Modified template path
76 */
77 public function loadCustomTemplates($template) {
78 global $post;
79
80 // Handle single quote pages
81 if (is_singular(\EasyInvoice\Constants\PostTypes::EASY_INVOICE_QUOTE_POST_TYPE)) {
82 $custom_template = EASY_INVOICE_PLUGIN_DIR . 'templates/quotes/single.php';
83
84
85 if (file_exists($custom_template)) {
86 return $custom_template;
87 } else {
88 // Single quote template not found
89 }
90 }
91
92 // Handle single invoice pages
93 if (is_singular(\EasyInvoice\Constants\PostTypes::EASY_INVOICE_POST_TYPE)) {
94 $custom_template = EASY_INVOICE_PLUGIN_DIR . 'templates/invoices/single.php';
95
96 if (file_exists($custom_template)) {
97 return $custom_template;
98 } else {
99 // Single invoice template not found
100 }
101 }
102
103 return $template;
104 }
105 }