| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template Action. |
| 4 |
* |
| 5 |
* @package ULTP\Templates |
| 6 |
* @since v.1.0.0 |
| 7 |
*/ |
| 8 |
namespace ULTP; |
| 9 |
|
| 10 |
defined('ABSPATH') || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Templates class. |
| 14 |
*/ |
| 15 |
class Templates{ |
| 16 |
|
| 17 |
/** |
| 18 |
* Setup class. |
| 19 |
* |
| 20 |
* @since v.1.0.0 |
| 21 |
*/ |
| 22 |
public function __construct(){ |
| 23 |
add_filter( 'template_include', array($this, 'set_template_callback') ); |
| 24 |
$post_types = get_post_types(); |
| 25 |
if( !empty($post_types) ){ |
| 26 |
foreach ($post_types as $post_type){ |
| 27 |
add_filter( "theme_{$post_type}_templates", array( $this, 'add_template_callback' ) ); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Include Template File |
| 34 |
* |
| 35 |
* @since v.1.0.0 |
| 36 |
* @param STRING | Attachment |
| 37 |
* @return STRING | Template File Path |
| 38 |
*/ |
| 39 |
public function set_template_callback($template){ |
| 40 |
if ( is_singular() ) { |
| 41 |
if ( get_post_meta( get_the_ID(), '_wp_page_template', true ) === 'ultp_page_template' ) { |
| 42 |
$template = ULTP_PATH . 'classes/template-without-title.php'; |
| 43 |
} |
| 44 |
} |
| 45 |
return $template; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Add A Page Template |
| 50 |
* |
| 51 |
* @since v.1.0.0 |
| 52 |
* @param ARRAY | Page Template List |
| 53 |
* @return ARRAY | Page Template List as Array |
| 54 |
*/ |
| 55 |
public function add_template_callback($templates){ |
| 56 |
$templates['ultp_page_template'] = __('PostX Template', 'ultimate-post'); |
| 57 |
return $templates; |
| 58 |
} |
| 59 |
} |