| 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 |
} |