| 1 |
<?php |
| 2 |
namespace ULTP; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Templates{ |
| 7 |
public function __construct(){ |
| 8 |
add_filter( 'template_include', array($this, 'set_template_callback') ); |
| 9 |
$post_types = get_post_types(); |
| 10 |
if( !empty($post_types) ){ |
| 11 |
foreach ($post_types as $post_type){ |
| 12 |
add_filter( "theme_{$post_type}_templates", array( $this, 'add_template_callback' ) ); |
| 13 |
} |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
public function set_template_callback($template){ |
| 18 |
if ( is_singular() ) { |
| 19 |
if ( get_post_meta( get_the_ID(), '_wp_page_template', true ) === 'ultp_page_template' ) { |
| 20 |
$template = ULTP_PATH . 'classes/template-without-title.php'; |
| 21 |
} |
| 22 |
} |
| 23 |
return $template; |
| 24 |
} |
| 25 |
|
| 26 |
public function add_template_callback($templates){ |
| 27 |
$templates['ultp_page_template'] = __('Gutenberg Post Blocks Template', 'ultimate-post'); |
| 28 |
return $templates; |
| 29 |
} |
| 30 |
} |