| @@ -1,30 +1,61 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Template Action. | |
| 4 | + * | |
| 5 | + * @package ULTP\Templates | |
| 6 | + * @since v.1.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 2 | 9 | namespace ULTP; |
| 3 | 10 | |
| 4 | -defined('ABSPATH') || exit; | |
| 11 | +defined( 'ABSPATH' ) || exit; | |
| 5 | 12 | |
| 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 | - } | |
| 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 { | |
| 16 | 22 | |
| 17 | - public function set_template_callback($template){ | |
| 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 ) { | |
| 18 | 41 | 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 | - } | |
| 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 | + } | |
| 22 | 46 | } |
| 23 | 47 | return $template; |
| 24 | - } | |
| 48 | + } | |
| 25 | 49 | |
| 26 | - public function add_template_callback($templates){ | |
| 27 | - $templates['ultp_page_template'] = __('Gutenberg Post Blocks Template', 'ultimate-post'); | |
| 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' ); | |
| 28 | 59 | return $templates; |
| 29 | 60 | } |
| 30 | -} | |
| 61 | +} | |