PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.2
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.2
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / includes / mlsimport-enum-labels.php

mlsimport-enum-labels.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.2, at includes/mlsimport-enum-labels.php

51 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Enum option label resolution for Import Task filter dropdowns.
4 *
5 * The Import Task metabox builds its City / CountyOrParish / PropertyType
6 * selects from the MLS enum lists saved in the `mlsimport_mls_metadata_mls_enums`
7 * option. The option VALUE submitted by the form is always the enum KEY — that
8 * is the value the SaaS URL builder puts into the OData filter. The LABEL the
9 * user sees comes from this helper.
10 *
11 * For every classic MLS the enum lists are name=>name ("Dallas" => "Dallas"),
12 * so the label equals the key and nothing changes visually. Code=>name
13 * providers — Centris (mls_id 9001) stores its City list as
14 * "839" => "Montréal" because listings carry only CityOrTownshipKey — get the
15 * human name as the label while the form keeps submitting the code.
16 *
17 * Kept as a standalone, WordPress-free file so the rule is unit-testable
18 * (tests/EnumOptionLabelTest.php) without loading the admin monolith.
19 *
20 * @package Mlsimport
21 * @subpackage Mlsimport/includes
22 */
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit;
26 }
27
28 /**
29 * Resolve the display label for one enum dropdown option.
30 *
31 * Step by step:
32 * 1. Look the key up in the enum map (key => label) saved for the MLS.
33 * 2. If the map holds a non-empty string label, show that.
34 * 3. Otherwise fall back to the key itself, so an incomplete or name=>name
35 * map can never blank an option.
36 *
37 * @param string $select_key The enum key used as the option value.
38 * @param array $enum_map The enum list for this field (key => label).
39 * @return string The label to render for the option.
40 */
41 function mlsimport_enum_option_label( $select_key, $enum_map ) {
42 if ( is_array( $enum_map ) && isset( $enum_map[ $select_key ] ) ) {
43 $label = $enum_map[ $select_key ];
44 if ( is_string( $label ) && '' !== $label ) {
45 return $label;
46 }
47 }
48
49 return (string) $select_key;
50 }
51