| @@ -1,61 +1,30 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Template Action. | |
| 4 | - * | |
| 5 | - * @package ULTP\Templates | |
| 6 | - * @since v.1.0.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | 2 | namespace ULTP; |
| 10 | 3 | |
| 11 | -defined( 'ABSPATH' ) || exit; | |
| 4 | +defined('ABSPATH') || exit; | |
| 12 | 5 | |
| 13 | -/** | |
| 14 | - * Templates class. | |
| 15 | - * | |
| 16 | - * Handles template file inclusion and page template registration for Ultimate Post. | |
| 17 | - * | |
| 18 | - * @package ULTP\Templates | |
| 19 | - * @since v.1.0.0 | |
| 20 | - */ | |
| 21 | -class Templates { | |
| 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 | + } | |
| 22 | 16 | |
| 23 | - /** | |
| 24 | - * Setup class. | |
| 25 | - * | |
| 26 | - * @since v.1.0.0 | |
| 27 | - */ | |
| 28 | - public function __construct() { | |
| 29 | - add_filter( 'template_include', array( $this, 'set_template_callback' ) ); | |
| 30 | - add_filter( 'theme_page_templates', array( $this, 'add_template_callback' ) ); | |
| 31 | - } | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Include Template File | |
| 35 | - * | |
| 36 | - * @since v.1.0.0 | |
| 37 | - * @param STRING $template Template file path. | |
| 38 | - * @return STRING Template file path. | |
| 39 | - */ | |
| 40 | - public function set_template_callback( $template ) { | |
| 17 | + public function set_template_callback($template){ | |
| 41 | 18 | if ( is_singular() ) { |
| 42 | - global $post; | |
| 43 | - if ( get_post_meta( $post->ID, '_wp_page_template', true ) === 'ultp_page_template' ) { | |
| 44 | - $template = ULTP_PATH . 'classes/template-without-title.php'; | |
| 45 | - } | |
| 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 | + } | |
| 46 | 22 | } |
| 47 | 23 | return $template; |
| 48 | - } | |
| 24 | + } | |
| 49 | 25 | |
| 50 | - /** | |
| 51 | - * Add a page template to the theme. | |
| 52 | - * | |
| 53 | - * @since v.1.0.0 | |
| 54 | - * @param ARRAY $templates The page template list. | |
| 55 | - * @return ARRAY | |
| 56 | - */ | |
| 57 | - public function add_template_callback( $templates ) { | |
| 58 | - $templates['ultp_page_template'] = __( 'PostX Template (Without Title)', 'ultimate-post' ); | |
| 26 | + public function add_template_callback($templates){ | |
| 27 | + $templates['ultp_page_template'] = __('Gutenberg Post Blocks Template', 'ultimate-post'); | |
| 59 | 28 | return $templates; |
| 60 | 29 | } |
| 61 | -} | |
| 30 | +} | |