| 1 |
<?php |
| 2 |
/** |
| 3 |
* Single Property Material Information |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @package PropertyHive/Templates |
| 7 |
* @version 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 11 |
|
| 12 |
global $post, $property; |
| 13 |
|
| 14 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 15 |
$material_information = $property->get_material_information(); |
| 16 |
|
| 17 |
if ( empty($material_information) ) |
| 18 |
{ |
| 19 |
return; |
| 20 |
} |
| 21 |
// Built-in keys use literal messages so translation tools can discover every label. |
| 22 |
$propertyhive_material_labels = array( |
| 23 |
'utilities' => __( 'Utilities', 'propertyhive' ), |
| 24 |
'accessibility' => __( 'Accessibility', 'propertyhive' ), |
| 25 |
'restrictions' => __( 'Restrictions', 'propertyhive' ), |
| 26 |
'rights' => __( 'Rights', 'propertyhive' ), |
| 27 |
'flood_risk' => __( 'Flood Risk', 'propertyhive' ), |
| 28 |
'electricity' => __( 'Electricity', 'propertyhive' ), |
| 29 |
'water' => __( 'Water', 'propertyhive' ), |
| 30 |
'heating' => __( 'Heating', 'propertyhive' ), |
| 31 |
'broadband' => __( 'Broadband', 'propertyhive' ), |
| 32 |
'sewerage' => __( 'Sewerage', 'propertyhive' ), |
| 33 |
'flooded_in_last_five_years' => __( 'Flooded In Last Five Years', 'propertyhive' ), |
| 34 |
'flood_source' => __( 'Flood Source', 'propertyhive' ), |
| 35 |
'flood_defences' => __( 'Flood Defences', 'propertyhive' ), |
| 36 |
); |
| 37 |
$propertyhive_material_label = static function ( $key ) use ( $propertyhive_material_labels ) { |
| 38 |
if ( isset( $propertyhive_material_labels[ $key ] ) ) { |
| 39 |
return $propertyhive_material_labels[ $key ]; |
| 40 |
} |
| 41 |
// Preserve translations registered by extensions for their own material-information keys. |
| 42 |
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText -- Extension-defined labels have no built-in literal; preserve the existing translation contract. |
| 43 |
return __( ucwords( str_replace( '_', ' ', $key ) ), 'propertyhive' ); |
| 44 |
}; |
| 45 |
?> |
| 46 |
<div class="property-material-information" style="min-width:400px"> |
| 47 |
|
| 48 |
<h2><?php echo esc_html( __( 'Utilities & More', 'propertyhive' ) ); ?></h2> |
| 49 |
|
| 50 |
<?php do_action( 'propertyhive_property_material_information_start' ); ?> |
| 51 |
|
| 52 |
<?php |
| 53 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 54 |
foreach ( $material_information as $key => $value ) |
| 55 |
{ |
| 56 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable. |
| 57 |
$label = $propertyhive_material_label( $key ); |
| 58 |
echo '<h4>' . esc_html( $label ) . '</h4>'; |
| 59 |
|
| 60 |
if ( is_array($value) && !empty($value) ) |
| 61 |
{ |
| 62 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 63 |
foreach ( $value as $subkey => $subvalue ) |
| 64 |
{ |
| 65 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable. |
| 66 |
$label = $propertyhive_material_label( $subkey ); |
| 67 |
|
| 68 |
echo '<strong>' . esc_html( $label ) . ':</strong> ' . esc_html($subvalue) . '<br>'; |
| 69 |
} |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
echo '<strong>' . esc_html( $label ) . ':</strong> ' . esc_html($value) . '<br>'; |
| 74 |
} |
| 75 |
} |
| 76 |
?> |
| 77 |
|
| 78 |
<?php do_action( 'propertyhive_property_material_information_end' ); ?> |
| 79 |
|
| 80 |
</div> |