BlockTemplatesService.php
1 year ago
CollectionTemplateService.php
1 year ago
TemplatesService.php
1 year ago
TemplatesServiceProvider.php
1 year ago
UpsellTemplatesService.php
1 year ago
CollectionTemplateService.php
50 lines
| 1 | <?php |
| 2 | namespace SureCart\WordPress\Templates; |
| 3 | |
| 4 | /** |
| 5 | * The template service. |
| 6 | */ |
| 7 | class CollectionTemplateService { |
| 8 | /** |
| 9 | * The template file/name associations. |
| 10 | * |
| 11 | * @var array |
| 12 | */ |
| 13 | private $templates = []; |
| 14 | |
| 15 | /** |
| 16 | * The post type for the templates. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | private $type = 'sc_collection'; |
| 21 | |
| 22 | /** |
| 23 | * Get things going. |
| 24 | * |
| 25 | * @param array $templates The template file/name associations. |
| 26 | */ |
| 27 | public function __construct( $templates ) { |
| 28 | $this->templates = $templates; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Bootstrap actions and filters. |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function bootstrap() { |
| 37 | add_filter( 'theme_' . $this->type . '_templates', [ $this, 'addTemplates' ] ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Add the templates to the theme. |
| 42 | * |
| 43 | * @param array $templates The templates. |
| 44 | * @return array |
| 45 | */ |
| 46 | public function addTemplates( $templates ) { |
| 47 | return array_merge( $templates, $this->templates ); |
| 48 | } |
| 49 | } |
| 50 |