| 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 |
add_filter( 'theme_page_templates', array( $this, 'add_template_callback' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Include Template File |
| 29 |
* |
| 30 |
* @since v.1.0.0 |
| 31 |
* @param STRING | Attachment |
| 32 |
* @return STRING | Template File Path |
| 33 |
*/ |
| 34 |
public function set_template_callback( $template ) { |
| 35 |
if ( is_singular() ) { |
| 36 |
global $post; |
| 37 |
if ( get_post_meta( $post->ID, '_wp_page_template', true ) === 'ultp_page_template' ) { |
| 38 |
$template = ULTP_PATH . 'classes/template-without-title.php'; |
| 39 |
} |
| 40 |
} |
| 41 |
return $template; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Add A Page Template |
| 46 |
* |
| 47 |
* @since v.1.0.0 |
| 48 |
* @param ARRAY | Page Template List |
| 49 |
* @return ARRAY | Page Template List as Array |
| 50 |
*/ |
| 51 |
public function add_template_callback( $templates ) { |
| 52 |
$templates['ultp_page_template'] = __( 'PostX Template (Without Title)', 'ultimate-post' ); |
| 53 |
return $templates; |
| 54 |
} |
| 55 |
} |