| 1 |
<?php |
| 2 |
/** |
| 3 |
* Standalone (theme_id 990) template loader. |
| 4 |
* |
| 5 |
* Resolves a template name to the active theme's mlsimport/ override (child then |
| 6 |
* parent theme, via locate_template) if present, else the plugin's bundled |
| 7 |
* templates/ directory — the WooCommerce override pattern, so any theme can |
| 8 |
* restyle the front-end without editing the plugin. |
| 9 |
* |
| 10 |
* @package Mlsimport |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Resolves standalone front-end templates, theme-overridable. |
| 19 |
*/ |
| 20 |
class Mlsimport_Standalone_Template { |
| 21 |
|
| 22 |
/** |
| 23 |
* Absolute path to the template to use for $name. |
| 24 |
* |
| 25 |
* @param string $name Template filename (e.g. 'card.php' or 'parts/map.php'). |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public static function locate( string $name ): string { |
| 29 |
// Normalize to a relative name (a leading slash would break the concatenation). |
| 30 |
$name = ltrim( $name, '/' ); |
| 31 |
/** Filter the template filename before lookup. @since 6.3 */ |
| 32 |
$name = (string) apply_filters( 'mlsimport_template_name', $name ); |
| 33 |
/** Filter the theme override sub-directory. @since 6.3 */ |
| 34 |
$subdir = (string) apply_filters( 'mlsimport_template_subdir', 'mlsimport/' ); |
| 35 |
|
| 36 |
// Prefer the active theme's mlsimport/ override (child then parent); if the |
| 37 |
// theme ships none, fall back to the plugin's bundled templates/ copy. |
| 38 |
$override = locate_template( array( $subdir . $name ) ); |
| 39 |
$path = ( '' !== $override ) ? $override : self::default_dir() . $name; |
| 40 |
|
| 41 |
/** Filter the resolved template path (full override). @since 6.3 */ |
| 42 |
return (string) apply_filters( 'mlsimport_locate_template', $path, $name, $subdir ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* The plugin's bundled templates directory (with trailing slash). |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public static function default_dir(): string { |
| 51 |
return dirname( __DIR__, 2 ) . '/templates/'; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* get_header() that stays silent when the active theme has no header.php. |
| 57 |
* |
| 58 |
* WordPress 6.x emits a deprecation notice when get_header() runs against a |
| 59 |
* theme without header.php; bundled standalone templates call this instead so a |
| 60 |
* header-less theme doesn't fill the log with notices. |
| 61 |
* |
| 62 |
* @param string|null $name Optional specialised header name. |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
function mlsimport_get_header( $name = null ): void { |
| 66 |
// Only call get_header() when the theme actually provides a header.php. |
| 67 |
if ( '' !== locate_template( 'header.php' ) ) { |
| 68 |
get_header( $name ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* get_footer() that stays silent when the active theme has no footer.php. |
| 74 |
* |
| 75 |
* @param string|null $name Optional specialised footer name. |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
function mlsimport_get_footer( $name = null ): void { |
| 79 |
// Only call get_footer() when the theme actually provides a footer.php. |
| 80 |
if ( '' !== locate_template( 'footer.php' ) ) { |
| 81 |
get_footer( $name ); |
| 82 |
} |
| 83 |
} |
| 84 |
|