| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable template part |
| 4 |
* |
| 5 |
* @version 1.0.0 |
| 6 |
* @package Charitable/Classes/Charitable_Template_Part |
| 7 |
* @author Eric Daams |
| 8 |
* @copyright Copyright (c) 2022, Studio 164a |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Template_Part' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Template_Part |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Charitable_Template_Part { |
| 25 |
|
| 26 |
/** |
| 27 |
* @var string The template's slug. |
| 28 |
*/ |
| 29 |
private $slug; |
| 30 |
|
| 31 |
/** |
| 32 |
* @var string An optional name to be appended to the slug. |
| 33 |
*/ |
| 34 |
private $name; |
| 35 |
|
| 36 |
/** |
| 37 |
* Class constructor. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* |
| 41 |
* @param string $slug |
| 42 |
* @param string $name Optional name. |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function __construct($slug, $name = "" ) { |
| 46 |
$this->slug = $slug; |
| 47 |
$this->name = $name; |
| 48 |
|
| 49 |
new Charitable_Template( $this->get_template_names(), true, false ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns the array of template names. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* |
| 57 |
* @return array |
| 58 |
*/ |
| 59 |
private function get_template_names() { |
| 60 |
$names = array( |
| 61 |
$this->slug . '.php' |
| 62 |
); |
| 63 |
|
| 64 |
/** |
| 65 |
* If a name is set, add the slug-name.php combination to the start of the $names array |
| 66 |
*/ |
| 67 |
if ( strlen( $this->name ) ) { |
| 68 |
array_unshift( $names, $this->slug . '-' . $this->name . '.php' ); |
| 69 |
} |
| 70 |
|
| 71 |
return $names; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
endif; |