| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | function epl_get_core_post_types() { |
| 23: | return apply_filters( 'epl_core_post_types', array( 'rural', 'property', 'rental', 'land', 'commercial', 'commercial_land', 'business' ) ); |
| 24: | } |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | function epl_get_core_sales_post_types() { |
| 32: | return apply_filters( 'epl_core_sales_post_types', array( 'rural', 'property', 'land', 'commercial', 'commercial_land', 'business' ) ); |
| 33: | } |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | function epl_get_core_rental_post_types() { |
| 41: | return apply_filters( 'epl_core_rental_post_types', array( 'rental' ) ); |
| 42: | } |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | function epl_all_post_types() { |
| 50: | $epl_posts = epl_get_active_post_types(); |
| 51: | $epl_posts = array_keys( $epl_posts ); |
| 52: | return apply_filters( 'epl_additional_post_types', $epl_posts ); |
| 53: | } |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | function is_epl_core_post( $type = null ) { |
| 64: | $type = is_null( $type ) ? get_post_type() : $type; |
| 65: | return in_array( $type, epl_get_core_post_types(), true ); |
| 66: | } |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | function is_epl_sales_post( $type = null ) { |
| 77: | $type = is_null( $type ) ? get_post_type() : $type; |
| 78: | return in_array( $type, epl_get_core_sales_post_types(), true ); |
| 79: | } |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | function is_epl_rental_post( $type = null ) { |
| 90: | $type = is_null( $type ) ? get_post_type() : $type; |
| 91: | return in_array( $type, epl_get_core_rental_post_types(), true ); |
| 92: | } |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | function is_epl_post( $type = null ) { |
| 103: | $all_types = epl_all_post_types(); |
| 104: | if ( empty( $all_types ) ) { |
| 105: | return false; |
| 106: | } |
| 107: | |
| 108: | $type = null === $type ? get_post_type() : $type; |
| 109: | return in_array( $type, epl_all_post_types(), true ); |
| 110: | } |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | function is_epl_post_single() { |
| 118: | |
| 119: | $all_types = epl_all_post_types(); |
| 120: | if ( empty( $all_types ) ) { |
| 121: | return false; |
| 122: | } |
| 123: | |
| 124: | return is_singular( epl_all_post_types() ); |
| 125: | } |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | function is_epl_post_type( $type ) { |
| 136: | |
| 137: | $all_types = epl_all_post_types(); |
| 138: | if ( empty( $all_types ) ) { |
| 139: | return false; |
| 140: | } |
| 141: | |
| 142: | return ( in_array( $type, epl_all_post_types(), true ) && get_post_type() === $type ); |
| 143: | } |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | function is_epl_post_archive() { |
| 151: | |
| 152: | $all_types = epl_all_post_types(); |
| 153: | if ( empty( $all_types ) ) { |
| 154: | return false; |
| 155: | } |
| 156: | |
| 157: | return is_post_type_archive( epl_all_post_types() ); |
| 158: | } |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | function epl_listing_has_secondary_author() { |
| 166: | return epl_listing_has_secondary_agent(); |
| 167: | } |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | function epl_listing_has_secondary_agent() { |
| 175: | return epl_listing_is_agent_available( 'property_second_agent' ); |
| 176: | } |
| 177: | |
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: | |
| 183: | function epl_listing_has_third_agent() { |
| 184: | return epl_listing_is_agent_available( 'property_third_agent' ); |
| 185: | } |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: | function epl_listing_has_fourth_agent() { |
| 193: | return epl_listing_is_agent_available( 'property_fourth_agent' ); |
| 194: | } |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | |
| 203: | |
| 204: | |
| 205: | function epl_listing_is_agent_available( $agent_key = 'property_second_agent' ) { |
| 206: | $exists = false; |
| 207: | $agent = get_property_meta( $agent_key ); |
| 208: | if ( ! empty( $agent ) ) { |
| 209: | $agent_author = get_user_by( 'login', sanitize_user( $agent ) ); |
| 210: | if ( false !== $agent_author ) { |
| 211: | $exists = $agent_author->ID; |
| 212: | } |
| 213: | } |
| 214: | return $exists; |
| 215: | } |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: | function epl_listing_has_primary_agent() { |
| 223: | $exists = false; |
| 224: | $property_agent = get_property_meta( 'property_agent' ); |
| 225: | if ( ! empty( $property_agent ) ) { |
| 226: | $author = get_user_by( 'login', sanitize_user( $property_agent ) ); |
| 227: | if ( false !== $author ) { |
| 228: | $exists = $author->ID; |
| 229: | } |
| 230: | } |
| 231: | return $exists; |
| 232: | } |
| 233: | |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | |
| 244: | |
| 245: | |
| 246: | |
| 247: | function epl_listing_has_any_meta( $keys = array(), $respect_show = false ) { |
| 248: | global $property; |
| 249: | |
| 250: | if ( ! $property instanceof EPL_Property_Meta ) { |
| 251: | return false; |
| 252: | } |
| 253: | |
| 254: | foreach ( (array) $keys as $key ) { |
| 255: | if ( $respect_show && ! apply_filters( 'epl_show_' . $key, true ) ) { |
| 256: | continue; |
| 257: | } |
| 258: | |
| 259: | $value = $property->get_property_meta( $key ); |
| 260: | |
| 261: | if ( is_array( $value ) ) { |
| 262: | $value = isset( $value['image_url_or_path'] ) ? $value['image_url_or_path'] : ''; |
| 263: | } |
| 264: | |
| 265: | if ( is_string( $value ) ) { |
| 266: | $value = trim( $value ); |
| 267: | } |
| 268: | |
| 269: | if ( ! empty( $value ) ) { |
| 270: | return true; |
| 271: | } |
| 272: | } |
| 273: | |
| 274: | return false; |
| 275: | } |
| 276: | |
| 277: | |
| 278: | |
| 279: | |
| 280: | |
| 281: | |
| 282: | |
| 283: | |
| 284: | |
| 285: | |
| 286: | function epl_listing_has_floor_plans() { |
| 287: | $keys = apply_filters( 'epl_floorplan_keys', array( 'property_floorplan', 'property_floorplan_2' ) ); |
| 288: | |
| 289: | return (bool) apply_filters( 'epl_listing_has_floor_plans', epl_listing_has_any_meta( $keys ) ); |
| 290: | } |
| 291: | |
| 292: | |
| 293: | |
| 294: | |
| 295: | |
| 296: | |
| 297: | |
| 298: | |
| 299: | function epl_listing_has_video() { |
| 300: | return (bool) apply_filters( 'epl_listing_has_video', epl_listing_has_any_meta( array( 'property_video_url' ) ) ); |
| 301: | } |
| 302: | |
| 303: | |
| 304: | |
| 305: | |
| 306: | |
| 307: | |
| 308: | |
| 309: | |
| 310: | |
| 311: | |
| 312: | function epl_listing_has_inspection_times() { |
| 313: | global $property; |
| 314: | |
| 315: | $has = false; |
| 316: | |
| 317: | if ( $property instanceof EPL_Property_Meta ) { |
| 318: | $times = $property->get_property_inspection_times(); |
| 319: | $has = is_string( $times ) && '' !== trim( wp_strip_all_tags( $times ) ); |
| 320: | } |
| 321: | |
| 322: | return (bool) apply_filters( 'epl_listing_has_inspection_times', $has ); |
| 323: | } |
| 324: | |
| 325: | |
| 326: | |
| 327: | |
| 328: | |
| 329: | |
| 330: | |
| 331: | |
| 332: | function epl_listing_has_auction_date() { |
| 333: | global $property; |
| 334: | |
| 335: | $has = false; |
| 336: | |
| 337: | if ( $property instanceof EPL_Property_Meta ) { |
| 338: | $auction = $property->get_property_auction(); |
| 339: | $has = is_string( $auction ) && '' !== trim( $auction ); |
| 340: | } |
| 341: | |
| 342: | return (bool) apply_filters( 'epl_listing_has_auction_date', $has ); |
| 343: | } |
| 344: | |
| 345: | |
| 346: | |
| 347: | |
| 348: | |
| 349: | |
| 350: | |
| 351: | |
| 352: | |
| 353: | |
| 354: | |
| 355: | |
| 356: | function epl_listing_has_links() { |
| 357: | $keys = array_merge( |
| 358: | (array) apply_filters( 'epl_external_link_keys', array( 'property_external_link', 'property_external_link_2', 'property_external_link_3' ) ), |
| 359: | (array) apply_filters( 'epl_floorplan_keys', array( 'property_floorplan', 'property_floorplan_2' ) ), |
| 360: | (array) apply_filters( 'epl_mini_web_keys', array( 'property_com_mini_web', 'property_com_mini_web_2', 'property_com_mini_web_3' ) ), |
| 361: | (array) apply_filters( 'epl_energy_certificate_keys', array( 'property_energy_certificate' ) ), |
| 362: | array( 'property_video_url' ) |
| 363: | ); |
| 364: | |
| 365: | return (bool) apply_filters( 'epl_listing_has_links', epl_listing_has_any_meta( $keys, true ) ); |
| 366: | } |
| 367: | |