| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 11 | 11 | |
| 12 | 12 | global $post, $property; |
| 13 | 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. | |
| 14 | 15 | $material_information = $property->get_material_information(); |
| 15 | 16 | |
| 16 | 17 | if ( empty($material_information) ) |
| 17 | 18 | { |
| @@ -16,8 +17,32 @@ | ||
| 16 | 17 | if ( empty($material_information) ) |
| 17 | 18 | { |
| 18 | 19 | return; |
| 19 | 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 | +}; | |
| 20 | 45 | ?> |
| 21 | 46 | <div class="property-material-information" style="min-width:400px"> |
| 22 | 47 | |
| 23 | 48 | <h2><?php echo esc_html( __( 'Utilities & More', 'propertyhive' ) ); ?></h2> |
| @@ -24,29 +49,29 @@ | ||
| 24 | 49 | |
| 25 | 50 | <?php do_action( 'propertyhive_property_material_information_start' ); ?> |
| 26 | 51 | |
| 27 | 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. | |
| 28 | 54 | foreach ( $material_information as $key => $value ) |
| 29 | 55 | { |
| 30 | - $label = $key; | |
| 31 | - $label = str_replace("_", " ", $label); | |
| 32 | - $label = ucwords($label); | |
| 33 | - echo '<h4>' . esc_html( __( $label, 'propertyhive' ) ) . '</h4>'; | |
| 56 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable. | |
| 57 | + $label = $propertyhive_material_label( $key ); | |
| 58 | + echo '<h4>' . esc_html( $label ) . '</h4>'; | |
| 34 | 59 | |
| 35 | 60 | if ( is_array($value) && !empty($value) ) |
| 36 | 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. | |
| 37 | 63 | foreach ( $value as $subkey => $subvalue ) |
| 38 | 64 | { |
| 39 | - $label = $subkey; | |
| 40 | - $label = str_replace("_", " ", $label); | |
| 41 | - $label = ucwords($label); | |
| 65 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable. | |
| 66 | + $label = $propertyhive_material_label( $subkey ); | |
| 42 | 67 | |
| 43 | - echo '<strong>' . esc_html( __( $label, 'propertyhive' ) ) . ':</strong> ' . esc_html($subvalue) . '<br>'; | |
| 68 | + echo '<strong>' . esc_html( $label ) . ':</strong> ' . esc_html($subvalue) . '<br>'; | |
| 44 | 69 | } |
| 45 | 70 | } |
| 46 | 71 | else |
| 47 | 72 | { |
| 48 | - echo '<strong>' . esc_html( __( $label, 'propertyhive' ) ) . ':</strong> ' . esc_html($value) . '<br>'; | |
| 73 | + echo '<strong>' . esc_html( $label ) . ':</strong> ' . esc_html($value) . '<br>'; | |
| 49 | 74 | } |
| 50 | 75 | } |
| 51 | 76 | ?> |
| 52 | 77 | |