PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.1
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-status-taxonomy.php

mlsimport-status-taxonomy.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at includes/mlsimport-status-taxonomy.php

77 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pure resolver for the taxonomy that holds a listing's MLS status.
4 *
5 * No WordPress calls — safe to unit-test in isolation.
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Return the taxonomy that holds a listing's MLS status.
14 *
15 * Honors the user's StandardStatus field mapping (the global
16 * mls-fields-map-taxonomy array) and falls back to the theme default when
17 * StandardStatus is not mapped.
18 *
19 * @param mixed $taxonomy_map The mls-fields-map-taxonomy array (anything else is treated as unmapped).
20 * @param string $default_taxonomy The theme's default status taxonomy.
21 * @return string
22 */
23 function mlsimport_status_taxonomy( $taxonomy_map, $default_taxonomy ) {
24 // Honor an explicit StandardStatus remap when the map array supplies one.
25 if ( is_array( $taxonomy_map ) && isset( $taxonomy_map['StandardStatus'] ) ) {
26 $mapped = trim( (string) $taxonomy_map['StandardStatus'] );
27 // A non-empty mapping wins over the theme default.
28 if ( '' !== $mapped ) {
29 return $mapped;
30 }
31 }
32
33 // Unmapped (or blank) -> fall back to the theme's default status taxonomy.
34 return $default_taxonomy;
35 }
36
37 /**
38 * Read the MLS status stored on a property, normalized for comparison.
39 *
40 * Each mode keeps status somewhere else, so the property's OWN post type picks
41 * the source — not whichever theme happens to be active. Standalone (990)
42 * listings are `mlsimport_property` and carry their status in the
43 * mlsimport_status taxonomy (see class-mlsimport-standalone-reso-map.php, which
44 * writes StandardStatus to `tax:mlsimport_status`); reading them through the
45 * active theme's taxonomy returns '' and makes reconciliation delete every
46 * listing it looks at.
47 *
48 * @param int $property_id The property post.
49 * @param mixed $taxonomy_map The mls-fields-map-taxonomy array (user remap of StandardStatus).
50 * @return string Normalized status, or '' when the property carries none.
51 */
52 function mlsimport_read_property_status( $property_id, $taxonomy_map = array() ) {
53 if ( 'mlsimport_property' === get_post_type( $property_id ) ) {
54 // Standalone (990).
55 $taxonomy = mlsimport_status_taxonomy( $taxonomy_map, 'mlsimport_status' );
56 } elseif ( post_type_exists( 'estate_property' ) ) {
57 // WPResidence / WpEstate.
58 $taxonomy = mlsimport_status_taxonomy( $taxonomy_map, 'property_status' );
59 } elseif ( post_type_exists( 'property' ) && taxonomy_exists( 'property_label' ) ) {
60 // Houzez.
61 $taxonomy = mlsimport_status_taxonomy( $taxonomy_map, 'property_label' );
62 } else {
63 // Real Homes keeps status in post meta, not a taxonomy.
64 return mlsimport_normalize_status_enum( get_post_meta( $property_id, 'inspiry_property_label', true ) );
65 }
66
67 // Read the status term(s) attached to the property in the resolved taxonomy.
68 $terms = get_the_terms( $property_id, $taxonomy );
69 // No terms (or an error) -> property carries no status.
70 if ( empty( $terms ) || ! is_array( $terms ) ) {
71 return '';
72 }
73
74 // Use the first term's name as the status, normalized for comparison.
75 return mlsimport_normalize_status_enum( $terms[0]->name );
76 }
77