| 1 |
<?php |
| 2 |
/** |
| 3 |
* Standalone (theme_id 990) single/archive template routing (M6). |
| 4 |
* |
| 5 |
* Routes single + archive views of mlsimport_property to the plugin's bundled |
| 6 |
* (theme-overridable) templates, so the listing detail page works on any theme. |
| 7 |
* |
| 8 |
* @package Mlsimport |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
require_once __DIR__ . '/class-mlsimport-standalone-template.php'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Swaps in the standalone single/archive templates via template_include. |
| 19 |
*/ |
| 20 |
class Mlsimport_Standalone_Single { |
| 21 |
|
| 22 |
/** |
| 23 |
* Use a bundled template for standalone single/archive views (template_include). |
| 24 |
* |
| 25 |
* @param string $template The template WordPress resolved. |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public static function template_include( $template ) { |
| 29 |
/** Filter the standalone template routing decision. @since 6.3 */ |
| 30 |
return apply_filters( 'mlsimport_template_include', self::resolve( $template ), $template ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Resolve the bundled template for the current standalone view, or the |
| 35 |
* original template when this isn't a standalone view. |
| 36 |
* |
| 37 |
* @param string $template The template WordPress resolved. |
| 38 |
* @return string |
| 39 |
*/ |
| 40 |
private static function resolve( $template ) { |
| 41 |
// Single property detail page -> bundled single-property template. |
| 42 |
if ( is_singular( 'mlsimport_property' ) ) { |
| 43 |
$located = Mlsimport_Standalone_Template::locate( 'single-mlsimport-property.php' ); |
| 44 |
if ( file_exists( $located ) ) { |
| 45 |
return $located; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// Property archive OR any of the plugin's property taxonomy archives. |
| 50 |
if ( is_post_type_archive( 'mlsimport_property' ) || is_tax( Mlsimport_Standalone_Cpt::taxonomy_slugs() ) ) { |
| 51 |
$located = Mlsimport_Standalone_Template::locate( 'archive-mlsimport-property.php' ); |
| 52 |
if ( file_exists( $located ) ) { |
| 53 |
return $located; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// Single agent profile page -> bundled single-agent template. |
| 58 |
if ( is_singular( 'mlsimport_agent' ) ) { |
| 59 |
$located = Mlsimport_Standalone_Template::locate( 'single-mlsimport-agent.php' ); |
| 60 |
if ( file_exists( $located ) ) { |
| 61 |
return $located; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// Agent archive (directory) -> bundled agent-archive template. |
| 66 |
if ( is_post_type_archive( 'mlsimport_agent' ) ) { |
| 67 |
$located = Mlsimport_Standalone_Template::locate( 'archive-mlsimport-agent.php' ); |
| 68 |
if ( file_exists( $located ) ) { |
| 69 |
return $located; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
// Not a standalone view (or the bundled file is missing): leave WP's choice. |
| 74 |
return $template; |
| 75 |
} |
| 76 |
} |
| 77 |
|