| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
/** |
| 6 |
* Template Loader |
| 7 |
* |
| 8 |
* @class PH_Template_Loader |
| 9 |
* @version 1.0.0 |
| 10 |
* @package PropertyHive/Classes |
| 11 |
* @category Class |
| 12 |
* @author PropertyHive |
| 13 |
*/ |
| 14 |
class PH_Template_Loader { |
| 15 |
|
| 16 |
/** |
| 17 |
* Constructor |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
add_filter( 'template_include', array( $this, 'template_loader' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Load a template. |
| 25 |
* |
| 26 |
* Handles template usage so that we can use our own templates instead of the themes. |
| 27 |
* |
| 28 |
* Templates are in the 'templates' folder. propertyhive looks for theme |
| 29 |
* overrides in /theme/propertyhive/ by default |
| 30 |
* |
| 31 |
* For beginners, it also looks for a propertyhive.php template first. If the user adds |
| 32 |
* this to the theme (containing a propertyhive() inside) this will be used for all |
| 33 |
* propertyhive templates. |
| 34 |
* |
| 35 |
* @param mixed $template |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function template_loader( $template ) { |
| 39 |
|
| 40 |
$find = array( 'propertyhive.php' ); |
| 41 |
$file = ''; |
| 42 |
|
| 43 |
if ( is_single() && get_post_type() == 'property' ) { |
| 44 |
|
| 45 |
$file = 'single-property.php'; |
| 46 |
$find[] = $file; |
| 47 |
$find[] = PH_TEMPLATE_PATH . $file; |
| 48 |
|
| 49 |
|
| 50 |
} elseif ( is_post_type_archive( 'property' ) || is_page( ph_get_page_id( 'search_results' ) ) ) { |
| 51 |
|
| 52 |
$file = 'archive-property.php'; |
| 53 |
$find[] = $file; |
| 54 |
$find[] = PH_TEMPLATE_PATH . $file; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
if ( $file ) { |
| 59 |
$template = locate_template( array_unique($find) ); |
| 60 |
if ( ! $template ) |
| 61 |
$template = PH()->plugin_path() . '/templates/' . $file; |
| 62 |
} |
| 63 |
|
| 64 |
$template = apply_filters( 'propertyhive_loaded_template', $template ); |
| 65 |
|
| 66 |
return $template; |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
new PH_Template_Loader(); |