| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template Action. |
| 4 |
* |
| 5 |
* @package ULTP\Templates |
| 6 |
* @since v.1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ULTP; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 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 { |
| 22 |
|
| 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 ) { |
| 41 |
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 |
} |
| 46 |
} |
| 47 |
return $template; |
| 48 |
} |
| 49 |
|
| 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' ); |
| 59 |
return $templates; |
| 60 |
} |
| 61 |
} |
| 62 |
|