| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Form Functions |
| 4 |
* |
| 5 |
* Functions related to drawing forms on the frontend. |
| 6 |
* |
| 7 |
* @author PropertyHive |
| 8 |
* @category Core |
| 9 |
* @package PropertyHive/Functions |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* Main function for drawing entire property search form. We give the ability for an ID to be passed so differently formatted forms can be used |
| 15 |
* (ie. a homepage search form might be different from a search form on search results) |
| 16 |
* |
| 17 |
* @param string $id |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function ph_get_search_form( $id = 'default' ) { |
| 21 |
|
| 22 |
$form_controls = ph_get_search_form_fields(); |
| 23 |
|
| 24 |
$form_controls = apply_filters( 'propertyhive_search_form_fields_' . $id, $form_controls ); |
| 25 |
$form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls ); |
| 26 |
|
| 27 |
// We 100% need department so make sure it exists. If it doesn't, set a hidden field |
| 28 |
if ( !isset($form_controls['department']) ) |
| 29 |
{ |
| 30 |
$original_form_controls = ph_get_search_form_fields(); |
| 31 |
$original_department = $original_form_controls['department']; |
| 32 |
$original_department['type'] = 'hidden'; |
| 33 |
|
| 34 |
$form_controls['department'] = $original_department; |
| 35 |
} |
| 36 |
|
| 37 |
// append hidden order and view fields so these are maintained should a new search be performed |
| 38 |
foreach ( $_REQUEST as $key => $value ) |
| 39 |
{ |
| 40 |
if ( isset($form_controls[$key]) ) |
| 41 |
continue; |
| 42 |
|
| 43 |
if ( $key == 'officeID' && isset($form_controls['office']) ) |
| 44 |
continue; |
| 45 |
|
| 46 |
if ( $key == 'paged' ) |
| 47 |
continue; |
| 48 |
|
| 49 |
if ( |
| 50 |
( $key == 'minimum_price' || $key == 'maximum_price' ) && array_key_exists('price_slider', $form_controls) || |
| 51 |
( $key == 'minimum_rent' || $key == 'maximum_rent' ) && array_key_exists('rent_slider', $form_controls) || |
| 52 |
( $key == 'minimum_bedrooms' || $key == 'maximum_bedrooms' ) && array_key_exists('bedrooms_slider', $form_controls) |
| 53 |
) |
| 54 |
continue; |
| 55 |
|
| 56 |
// we've received a field that isn't a standard form control so let's store it in a hidden field so it's not lost |
| 57 |
if ( is_array($value) ) |
| 58 |
{ |
| 59 |
foreach ( $value as $i => $val ) |
| 60 |
{ |
| 61 |
$form_controls[$key . '-' . $i] = array('type' => 'hidden', 'name' => $key . '[]', 'value' => stripslashes( ph_clean( $val) )); |
| 62 |
} |
| 63 |
} |
| 64 |
else |
| 65 |
{ |
| 66 |
$form_controls[$key] = array('type' => 'hidden', 'value' => stripslashes( ph_clean( $value) )); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
$form_controls = apply_filters( 'propertyhive_search_form_fields_after_' . $id, $form_controls ); |
| 71 |
$form_controls = apply_filters( 'propertyhive_search_form_fields_after', $form_controls ); |
| 72 |
|
| 73 |
ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $id ) ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get default fields to be shown on search forms |
| 79 |
* |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
function ph_get_search_form_fields() |
| 83 |
{ |
| 84 |
$fields = array(); |
| 85 |
|
| 86 |
$departments = ph_get_departments(); |
| 87 |
|
| 88 |
$department_options = array(); |
| 89 |
$default_value = ''; |
| 90 |
|
| 91 |
foreach ( $departments as $key => $value ) |
| 92 |
{ |
| 93 |
if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' ) |
| 94 |
{ |
| 95 |
$department_options[$key] = $value; |
| 96 |
|
| 97 |
if ($default_value == '' && get_option( 'propertyhive_primary_department' ) == $key ) |
| 98 |
{ |
| 99 |
$default_value = $key; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
$sales_department_active = false; |
| 105 |
if ( array_key_exists('residential-sales', $departments) ) |
| 106 |
{ |
| 107 |
$sales_department_active = true; |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
$custom_departments = ph_get_custom_departments(); |
| 112 |
if ( !empty($custom_departments) ) |
| 113 |
{ |
| 114 |
foreach ( $custom_departments as $key => $department ) |
| 115 |
{ |
| 116 |
if ( isset($department['based_on']) && $department['based_on'] == 'residential-sales' ) |
| 117 |
{ |
| 118 |
$sales_department_active = true; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
$lettings_department_active = false; |
| 125 |
if ( array_key_exists('residential-lettings', $departments) ) |
| 126 |
{ |
| 127 |
$lettings_department_active = true; |
| 128 |
} |
| 129 |
else |
| 130 |
{ |
| 131 |
$custom_departments = ph_get_custom_departments(); |
| 132 |
if ( !empty($custom_departments) ) |
| 133 |
{ |
| 134 |
foreach ( $custom_departments as $key => $department ) |
| 135 |
{ |
| 136 |
if ( isset($department['based_on']) && $department['based_on'] == 'residential-lettings' ) |
| 137 |
{ |
| 138 |
$lettings_department_active = true; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
$commercial_department_active = false; |
| 145 |
if ( array_key_exists('commercial', $departments) ) |
| 146 |
{ |
| 147 |
$commercial_department_active = true; |
| 148 |
} |
| 149 |
else |
| 150 |
{ |
| 151 |
$custom_departments = ph_get_custom_departments(); |
| 152 |
if ( !empty($custom_departments) ) |
| 153 |
{ |
| 154 |
foreach ( $custom_departments as $key => $department ) |
| 155 |
{ |
| 156 |
if ( isset($department['based_on']) && $department['based_on'] == 'commercial' ) |
| 157 |
{ |
| 158 |
$commercial_department_active = true; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
$fields['department'] = array( |
| 165 |
'type' => 'radio', |
| 166 |
'options' => $department_options, |
| 167 |
'value' => $default_value |
| 168 |
); |
| 169 |
|
| 170 |
if ( $sales_department_active || $lettings_department_active ) |
| 171 |
{ |
| 172 |
if ( $sales_department_active ) |
| 173 |
{ |
| 174 |
$prices = array( |
| 175 |
'' => __( 'No preference', 'propertyhive' ), |
| 176 |
'100000' => '£100,000', |
| 177 |
'150000' => '£150,000', |
| 178 |
'200000' => '£200,000', |
| 179 |
'250000' => '£250,000', |
| 180 |
'300000' => '£300,000', |
| 181 |
'500000' => '£500,000', |
| 182 |
'750000' => '£750,000', |
| 183 |
'1000000' => '£1,000,000' |
| 184 |
); |
| 185 |
|
| 186 |
$fields['minimum_price'] = array( |
| 187 |
'type' => 'select', |
| 188 |
'show_label' => true, |
| 189 |
'label' => __( 'Min Price', 'propertyhive' ), |
| 190 |
'before' => '<div class="control control-minimum_price sales-only">', |
| 191 |
'options' => $prices |
| 192 |
); |
| 193 |
|
| 194 |
$fields['maximum_price'] = array( |
| 195 |
'type' => 'select', |
| 196 |
'show_label' => true, |
| 197 |
'label' => __( 'Max Price', 'propertyhive' ), |
| 198 |
'before' => '<div class="control control-maximum_price sales-only">', |
| 199 |
'options' => $prices |
| 200 |
); |
| 201 |
} |
| 202 |
|
| 203 |
if ( $lettings_department_active ) |
| 204 |
{ |
| 205 |
$prices = array( |
| 206 |
'' => __( 'No preference', 'propertyhive' ), |
| 207 |
'500' => '£500 PCM', |
| 208 |
'600' => '£600 PCM', |
| 209 |
'750' => '£750 PCM', |
| 210 |
'1000' => '£1000 PCM', |
| 211 |
'1250' => '£1250 PCM', |
| 212 |
'1500' => '£1500 PCM', |
| 213 |
'2000' => '£2000 PCM' |
| 214 |
); |
| 215 |
|
| 216 |
$fields['minimum_rent'] = array( |
| 217 |
'type' => 'select', |
| 218 |
'show_label' => true, |
| 219 |
'label' => __( 'Min Rent', 'propertyhive' ), |
| 220 |
'before' => '<div class="control control-minimum_rent lettings-only">', |
| 221 |
'options' => $prices |
| 222 |
); |
| 223 |
|
| 224 |
$fields['maximum_rent'] = array( |
| 225 |
'type' => 'select', |
| 226 |
'show_label' => true, |
| 227 |
'label' => __( 'Max Rent', 'propertyhive' ), |
| 228 |
'before' => '<div class="control control-maximum_rent lettings-only">', |
| 229 |
'options' => $prices |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
$fields['minimum_bedrooms'] = array( |
| 234 |
'type' => 'select', |
| 235 |
'show_label' => true, |
| 236 |
'label' => __( 'Min Beds', 'propertyhive' ), |
| 237 |
'before' => '<div class="control control-minimum_bedrooms residential-only">', |
| 238 |
'options' => array( '' => __( 'No preference', 'propertyhive' ), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5) |
| 239 |
); |
| 240 |
|
| 241 |
$fields['property_type'] = array( |
| 242 |
'type' => 'property_type', |
| 243 |
'show_label' => true, |
| 244 |
'before' => '<div class="control control-property_type residential-only">', |
| 245 |
'label' => __( 'Type', 'propertyhive' ), |
| 246 |
); |
| 247 |
} |
| 248 |
|
| 249 |
if ( $commercial_department_active ) |
| 250 |
{ |
| 251 |
$sizes = array( |
| 252 |
'' => __( 'No preference', 'propertyhive' ), |
| 253 |
'250' => '250 sq ft', |
| 254 |
'500' => '500 sq ft', |
| 255 |
'1000' => '1,000 sq ft', |
| 256 |
'2500' => '2,500 sq ft', |
| 257 |
'5000' => '5,000 sq ft', |
| 258 |
'10000' => '10,000 sq ft', |
| 259 |
'25000' => '25,000 sq ft', |
| 260 |
'50000' => '50,000 sq ft' |
| 261 |
); |
| 262 |
|
| 263 |
$fields['minimum_floor_area'] = array( |
| 264 |
'type' => 'select', |
| 265 |
'show_label' => true, |
| 266 |
'label' => __( 'Min Floor Area', 'propertyhive' ), |
| 267 |
'before' => '<div class="control control-minimum_floor_area commercial-only">', |
| 268 |
'options' => $sizes |
| 269 |
); |
| 270 |
|
| 271 |
$fields['maximum_floor_area'] = array( |
| 272 |
'type' => 'select', |
| 273 |
'show_label' => true, |
| 274 |
'label' => __( 'Max Floor Area', 'propertyhive' ), |
| 275 |
'before' => '<div class="control control-maximum_floor_area commercial-only">', |
| 276 |
'options' => $sizes |
| 277 |
); |
| 278 |
|
| 279 |
$fields['commercial_property_type'] = array( |
| 280 |
'type' => 'commercial_property_type', |
| 281 |
'show_label' => true, |
| 282 |
'before' => '<div class="control control-commercial_property_type commercial-only">', |
| 283 |
'label' => __( 'Type', 'propertyhive' ), |
| 284 |
); |
| 285 |
} |
| 286 |
|
| 287 |
return $fields; |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Main function for drawing property enquiry form. |
| 292 |
* |
| 293 |
* @param string $property_id |
| 294 |
* @return void |
| 295 |
*/ |
| 296 |
function propertyhive_enquiry_form( $property_id = '' ) |
| 297 |
{ |
| 298 |
global $post; |
| 299 |
|
| 300 |
$form_controls = ph_get_property_enquiry_form_fields( $property_id ); |
| 301 |
|
| 302 |
$form_controls = apply_filters( 'propertyhive_property_enquiry_form_fields', $form_controls, $property_id ); |
| 303 |
|
| 304 |
$form_controls['property_id'] = array( |
| 305 |
'type' => 'hidden', |
| 306 |
'value' => ( $property_id != '' ? $property_id : $post->ID ) |
| 307 |
); |
| 308 |
|
| 309 |
$utm_fields = array( 'utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign', 'gclid', 'fbclid' ); |
| 310 |
foreach ( $utm_fields as $utm_field ) |
| 311 |
{ |
| 312 |
$form_controls[$utm_field] = array( |
| 313 |
'type' => 'hidden', |
| 314 |
'value' =>'' |
| 315 |
); |
| 316 |
} |
| 317 |
|
| 318 |
if ( get_option( 'propertyhive_property_enquiry_form_disclaimer', '' ) != '' ) |
| 319 |
{ |
| 320 |
$disclaimer = get_option( 'propertyhive_property_enquiry_form_disclaimer', '' ); |
| 321 |
|
| 322 |
$form_controls['disclaimer'] = array( |
| 323 |
'type' => 'checkbox', |
| 324 |
'label' => $disclaimer, |
| 325 |
'label_style' => 'width:100%;', |
| 326 |
'required' => true |
| 327 |
); |
| 328 |
} |
| 329 |
|
| 330 |
ph_get_template( 'global/make-enquiry-form.php',array( 'form_controls' => $form_controls ) ); |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* Get default fields to be shown on search forms |
| 335 |
* |
| 336 |
* @return array |
| 337 |
*/ |
| 338 |
function ph_get_property_enquiry_form_fields( $property_id = '' ) |
| 339 |
{ |
| 340 |
global $post; |
| 341 |
|
| 342 |
$fields = array(); |
| 343 |
|
| 344 |
$fields['name'] = array( |
| 345 |
'type' => 'text', |
| 346 |
'label' => __( 'Full Name', 'propertyhive' ), |
| 347 |
'show_label' => true, |
| 348 |
'before' => '<div class="control control-name">', |
| 349 |
'required' => true |
| 350 |
); |
| 351 |
if ( is_user_logged_in() ) |
| 352 |
{ |
| 353 |
$current_user = wp_get_current_user(); |
| 354 |
|
| 355 |
$fields['name']['value'] = $current_user->display_name; |
| 356 |
} |
| 357 |
|
| 358 |
$fields['email_address'] = array( |
| 359 |
'type' => 'email', |
| 360 |
'label' => __( 'Email Address', 'propertyhive' ), |
| 361 |
'show_label' => true, |
| 362 |
'before' => '<div class="control control-email_address">', |
| 363 |
'required' => true |
| 364 |
); |
| 365 |
if ( is_user_logged_in() ) |
| 366 |
{ |
| 367 |
$current_user = wp_get_current_user(); |
| 368 |
|
| 369 |
$fields['email_address']['value'] = $current_user->user_email; |
| 370 |
} |
| 371 |
|
| 372 |
$fields['telephone_number'] = array( |
| 373 |
'type' => 'text', |
| 374 |
'label' => __( 'Number', 'propertyhive' ), |
| 375 |
'show_label' => true, |
| 376 |
'before' => '<div class="control control-telephone_number">', |
| 377 |
'required' => true |
| 378 |
); |
| 379 |
|
| 380 |
$fields['message'] = array( |
| 381 |
'type' => 'textarea', |
| 382 |
'label' => __( 'Message', 'propertyhive' ), |
| 383 |
'show_label' => true, |
| 384 |
'before' => '<div class="control control-message">', |
| 385 |
'required' => true |
| 386 |
); |
| 387 |
|
| 388 |
return $fields; |
| 389 |
} |
| 390 |
|
| 391 |
/** |
| 392 |
* Get default fields to be shown on applicant registration forms |
| 393 |
* |
| 394 |
* @return array |
| 395 |
*/ |
| 396 |
function ph_get_user_details_form_fields() |
| 397 |
{ |
| 398 |
global $post; |
| 399 |
|
| 400 |
if ( is_user_logged_in() ) |
| 401 |
{ |
| 402 |
$current_user = wp_get_current_user(); |
| 403 |
|
| 404 |
if ( $current_user instanceof WP_User ) |
| 405 |
{ |
| 406 |
$contact = new PH_Contact( '', $current_user->ID ); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
$fields = array(); |
| 411 |
|
| 412 |
$fields['name'] = array( |
| 413 |
'type' => 'text', |
| 414 |
'label' => __( 'Full Name', 'propertyhive' ), |
| 415 |
'required' => true |
| 416 |
); |
| 417 |
if ( is_user_logged_in() && $current_user instanceof WP_User ) |
| 418 |
{ |
| 419 |
$fields['name']['value'] = $current_user->display_name; |
| 420 |
} |
| 421 |
|
| 422 |
$fields['email_address'] = array( |
| 423 |
'type' => 'email', |
| 424 |
'label' => __( 'Email Address', 'propertyhive' ), |
| 425 |
'required' => true |
| 426 |
); |
| 427 |
if ( is_user_logged_in() && $current_user instanceof WP_User ) |
| 428 |
{ |
| 429 |
$fields['email_address']['value'] = $current_user->user_email; |
| 430 |
} |
| 431 |
|
| 432 |
$fields['telephone_number'] = array( |
| 433 |
'type' => 'text', |
| 434 |
'label' => __( 'Telephone Number', 'propertyhive' ), |
| 435 |
'required' => false |
| 436 |
); |
| 437 |
if ( is_user_logged_in() && $current_user instanceof WP_User ) |
| 438 |
{ |
| 439 |
$fields['telephone_number']['value'] = $contact->telephone_number; |
| 440 |
} |
| 441 |
|
| 442 |
if ( get_option( 'propertyhive_applicant_users', '' ) == 'yes' ) |
| 443 |
{ |
| 444 |
$fields['password'] = array( |
| 445 |
'type' => 'password', |
| 446 |
'label' => __( 'Password', 'propertyhive' ), |
| 447 |
'required' => true |
| 448 |
); |
| 449 |
|
| 450 |
$fields['password2'] = array( |
| 451 |
'type' => 'password', |
| 452 |
'label' => __( 'Confirm Password', 'propertyhive' ), |
| 453 |
'required' => true |
| 454 |
); |
| 455 |
} |
| 456 |
|
| 457 |
return $fields; |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Get default fields to be shown on applicant registration forms |
| 462 |
* |
| 463 |
* @return array |
| 464 |
*/ |
| 465 |
function ph_get_applicant_requirements_form_fields($applicant_profile = false) |
| 466 |
{ |
| 467 |
global $post; |
| 468 |
|
| 469 |
$fields = array(); |
| 470 |
|
| 471 |
$offices = array(); |
| 472 |
$value = ''; |
| 473 |
|
| 474 |
$args = array( |
| 475 |
'post_type' => 'office', |
| 476 |
'nopaging' => true, |
| 477 |
'orderby' => 'title', |
| 478 |
'order' => 'ASC' |
| 479 |
); |
| 480 |
|
| 481 |
$office_query = new WP_Query( $args ); |
| 482 |
|
| 483 |
if ( $office_query->have_posts() ) |
| 484 |
{ |
| 485 |
while ( $office_query->have_posts() ) |
| 486 |
{ |
| 487 |
$office_query->the_post(); |
| 488 |
|
| 489 |
$offices[get_the_ID()] = get_the_title(); |
| 490 |
|
| 491 |
if ( get_post_meta(get_the_ID(), 'primary', TRUE) == 1 ) |
| 492 |
{ |
| 493 |
$value = get_the_ID(); |
| 494 |
} |
| 495 |
} |
| 496 |
} |
| 497 |
wp_reset_postdata(); |
| 498 |
|
| 499 |
$fields['office_id'] = array( |
| 500 |
'type' => ( (count($offices) <= 1) ? 'hidden' : 'select' ), |
| 501 |
'label' => __( 'Office', 'propertyhive' ), |
| 502 |
'required' => false, |
| 503 |
'show_label' => true, |
| 504 |
'value' => $value, |
| 505 |
'options' => $offices |
| 506 |
); |
| 507 |
|
| 508 |
$value = ''; |
| 509 |
|
| 510 |
$ph_departments = ph_get_departments(); |
| 511 |
$departments = array(); |
| 512 |
|
| 513 |
$show_residential_fields = false; |
| 514 |
$show_commercial_fields = false; |
| 515 |
foreach ( $ph_departments as $key => $department ) |
| 516 |
{ |
| 517 |
if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' ) |
| 518 |
{ |
| 519 |
$departments[$key] = $department; |
| 520 |
if ($value == '' && (get_option( 'propertyhive_primary_department' ) == $key || get_option( 'propertyhive_primary_department' ) === FALSE) ) |
| 521 |
{ |
| 522 |
$value = $key; |
| 523 |
} |
| 524 |
|
| 525 |
if ( in_array($key, array('residential-sales', 'residential-lettings')) || in_array(ph_get_custom_department_based_on($key), array('residential-sales', 'residential-lettings')) ) |
| 526 |
{ |
| 527 |
$show_residential_fields = true; |
| 528 |
} |
| 529 |
|
| 530 |
if ( in_array($key, array('commercial')) || in_array(ph_get_custom_department_based_on($key), array('commercial')) ) |
| 531 |
{ |
| 532 |
$show_commercial_fields = true; |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
$fields['department'] = array( |
| 538 |
'type' => 'radio', |
| 539 |
'label' => __( 'Looking For', 'propertyhive' ), |
| 540 |
'required' => true, |
| 541 |
'show_label' => true, |
| 542 |
'value' => $value, |
| 543 |
'options' => $departments |
| 544 |
); |
| 545 |
if ( is_user_logged_in() && isset($applicant_profile['department']) ) |
| 546 |
{ |
| 547 |
$fields['department']['value'] = $applicant_profile['department']; |
| 548 |
} |
| 549 |
if ( count($departments) == 1 ) |
| 550 |
{ |
| 551 |
$fields['department']['type'] = 'hidden'; |
| 552 |
} |
| 553 |
|
| 554 |
if ( $show_residential_fields ) |
| 555 |
{ |
| 556 |
$fields['maximum_price'] = array( |
| 557 |
'type' => 'number', |
| 558 |
'label' => __( 'Maximum Price', 'propertyhive' ), |
| 559 |
'style' => 'max-width:150px;', |
| 560 |
'before' => '<div class="control control-minimum_price sales-only">', |
| 561 |
'required' => false |
| 562 |
); |
| 563 |
if ( is_user_logged_in() && isset($applicant_profile['max_price']) ) |
| 564 |
{ |
| 565 |
$fields['maximum_price']['value'] = $applicant_profile['max_price']; |
| 566 |
} |
| 567 |
|
| 568 |
$fields['maximum_rent'] = array( |
| 569 |
'type' => 'number', |
| 570 |
'label' => __( 'Maximum Rent', 'propertyhive' ) . ' (PCM)', |
| 571 |
'style' => 'max-width:150px;', |
| 572 |
'before' => '<div class="control control-minimum_price lettings-only">', |
| 573 |
'required' => false |
| 574 |
); |
| 575 |
if ( is_user_logged_in() && isset($applicant_profile['max_rent']) ) |
| 576 |
{ |
| 577 |
$fields['maximum_rent']['value'] = $applicant_profile['max_rent']; |
| 578 |
} |
| 579 |
|
| 580 |
$fields['minimum_bedrooms'] = array( |
| 581 |
'type' => 'number', |
| 582 |
'label' => __( 'Minimum Bedrooms', 'propertyhive' ), |
| 583 |
'style' => 'max-width:80px;', |
| 584 |
'before' => '<div class="control control-minimum_bedrooms residential-only">', |
| 585 |
'required' => false |
| 586 |
); |
| 587 |
if ( is_user_logged_in() && isset($applicant_profile['min_beds']) ) |
| 588 |
{ |
| 589 |
$fields['minimum_bedrooms']['value'] = $applicant_profile['min_beds']; |
| 590 |
} |
| 591 |
|
| 592 |
$args = array( |
| 593 |
'hide_empty' => false, |
| 594 |
'parent' => 0 |
| 595 |
); |
| 596 |
$terms = get_terms( 'property_type', $args ); |
| 597 |
|
| 598 |
$options = array(); |
| 599 |
|
| 600 |
$selected_value = ''; |
| 601 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 602 |
{ |
| 603 |
$options = array( '' => __( 'All Property Types', 'propertyhive' ) ); |
| 604 |
|
| 605 |
foreach ($terms as $term) |
| 606 |
{ |
| 607 |
$options[$term->term_id] = $term->name; |
| 608 |
|
| 609 |
$args = array( |
| 610 |
'hide_empty' => false, |
| 611 |
'parent' => $term->term_id |
| 612 |
); |
| 613 |
$subterms = get_terms( 'property_type', $args ); |
| 614 |
|
| 615 |
if ( !empty( $subterms ) && !is_wp_error( $subterms ) ) |
| 616 |
{ |
| 617 |
foreach ($subterms as $term) |
| 618 |
{ |
| 619 |
$options[$term->term_id] = '- ' . $term->name; |
| 620 |
} |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
if ( !empty($options) ) |
| 626 |
{ |
| 627 |
$fields['property_type'] = array( |
| 628 |
'type' => 'select', |
| 629 |
'label' => __( 'Property Type', 'propertyhive' ), |
| 630 |
'before' => '<div class="control control-property_type residential-only">', |
| 631 |
'required' => false, |
| 632 |
'multiselect' => true, |
| 633 |
'options' => $options, |
| 634 |
); |
| 635 |
|
| 636 |
if ( is_user_logged_in() && isset($applicant_profile['property_types']) && is_array($applicant_profile['property_types']) && !empty($applicant_profile['property_types']) ) |
| 637 |
{ |
| 638 |
$fields['property_type']['value'] = $applicant_profile['property_types']; |
| 639 |
} |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
if ( $show_commercial_fields ) |
| 644 |
{ |
| 645 |
$fields['available_as_sale'] = array( |
| 646 |
'type' => 'checkbox', |
| 647 |
'label' => __( 'For Sale', 'propertyhive' ), |
| 648 |
'before' => '<div class="control control-available_as_sale commercial-only">', |
| 649 |
'required' => false, |
| 650 |
); |
| 651 |
if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('sale', $applicant_profile['available_as']) ) |
| 652 |
{ |
| 653 |
$fields['available_as_sale']['checked'] = true; |
| 654 |
} |
| 655 |
|
| 656 |
$fields['available_as_rent'] = array( |
| 657 |
'type' => 'checkbox', |
| 658 |
'label' => __( 'To Rent', 'propertyhive' ), |
| 659 |
'before' => '<div class="control control-available_as_rent commercial-only">', |
| 660 |
'required' => false, |
| 661 |
); |
| 662 |
if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('rent', $applicant_profile['available_as']) ) |
| 663 |
{ |
| 664 |
$fields['available_as_rent']['checked'] = true; |
| 665 |
} |
| 666 |
|
| 667 |
$fields['minimum_floor_area'] = array( |
| 668 |
'type' => 'number', |
| 669 |
'label' => __( 'Min Floor Area (Sq Ft)', 'propertyhive' ), |
| 670 |
'style' => 'max-width:150px;', |
| 671 |
'before' => '<div class="control control-minimum_floor_area commercial-only">', |
| 672 |
'required' => false |
| 673 |
); |
| 674 |
if ( is_user_logged_in() && isset($applicant_profile['min_floor_area']) ) |
| 675 |
{ |
| 676 |
$fields['minimum_floor_area']['value'] = $applicant_profile['min_floor_area']; |
| 677 |
} |
| 678 |
|
| 679 |
$fields['maximum_floor_area'] = array( |
| 680 |
'type' => 'number', |
| 681 |
'label' => __( 'Max Floor Area (Sq Ft)', 'propertyhive' ), |
| 682 |
'style' => 'max-width:150px;', |
| 683 |
'before' => '<div class="control control-maximum_floor_area commercial-only">', |
| 684 |
'required' => false |
| 685 |
); |
| 686 |
if ( is_user_logged_in() && isset($applicant_profile['max_floor_area']) ) |
| 687 |
{ |
| 688 |
$fields['maximum_floor_area']['value'] = $applicant_profile['max_floor_area']; |
| 689 |
} |
| 690 |
|
| 691 |
$args = array( |
| 692 |
'hide_empty' => false, |
| 693 |
'parent' => 0 |
| 694 |
); |
| 695 |
$terms = get_terms( 'commercial_property_type', $args ); |
| 696 |
|
| 697 |
$options = array(); |
| 698 |
|
| 699 |
$selected_value = ''; |
| 700 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 701 |
{ |
| 702 |
$options = array( '' => __( 'All Property Types', 'propertyhive' ) ); |
| 703 |
|
| 704 |
foreach ($terms as $term) |
| 705 |
{ |
| 706 |
$options[$term->term_id] = $term->name; |
| 707 |
|
| 708 |
$args = array( |
| 709 |
'hide_empty' => false, |
| 710 |
'parent' => $term->term_id |
| 711 |
); |
| 712 |
$subterms = get_terms( 'commercial_property_type', $args ); |
| 713 |
|
| 714 |
if ( !empty( $subterms ) && !is_wp_error( $subterms ) ) |
| 715 |
{ |
| 716 |
foreach ($subterms as $term) |
| 717 |
{ |
| 718 |
$options[$term->term_id] = '- ' . $term->name; |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
if ( !empty($options) ) |
| 725 |
{ |
| 726 |
$fields['commercial_property_type'] = array( |
| 727 |
'type' => 'select', |
| 728 |
'label' => __( 'Property Type', 'propertyhive' ), |
| 729 |
'before' => '<div class="control control-commercial_property_type commercial-only">', |
| 730 |
'required' => false, |
| 731 |
'multiselect' => true, |
| 732 |
'options' => $options, |
| 733 |
); |
| 734 |
|
| 735 |
if ( is_user_logged_in() && isset($applicant_profile['commercial_property_types']) && is_array($applicant_profile['commercial_property_types']) && !empty($applicant_profile['commercial_property_types']) ) |
| 736 |
{ |
| 737 |
$fields['commercial_property_type']['value'] = $applicant_profile['commercial_property_types']; |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
if ( get_option('propertyhive_applicant_locations_type') != 'text' ) |
| 743 |
{ |
| 744 |
$args = array( |
| 745 |
'hide_empty' => false, |
| 746 |
'parent' => 0 |
| 747 |
); |
| 748 |
$terms = get_terms( 'location', $args ); |
| 749 |
|
| 750 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 751 |
{ |
| 752 |
$fields['location'] = array( |
| 753 |
'type' => 'location', |
| 754 |
'label' => __( 'Location', 'propertyhive' ), |
| 755 |
'blank_option' => __( 'All Locations', 'propertyhive' ), |
| 756 |
'required' => false, |
| 757 |
'multiselect' => true, |
| 758 |
); |
| 759 |
|
| 760 |
if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) ) |
| 761 |
{ |
| 762 |
$fields['location']['value'] = $applicant_profile['locations']; |
| 763 |
} |
| 764 |
} |
| 765 |
} |
| 766 |
else |
| 767 |
{ |
| 768 |
$fields['location_text'] = array( |
| 769 |
'type' => 'text', |
| 770 |
'label' => __( 'Location', 'propertyhive' ), |
| 771 |
'required' => false |
| 772 |
); |
| 773 |
|
| 774 |
if ( is_user_logged_in() && isset($applicant_profile['location_text']) && $applicant_profile['location_text'] != '' ) |
| 775 |
{ |
| 776 |
$fields['location_text']['value'] = $applicant_profile['location_text']; |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
$fields['additional_requirements'] = array( |
| 781 |
'type' => 'textarea', |
| 782 |
'label' => __( 'Additional Requirements', 'propertyhive' ), |
| 783 |
'required' => false |
| 784 |
); |
| 785 |
if ( is_user_logged_in() && isset($applicant_profile['notes']) ) |
| 786 |
{ |
| 787 |
$fields['additional_requirements']['value'] = $applicant_profile['notes']; |
| 788 |
} |
| 789 |
|
| 790 |
return $fields; |
| 791 |
} |
| 792 |
|
| 793 |
/** |
| 794 |
* Output individual field |
| 795 |
* |
| 796 |
* @return void |
| 797 |
*/ |
| 798 |
function ph_form_field( $key, $field ) |
| 799 |
{ |
| 800 |
global $post; |
| 801 |
|
| 802 |
$output = ''; |
| 803 |
|
| 804 |
switch ($field['type']) |
| 805 |
{ |
| 806 |
case "text": |
| 807 |
case "email": |
| 808 |
case "date": |
| 809 |
case "number": |
| 810 |
case "password": |
| 811 |
{ |
| 812 |
$field['id'] = isset( $field['id'] ) ? $field['id'] : $key; |
| 813 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 814 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 815 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 816 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 817 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 818 |
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' ); |
| 819 |
$field['required'] = isset( $field['required'] ) ? $field['required'] : false; |
| 820 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 821 |
|
| 822 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 823 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 824 |
{ |
| 825 |
$field['value'] = sanitize_text_field( wp_unslash( $_GET[$key] ) ); |
| 826 |
} |
| 827 |
else |
| 828 |
{ |
| 829 |
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) ) |
| 830 |
{ |
| 831 |
$value = get_post_meta( $post->ID, '_' . $key, true ); |
| 832 |
if ( $value != '' ) |
| 833 |
{ |
| 834 |
$field['value'] = $value; |
| 835 |
} |
| 836 |
} |
| 837 |
} |
| 838 |
|
| 839 |
$output .= $field['before']; |
| 840 |
|
| 841 |
if ($field['show_label']) |
| 842 |
{ |
| 843 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label']; |
| 844 |
if ($field['required']) |
| 845 |
{ |
| 846 |
$output .= '<span class="required"> *</span>'; |
| 847 |
} |
| 848 |
$output .= '</label>'; |
| 849 |
} |
| 850 |
|
| 851 |
$output .= '<input |
| 852 |
type="' . esc_attr( $field['type'] ) . '" |
| 853 |
name="' . esc_attr( $key ) . '" |
| 854 |
id="' . esc_attr( $field['id'] ) . '" |
| 855 |
value="' . esc_attr( $field['value'] ) . '" |
| 856 |
placeholder="' . esc_attr( $field['placeholder'] ) . '" |
| 857 |
class="' . esc_attr( $field['class'] ) . '" |
| 858 |
style="' . esc_attr( $field['style'] ) . '" |
| 859 |
' . ( ($field['required']) ? 'required' : '' ) . ' |
| 860 |
>'; |
| 861 |
|
| 862 |
$output .= $field['after']; |
| 863 |
|
| 864 |
break; |
| 865 |
} |
| 866 |
case "textarea": |
| 867 |
{ |
| 868 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 869 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 870 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 871 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 872 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 873 |
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 874 |
$field['required'] = isset( $field['required'] ) ? $field['required'] : false; |
| 875 |
|
| 876 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 877 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 878 |
{ |
| 879 |
$field['value'] = sanitize_textarea_field( wp_unslash( $_GET[$key] ) ); |
| 880 |
} |
| 881 |
else |
| 882 |
{ |
| 883 |
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) ) |
| 884 |
{ |
| 885 |
$value = get_post_meta( $post->ID, '_' . $key, true ); |
| 886 |
if ( $value != '' ) |
| 887 |
{ |
| 888 |
$field['value'] = $value; |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
|
| 893 |
$output .= $field['before']; |
| 894 |
|
| 895 |
if ($field['show_label']) |
| 896 |
{ |
| 897 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label']; |
| 898 |
if ($field['required']) |
| 899 |
{ |
| 900 |
$output .= '<span class="required"> *</span>'; |
| 901 |
} |
| 902 |
$output .= '</label>'; |
| 903 |
} |
| 904 |
|
| 905 |
$output .= '<textarea |
| 906 |
name="' . esc_attr( $key ) . '" |
| 907 |
id="' . esc_attr( $key ) . '" |
| 908 |
placeholder="' . esc_attr( $field['placeholder'] ) . '" |
| 909 |
class="' . esc_attr( $field['class'] ) . '" |
| 910 |
' . ( ($field['required']) ? 'required' : '' ) . ' |
| 911 |
>' . esc_attr( $field['value'] ) . '</textarea>'; |
| 912 |
|
| 913 |
$output .= $field['after']; |
| 914 |
|
| 915 |
break; |
| 916 |
} |
| 917 |
case "checkbox": |
| 918 |
{ |
| 919 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 920 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 921 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 922 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 923 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 924 |
$field['label_style'] = isset( $field['label_style'] ) ? $field['label_style'] : ''; |
| 925 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : 'yes'; |
| 926 |
$field['checked'] = isset( $field['checked'] ) ? $field['checked'] : false; |
| 927 |
if ( isset( $_GET[$key] ) && sanitize_text_field(wp_unslash($_GET[$key])) == $field['value'] ) |
| 928 |
{ |
| 929 |
$field['checked'] = true; |
| 930 |
} |
| 931 |
else |
| 932 |
{ |
| 933 |
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) ) |
| 934 |
{ |
| 935 |
$value = get_post_meta( $post->ID, '_' . $key, true ); |
| 936 |
if ( $value == 'yes' ) |
| 937 |
{ |
| 938 |
$field['checked'] = true; |
| 939 |
} |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
$output .= $field['before']; |
| 944 |
|
| 945 |
$output .= '<label style="' . esc_attr( $field['label_style'] ) . '"><input |
| 946 |
type="' . esc_attr( $field['type'] ) . '" |
| 947 |
name="' . esc_attr( $key ) . '" |
| 948 |
value="' . esc_attr( $field['value'] ) . '" |
| 949 |
class="' . esc_attr( $field['class'] ) . '" |
| 950 |
' . checked( $field['checked'], true, false ) . ' |
| 951 |
>'; |
| 952 |
if ($field['show_label']) |
| 953 |
{ |
| 954 |
$output .= ' <span>' . $field['label'] . '</span>'; |
| 955 |
} |
| 956 |
$output .= '</label>'; |
| 957 |
|
| 958 |
$output .= $field['after']; |
| 959 |
|
| 960 |
break; |
| 961 |
} |
| 962 |
case "radio": |
| 963 |
{ |
| 964 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 965 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 966 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 967 |
$field['before_option'] = isset( $field['before_option'] ) ? $field['before_option'] : '<label>'; |
| 968 |
$field['after_option'] = isset( $field['after_option'] ) ? $field['after_option'] : '</label>'; |
| 969 |
$field['before_input'] = isset( $field['before_input'] ) ? $field['before_input'] : ''; |
| 970 |
$field['after_input'] = isset( $field['after_input'] ) ? $field['after_input'] : ''; |
| 971 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false; |
| 972 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 973 |
$field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array(); |
| 974 |
|
| 975 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 976 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 977 |
{ |
| 978 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 979 |
} |
| 980 |
|
| 981 |
$output .= $field['before']; |
| 982 |
|
| 983 |
if ($field['show_label']) |
| 984 |
{ |
| 985 |
// get first option as 'for' |
| 986 |
$option_key = ''; |
| 987 |
foreach ( $field['options'] as $option_key => $value ) |
| 988 |
{ |
| 989 |
break; |
| 990 |
} |
| 991 |
$output .= '<label for="' . esc_attr( $key ) . '_' . esc_attr( $option_key ) . '">' . $field['label'] . '</label>'; |
| 992 |
} |
| 993 |
|
| 994 |
foreach ( $field['options'] as $option_key => $value ) |
| 995 |
{ |
| 996 |
$id = esc_attr( $key ) . '_' . esc_attr( $option_key ); |
| 997 |
$output .= str_replace("{id}", $id, $field['before_option']); |
| 998 |
$output .= str_replace("{id}", $id, $field['before_input']); |
| 999 |
$output .= '<input |
| 1000 |
type="' . esc_attr( $field['type'] ) . '" |
| 1001 |
name="' . esc_attr( $key ) . '" |
| 1002 |
id="' . $id . '" |
| 1003 |
value="' . esc_attr( $option_key ) . '" |
| 1004 |
class="' . esc_attr( $field['class'] ) . '" |
| 1005 |
' . checked( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . ' |
| 1006 |
>'; |
| 1007 |
$output .= str_replace("{id}", $id, $field['after_input']); |
| 1008 |
$output .= ' ' . esc_html( $value ); |
| 1009 |
$output .= str_replace("{id}", $id, $field['after_option']); |
| 1010 |
} |
| 1011 |
|
| 1012 |
$output .= $field['after']; |
| 1013 |
|
| 1014 |
break; |
| 1015 |
} |
| 1016 |
case "select": |
| 1017 |
{ |
| 1018 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 1019 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1020 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1021 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1022 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1023 |
$field['required'] = isset( $field['required'] ) ? $field['required'] : false; |
| 1024 |
$field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array(); |
| 1025 |
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false; |
| 1026 |
|
| 1027 |
if ( $field['multiselect'] ) |
| 1028 |
{ |
| 1029 |
wp_enqueue_script( 'multiselect' ); |
| 1030 |
} |
| 1031 |
|
| 1032 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1033 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1034 |
{ |
| 1035 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 1036 |
} |
| 1037 |
else |
| 1038 |
{ |
| 1039 |
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) ) |
| 1040 |
{ |
| 1041 |
$value = get_post_meta( $post->ID, '_' . $key, true ); |
| 1042 |
if ( $value != '' ) |
| 1043 |
{ |
| 1044 |
$field['value'] = $value; |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
$output .= $field['before']; |
| 1050 |
|
| 1051 |
if ($field['show_label']) |
| 1052 |
{ |
| 1053 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label']; |
| 1054 |
if ($field['required']) |
| 1055 |
{ |
| 1056 |
$output .= '<span class="required"> *</span>'; |
| 1057 |
} |
| 1058 |
$output .= '</label>'; |
| 1059 |
} |
| 1060 |
|
| 1061 |
$blank_option = ''; |
| 1062 |
foreach ( $field['options'] as $option_key => $value ) |
| 1063 |
{ |
| 1064 |
if ( $field['multiselect'] && $option_key == '' ) |
| 1065 |
{ |
| 1066 |
$blank_option = $value; |
| 1067 |
continue; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
$output .= '<select |
| 1072 |
name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '" |
| 1073 |
id="' . esc_attr( $key ) . '" |
| 1074 |
class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '" |
| 1075 |
' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . ' |
| 1076 |
data-blank-option="' . esc_attr($blank_option) . '" |
| 1077 |
>'; |
| 1078 |
|
| 1079 |
foreach ( $field['options'] as $option_key => $value ) |
| 1080 |
{ |
| 1081 |
if ( $field['multiselect'] && $option_key == '' ) |
| 1082 |
{ |
| 1083 |
// Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder |
| 1084 |
continue; |
| 1085 |
} |
| 1086 |
|
| 1087 |
$output .= '<option |
| 1088 |
value="' . esc_attr( $option_key ) . '"'; |
| 1089 |
if ( !$field['multiselect'] ) |
| 1090 |
{ |
| 1091 |
$output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ); |
| 1092 |
} |
| 1093 |
else |
| 1094 |
{ |
| 1095 |
if ( |
| 1096 |
( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) ) |
| 1097 |
|| |
| 1098 |
( !isset($_REQUEST[$key]) && is_array($field['value']) && in_array($option_key, $field['value']) ) |
| 1099 |
) |
| 1100 |
{ |
| 1101 |
$output .= ' selected'; |
| 1102 |
} |
| 1103 |
} |
| 1104 |
$output .= '>' . esc_html( __( $value, 'propertyhive' ) ) . '</option>'; |
| 1105 |
} |
| 1106 |
|
| 1107 |
$output .= '</select>'; |
| 1108 |
|
| 1109 |
$output .= $field['after']; |
| 1110 |
|
| 1111 |
break; |
| 1112 |
} |
| 1113 |
case "office": |
| 1114 |
{ |
| 1115 |
$key = 'officeID'; |
| 1116 |
|
| 1117 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 1118 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1119 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1120 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1121 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1122 |
$field['blank_option'] = isset( $field['blank_option'] ) ? __( $field['blank_option'], 'propertyhive' ) : __( 'No preference', 'propertyhive' ); |
| 1123 |
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false; |
| 1124 |
|
| 1125 |
if ( $field['multiselect'] ) |
| 1126 |
{ |
| 1127 |
wp_enqueue_script( 'multiselect' ); |
| 1128 |
} |
| 1129 |
|
| 1130 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1131 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1132 |
{ |
| 1133 |
$field['value'] = (int)$_GET[$key]; |
| 1134 |
} |
| 1135 |
|
| 1136 |
$output .= $field['before']; |
| 1137 |
|
| 1138 |
if ($field['show_label']) |
| 1139 |
{ |
| 1140 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>'; |
| 1141 |
} |
| 1142 |
|
| 1143 |
$output .= '<select |
| 1144 |
name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '" |
| 1145 |
id="' . esc_attr( $key ) . '" |
| 1146 |
class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '" |
| 1147 |
' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . ' |
| 1148 |
data-blank-option="' . esc_attr( $field['blank_option'] ) . '" |
| 1149 |
>'; |
| 1150 |
|
| 1151 |
if ( !$field['multiselect'] ) |
| 1152 |
{ |
| 1153 |
$output .= '<option |
| 1154 |
value="" |
| 1155 |
' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . ' |
| 1156 |
>' . esc_html( $field['blank_option'] ) . '</option>'; |
| 1157 |
} |
| 1158 |
|
| 1159 |
$args = array( |
| 1160 |
'post_type' => 'office', |
| 1161 |
'nopaging' => true, |
| 1162 |
'orderby' => 'title', |
| 1163 |
'order' => 'ASC' |
| 1164 |
); |
| 1165 |
$office_query = new WP_Query($args); |
| 1166 |
|
| 1167 |
if ($office_query->have_posts()) |
| 1168 |
{ |
| 1169 |
while ($office_query->have_posts()) |
| 1170 |
{ |
| 1171 |
$office_query->the_post(); |
| 1172 |
|
| 1173 |
$output .= '<option |
| 1174 |
value="' . esc_attr( $post->ID ) . '" '; |
| 1175 |
if ( !$field['multiselect'] ) |
| 1176 |
{ |
| 1177 |
$output .= selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false ); |
| 1178 |
} |
| 1179 |
else |
| 1180 |
{ |
| 1181 |
if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($post->ID, $_REQUEST[$key]) ) |
| 1182 |
{ |
| 1183 |
$output .= ' selected'; |
| 1184 |
} |
| 1185 |
} |
| 1186 |
$output .= '>' . esc_html( get_the_title() ) . '</option>'; |
| 1187 |
|
| 1188 |
} |
| 1189 |
} |
| 1190 |
wp_reset_postdata(); |
| 1191 |
|
| 1192 |
$output .= '</select>'; |
| 1193 |
|
| 1194 |
$output .= $field['after']; |
| 1195 |
|
| 1196 |
break; |
| 1197 |
} |
| 1198 |
case "country": |
| 1199 |
{ |
| 1200 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 1201 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1202 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1203 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1204 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1205 |
|
| 1206 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1207 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1208 |
{ |
| 1209 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 1210 |
} |
| 1211 |
|
| 1212 |
$output .= $field['before']; |
| 1213 |
|
| 1214 |
if ($field['show_label']) |
| 1215 |
{ |
| 1216 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>'; |
| 1217 |
} |
| 1218 |
|
| 1219 |
$output .= '<select |
| 1220 |
name="' . esc_attr( $key ) . '" |
| 1221 |
id="' . esc_attr( $key ) . '" |
| 1222 |
class="' . esc_attr( $field['class'] ) . '" |
| 1223 |
>'; |
| 1224 |
|
| 1225 |
$output .= '<option |
| 1226 |
value="" |
| 1227 |
' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . ' |
| 1228 |
>' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>'; |
| 1229 |
|
| 1230 |
$countries = get_option( 'propertyhive_countries', array() ); |
| 1231 |
if ( is_array($countries) && !empty($countries) ) |
| 1232 |
{ |
| 1233 |
$ph_countries = new PH_Countries; |
| 1234 |
|
| 1235 |
foreach ( $countries as $country ) |
| 1236 |
{ |
| 1237 |
$ph_country = $ph_countries->get_country( $country ); |
| 1238 |
|
| 1239 |
if ( $ph_country !== FALSE ) |
| 1240 |
{ |
| 1241 |
$output .= '<option |
| 1242 |
value="' . esc_attr( $country ) . '" |
| 1243 |
' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . ' |
| 1244 |
>' . esc_html( $ph_country['name'] ) . '</option>'; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
} |
| 1248 |
|
| 1249 |
$output .= '</select>'; |
| 1250 |
|
| 1251 |
$output .= $field['after']; |
| 1252 |
|
| 1253 |
break; |
| 1254 |
} |
| 1255 |
case "slider": |
| 1256 |
{ |
| 1257 |
wp_enqueue_script('jquery'); |
| 1258 |
wp_enqueue_script('jquery-ui-core'); |
| 1259 |
wp_enqueue_script('jquery-ui-slider'); |
| 1260 |
wp_enqueue_script('jquery-ui-touch-punch', PH()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js', array('jquery'), '0.2.3', true); |
| 1261 |
wp_enqueue_style( 'jquery-ui-style', PH()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.css', array(), PH_VERSION ); |
| 1262 |
|
| 1263 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1264 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1265 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1266 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1267 |
$field['min'] = isset( $field['min'] ) ? $field['min'] : ''; |
| 1268 |
$field['max'] = isset( $field['max'] ) ? $field['max'] : ''; |
| 1269 |
$field['step'] = isset( $field['step'] ) ? $field['step'] : '1'; |
| 1270 |
|
| 1271 |
$output .= $field['before']; |
| 1272 |
|
| 1273 |
if ($field['show_label']) |
| 1274 |
{ |
| 1275 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label']; |
| 1276 |
$output .= ' - <span id="search-form-slider-value-' . $key . '" class="search-form-slider-value search-form-slider-value-' . $key . '"></span>'; |
| 1277 |
$output .= '</label>'; |
| 1278 |
} |
| 1279 |
|
| 1280 |
$output .= '<div id="search-form-slider-' . $key . '" class="search-form-slider search-form-slider-' . $key . '" style="min-width:150px;"></div>'; |
| 1281 |
|
| 1282 |
$field_name = str_replace("_slider", "", $key); |
| 1283 |
$output .= '<input type="hidden" name="minimum_' . $field_name . '" class="min_slider_value-' . $key . '" id="min_slider_value-' . $key . '" value="' . ( isset($_GET['minimum_' . $field_name]) ? ph_clean($_GET['minimum_' . $field_name]) : '' ) . '">'; |
| 1284 |
$output .= '<input type="hidden" name="maximum_' . $field_name . '" class="max_slider_value-' . $key . '" id="max_slider_value-' . $key . '" value="' . ( isset($_GET['maximum_' . $field_name]) ? ph_clean($_GET['maximum_' . $field_name]) : '' ) . '">'; |
| 1285 |
|
| 1286 |
$output .= $field['after']; |
| 1287 |
|
| 1288 |
$value = ''; |
| 1289 |
$prefix = ''; |
| 1290 |
$suffix = ''; |
| 1291 |
|
| 1292 |
if ( $key == 'price_slider' || $key == 'rent_slider' ) |
| 1293 |
{ |
| 1294 |
$prefix = '£'; |
| 1295 |
|
| 1296 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 1297 |
|
| 1298 |
$ph_countries = new PH_Countries(); |
| 1299 |
$countries = $ph_countries->countries; |
| 1300 |
|
| 1301 |
foreach ( $countries as $country_code => $country ) |
| 1302 |
{ |
| 1303 |
if ( isset($country['currency_code']) && $country['currency_code'] == $search_form_currency ) |
| 1304 |
{ |
| 1305 |
if ( $country['currency_prefix'] === true ) |
| 1306 |
{ |
| 1307 |
$prefix = $country['currency_symbol']; |
| 1308 |
$suffix = ''; |
| 1309 |
} |
| 1310 |
else |
| 1311 |
{ |
| 1312 |
$prefix = ''; |
| 1313 |
$suffix = $country['currency_symbol']; |
| 1314 |
} |
| 1315 |
break; |
| 1316 |
} |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
$js_key = wp_json_encode( sanitize_html_class( $key ) ); |
| 1321 |
$js_prefix = wp_json_encode( html_entity_decode( $prefix, ENT_QUOTES, 'UTF-8' ) ); |
| 1322 |
$js_suffix = wp_json_encode( html_entity_decode( $suffix, ENT_QUOTES, 'UTF-8' ) ); |
| 1323 |
|
| 1324 |
if ( $field['min'] != '' && $field['max'] != '' ) |
| 1325 |
{ |
| 1326 |
$value = 'values: [ ' . ( isset($_GET['minimum_' . $field_name]) && $_GET['minimum_' . $field_name] != '' ? (float)wp_unslash($_GET['minimum_' . $field_name]) : (float)$field['min'] ) . ', ' . ( isset($_GET['maximum_' . $field_name]) && $_GET['maximum_' . $field_name] != '' ? (float)wp_unslash($_GET['maximum_' . $field_name]) : (float)$field['max'] ) . ' ],'; |
| 1327 |
} |
| 1328 |
|
| 1329 |
$output .= '<script> |
| 1330 |
jQuery(document).ready(function() |
| 1331 |
{ |
| 1332 |
var key = ' . $js_key . '; |
| 1333 |
var prefix = ' . $js_prefix . '; |
| 1334 |
var suffix = ' . $js_suffix . '; |
| 1335 |
|
| 1336 |
jQuery(".search-form-slider-" + key).each(function(index) |
| 1337 |
{ |
| 1338 |
var $slider = jQuery(this); |
| 1339 |
|
| 1340 |
$slider.slider({ |
| 1341 |
range: ' . ( ( $field['min'] != '' && $field['max'] != '' ) ? 'true' : 'false' ) . ', |
| 1342 |
step: ' . (float) $field['step'] . ', |
| 1343 |
' . ( $field['min'] != '' ? 'min: ' . (float) $field['min'] . ',' : '' ) . ' |
| 1344 |
' . ( $field['max'] != '' ? 'max: ' . (float) $field['max'] . ',' : '' ) . ' |
| 1345 |
' . $value . ' |
| 1346 |
slide: function( event, ui ) { |
| 1347 |
var min = ui.values[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); |
| 1348 |
var max = ui.values[1].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); |
| 1349 |
|
| 1350 |
$slider.closest("form").find(".search-form-slider-value-" + key).text( |
| 1351 |
prefix + min + suffix + " - " + prefix + max + suffix |
| 1352 |
); |
| 1353 |
|
| 1354 |
$slider.closest("form").find(".min_slider_value-" + key).val(ui.values[0]); |
| 1355 |
$slider.closest("form").find(".max_slider_value-" + key).val(ui.values[1]); |
| 1356 |
} |
| 1357 |
}); |
| 1358 |
|
| 1359 |
var initialMin = $slider.slider("values", 0).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); |
| 1360 |
var initialMax = $slider.slider("values", 1).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); |
| 1361 |
|
| 1362 |
$slider.closest("form").find(".search-form-slider-value-" + key).text( |
| 1363 |
prefix + initialMin + suffix + " - " + prefix + initialMax + suffix |
| 1364 |
); |
| 1365 |
}); |
| 1366 |
}); |
| 1367 |
</script>'; |
| 1368 |
|
| 1369 |
break; |
| 1370 |
} |
| 1371 |
case "hidden": |
| 1372 |
{ |
| 1373 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1374 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $key; |
| 1375 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1376 |
{ |
| 1377 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 1378 |
} |
| 1379 |
|
| 1380 |
$output .= '<input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="' . esc_attr($field['value']) . '">'; |
| 1381 |
break; |
| 1382 |
} |
| 1383 |
case "html": |
| 1384 |
{ |
| 1385 |
$field['html'] = isset( $field['html'] ) ? $field['html'] : ''; |
| 1386 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1387 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1388 |
|
| 1389 |
$output .= $field['before']; |
| 1390 |
$output .= $field['html']; |
| 1391 |
$output .= $field['after']; |
| 1392 |
|
| 1393 |
break; |
| 1394 |
} |
| 1395 |
case "recaptcha": |
| 1396 |
{ |
| 1397 |
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : ''; |
| 1398 |
|
| 1399 |
$output .= '<script src="https://www.google.com/recaptcha/api.js"></script> |
| 1400 |
<div class="g-recaptcha" data-sitekey="' . esc_attr($field['site_key']) . '"></div>'; |
| 1401 |
break; |
| 1402 |
} |
| 1403 |
case "recaptcha-v3": |
| 1404 |
{ |
| 1405 |
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : ''; |
| 1406 |
|
| 1407 |
$output .= ' |
| 1408 |
<script src="https://www.google.com/recaptcha/api.js?render=' . $field['site_key'] . '"></script> |
| 1409 |
<script> |
| 1410 |
grecaptcha.ready(function() { |
| 1411 |
grecaptcha.execute("' . $field['site_key'] . '", {action:\'submit\'}) |
| 1412 |
.then(function(token) { |
| 1413 |
// add token value to form |
| 1414 |
document.querySelectorAll("#g-recaptcha-response").forEach( |
| 1415 |
elem => (elem.value = token) |
| 1416 |
); |
| 1417 |
}); |
| 1418 |
}); |
| 1419 |
</script> |
| 1420 |
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> |
| 1421 |
'; |
| 1422 |
break; |
| 1423 |
} |
| 1424 |
case "hCaptcha": |
| 1425 |
{ |
| 1426 |
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : ''; |
| 1427 |
|
| 1428 |
$output .= '<script src="https://js.hcaptcha.com/1/api.js" async defer></script> |
| 1429 |
<div class="h-captcha" data-sitekey="' . $field['site_key'] . '"></div>'; |
| 1430 |
break; |
| 1431 |
} |
| 1432 |
case "turnstile": |
| 1433 |
{ |
| 1434 |
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : ''; |
| 1435 |
|
| 1436 |
$output .= '<div class="turnstile" data-sitekey="' . $field['site_key'] . '"></div>'; |
| 1437 |
break; |
| 1438 |
} |
| 1439 |
case "daterange": |
| 1440 |
{ |
| 1441 |
wp_enqueue_script( 'moment.js', '//cdn.jsdelivr.net/momentjs/latest/moment.min.js' ); |
| 1442 |
wp_enqueue_script( 'daterangepicker.js', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js' ); |
| 1443 |
wp_enqueue_style( 'daterangepicker.css', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css' ); |
| 1444 |
|
| 1445 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1446 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1447 |
|
| 1448 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1449 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1450 |
|
| 1451 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1452 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 1453 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 1454 |
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 1455 |
|
| 1456 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1457 |
{ |
| 1458 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 1459 |
} |
| 1460 |
|
| 1461 |
$output .= $field['before']; |
| 1462 |
|
| 1463 |
if ($field['show_label']) |
| 1464 |
{ |
| 1465 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>'; |
| 1466 |
} |
| 1467 |
|
| 1468 |
$output .= '<input type="text" autocomplete="off" |
| 1469 |
name="' . esc_attr( $key ) . '" |
| 1470 |
id="' . esc_attr( $key ) . '" |
| 1471 |
value="' . esc_attr( $field['value'] ) . '" |
| 1472 |
style="' . esc_attr( $field['style'] ) . '" |
| 1473 |
class="' . esc_attr( $field['class'] ) . '" |
| 1474 |
placeholder="' . esc_attr( $field['placeholder'] ) . '" |
| 1475 |
/>'; |
| 1476 |
$output .= $field['after']; |
| 1477 |
|
| 1478 |
break; |
| 1479 |
} |
| 1480 |
default: |
| 1481 |
{ |
| 1482 |
if ( taxonomy_exists($field['type']) ) |
| 1483 |
{ |
| 1484 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; |
| 1485 |
$field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">'; |
| 1486 |
$field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>'; |
| 1487 |
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true; |
| 1488 |
$field['label'] = isset( $field['label'] ) ? $field['label'] : ''; |
| 1489 |
$field['blank_option'] = isset( $field['blank_option'] ) ? __( $field['blank_option'], 'propertyhive' ) : __( 'No preference', 'propertyhive' ); |
| 1490 |
$field['parent_terms_only'] = isset( $field['parent_terms_only'] ) ? $field['parent_terms_only'] : false; |
| 1491 |
$field['hide_empty'] = isset( $field['hide_empty'] ) ? $field['hide_empty'] : false; |
| 1492 |
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false; |
| 1493 |
$field['dynamic_population'] = ( isset( $field['dynamic_population'] ) && $field['type'] == 'location' && $field['parent_terms_only'] === false && $field['multiselect'] === false ) ? $field['dynamic_population'] : false; // only applies to location |
| 1494 |
|
| 1495 |
if ( $field['multiselect'] ) |
| 1496 |
{ |
| 1497 |
wp_enqueue_script( 'multiselect' ); |
| 1498 |
} |
| 1499 |
|
| 1500 |
$options = array( |
| 1501 |
'' => array( |
| 1502 |
'label' => $field['blank_option'], |
| 1503 |
'parent' => 0 |
| 1504 |
) |
| 1505 |
); |
| 1506 |
$args = array( |
| 1507 |
'hide_empty' => $field['hide_empty'], |
| 1508 |
'parent' => 0 |
| 1509 |
); |
| 1510 |
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field ); |
| 1511 |
$terms = get_terms( $field['type'], $args ); |
| 1512 |
|
| 1513 |
$levels_of_taxonomy = 1; |
| 1514 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 1515 |
{ |
| 1516 |
foreach ($terms as $term) |
| 1517 |
{ |
| 1518 |
if ( isset($field['hide_empty']) && $field['hide_empty'] === true ) |
| 1519 |
{ |
| 1520 |
$empty_check_args = array( |
| 1521 |
'post_type' => 'property', |
| 1522 |
'meta_query' => array( |
| 1523 |
array( |
| 1524 |
'key' => '_on_market', |
| 1525 |
'value' => 'yes', |
| 1526 |
), |
| 1527 |
), |
| 1528 |
'tax_query' => array( |
| 1529 |
array( |
| 1530 |
'taxonomy' => $field['type'], |
| 1531 |
'field' => 'term_id', |
| 1532 |
'terms' => $term->term_id, |
| 1533 |
), |
| 1534 |
), |
| 1535 |
); |
| 1536 |
|
| 1537 |
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $term->term_id ); |
| 1538 |
|
| 1539 |
$empty_check_query = new WP_Query( $empty_check_args ); |
| 1540 |
|
| 1541 |
if ( !$empty_check_query->have_posts() ) |
| 1542 |
{ |
| 1543 |
continue; |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
$options[(int)$term->term_id] = array( |
| 1548 |
'label' => __( $term->name, 'propertyhive' ), |
| 1549 |
'parent' => 0 |
| 1550 |
); |
| 1551 |
|
| 1552 |
if ($field['dynamic_population']) |
| 1553 |
$levels_of_taxonomy = max(1, $levels_of_taxonomy); |
| 1554 |
|
| 1555 |
if ( |
| 1556 |
!isset($field['parent_terms_only']) |
| 1557 |
|| |
| 1558 |
( |
| 1559 |
isset($field['parent_terms_only']) && |
| 1560 |
$field['parent_terms_only'] === false |
| 1561 |
) |
| 1562 |
) |
| 1563 |
{ |
| 1564 |
$args = array( |
| 1565 |
'hide_empty' => $field['hide_empty'], |
| 1566 |
'parent' => $term->term_id, |
| 1567 |
); |
| 1568 |
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field ); |
| 1569 |
$args = apply_filters( 'propertyhive_form_taxonomy_subterms_args', $args, $field ); |
| 1570 |
$subterms = get_terms( $field['type'], $args ); |
| 1571 |
|
| 1572 |
if ( !empty( $subterms ) && !is_wp_error( $subterms ) ) |
| 1573 |
{ |
| 1574 |
foreach ($subterms as $subterm) |
| 1575 |
{ |
| 1576 |
if ( isset($field['hide_empty']) && $field['hide_empty'] === true ) |
| 1577 |
{ |
| 1578 |
$empty_check_args = array( |
| 1579 |
'post_type' => 'property', |
| 1580 |
'meta_query' => array( |
| 1581 |
array( |
| 1582 |
'key' => '_on_market', |
| 1583 |
'value' => 'yes', |
| 1584 |
), |
| 1585 |
), |
| 1586 |
'tax_query' => array( |
| 1587 |
array( |
| 1588 |
'taxonomy' => $field['type'], |
| 1589 |
'field' => 'term_id', |
| 1590 |
'terms' => $subterm->term_id, |
| 1591 |
), |
| 1592 |
), |
| 1593 |
); |
| 1594 |
|
| 1595 |
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $subterm->term_id ); |
| 1596 |
|
| 1597 |
$empty_check_query = new WP_Query( $empty_check_args ); |
| 1598 |
|
| 1599 |
if ( !$empty_check_query->have_posts() ) |
| 1600 |
{ |
| 1601 |
continue; |
| 1602 |
} |
| 1603 |
} |
| 1604 |
|
| 1605 |
$options[(int)$subterm->term_id] = array( |
| 1606 |
'label' => ( !$field['dynamic_population'] ? '- ' : '' ) . __( $subterm->name, 'propertyhive' ), |
| 1607 |
'parent' => (int)$term->term_id, |
| 1608 |
); |
| 1609 |
|
| 1610 |
if ($field['dynamic_population']) |
| 1611 |
$levels_of_taxonomy = max(2, $levels_of_taxonomy); |
| 1612 |
|
| 1613 |
$args = array( |
| 1614 |
'hide_empty' => $field['hide_empty'], |
| 1615 |
'parent' => (int)$subterm->term_id |
| 1616 |
); |
| 1617 |
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field ); |
| 1618 |
$args = apply_filters( 'propertyhive_form_taxonomy_subsubterms_args', $args, $field ); |
| 1619 |
$subsubterms = get_terms( $field['type'], $args ); |
| 1620 |
|
| 1621 |
if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) ) |
| 1622 |
{ |
| 1623 |
foreach ($subsubterms as $subsubterm) |
| 1624 |
{ |
| 1625 |
if ( isset($field['hide_empty']) && $field['hide_empty'] === true ) |
| 1626 |
{ |
| 1627 |
$empty_check_args = array( |
| 1628 |
'post_type' => 'property', |
| 1629 |
'meta_query' => array( |
| 1630 |
array( |
| 1631 |
'key' => '_on_market', |
| 1632 |
'value' => 'yes', |
| 1633 |
), |
| 1634 |
), |
| 1635 |
'tax_query' => array( |
| 1636 |
array( |
| 1637 |
'taxonomy' => $field['type'], |
| 1638 |
'field' => 'term_id', |
| 1639 |
'terms' => $subsubterm->term_id, |
| 1640 |
), |
| 1641 |
), |
| 1642 |
); |
| 1643 |
|
| 1644 |
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $subsubterm->term_id ); |
| 1645 |
|
| 1646 |
$empty_check_query = new WP_Query( $empty_check_args ); |
| 1647 |
|
| 1648 |
if ( !$empty_check_query->have_posts() ) |
| 1649 |
{ |
| 1650 |
continue; |
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
$options[(int)$subsubterm->term_id] = array( |
| 1655 |
'label' => ( !$field['dynamic_population'] ? '- - ' : '' ) . __( $subsubterm->name, 'propertyhive' ), |
| 1656 |
'parent' => (int)$subterm->term_id, |
| 1657 |
); |
| 1658 |
|
| 1659 |
if ($field['dynamic_population']) |
| 1660 |
$levels_of_taxonomy = max(3, $levels_of_taxonomy); |
| 1661 |
} |
| 1662 |
} |
| 1663 |
} |
| 1664 |
} |
| 1665 |
} |
| 1666 |
} |
| 1667 |
} |
| 1668 |
|
| 1669 |
if ( $field['dynamic_population'] ) |
| 1670 |
{ |
| 1671 |
wp_localize_script( 'propertyhive_dynamic_population', 'propertyhive_dynamic_population_params', array( |
| 1672 |
'options' => $options, |
| 1673 |
'levels_of_taxonomy' => $levels_of_taxonomy, |
| 1674 |
'value' => isset($_GET[$field['type']]) ? ph_clean($_GET[$field['type']]) : '', |
| 1675 |
'other_values' => ( isset($_GET['other_' . $field['type']]) && is_array($_GET['other_' . $field['type']]) && !empty($_GET['other_' . $field['type']]) ) ? ph_clean(array_filter($_GET['other_' . $field['type']])) : array(), |
| 1676 |
'taxonomy' => $field['type'], |
| 1677 |
) ); |
| 1678 |
wp_enqueue_script( 'propertyhive_dynamic_population' ); |
| 1679 |
} |
| 1680 |
|
| 1681 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : ''; |
| 1682 |
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) ) |
| 1683 |
{ |
| 1684 |
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key])); |
| 1685 |
} |
| 1686 |
|
| 1687 |
for ( $level_i = 1; $level_i <= $levels_of_taxonomy; ++$level_i ) |
| 1688 |
{ |
| 1689 |
$output .= $field['before']; |
| 1690 |
|
| 1691 |
if ($field['show_label']) |
| 1692 |
{ |
| 1693 |
$output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>'; |
| 1694 |
} |
| 1695 |
|
| 1696 |
$output .= '<select |
| 1697 |
name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '" |
| 1698 |
id="' . esc_attr( $key ) . '" |
| 1699 |
class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '" |
| 1700 |
' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . |
| 1701 |
( $field['dynamic_population'] ? ' data-dynamic-population-level="' . $level_i . '"' : '' ) . |
| 1702 |
( ( $field['dynamic_population'] && $level_i > 1 ) ? ' disabled' : '' ) . ' |
| 1703 |
data-blank-option="' . esc_attr($field['blank_option']) . '" |
| 1704 |
>'; |
| 1705 |
|
| 1706 |
if ( $level_i == 1 ) |
| 1707 |
{ |
| 1708 |
foreach ( $options as $option_key => $value ) |
| 1709 |
{ |
| 1710 |
if ( $field['multiselect'] && $option_key == '' ) |
| 1711 |
{ |
| 1712 |
// Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder |
| 1713 |
continue; |
| 1714 |
} |
| 1715 |
|
| 1716 |
if ( $field['dynamic_population'] && $value['parent'] != '0' ) |
| 1717 |
{ |
| 1718 |
continue; |
| 1719 |
} |
| 1720 |
|
| 1721 |
$output .= '<option |
| 1722 |
value="' . esc_attr( $option_key ) . '"'; |
| 1723 |
if ( !$field['multiselect'] ) |
| 1724 |
{ |
| 1725 |
$output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ); |
| 1726 |
} |
| 1727 |
else |
| 1728 |
{ |
| 1729 |
if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) ) |
| 1730 |
{ |
| 1731 |
$output .= ' selected'; |
| 1732 |
} |
| 1733 |
elseif ( is_array($field['value']) && in_array($option_key, $field['value']) ) |
| 1734 |
{ |
| 1735 |
$output .= ' selected'; |
| 1736 |
} |
| 1737 |
} |
| 1738 |
$output .= '>' . esc_html( $value['label'] ) . '</option>'; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
$output .= '</select>'; |
| 1743 |
|
| 1744 |
$output .= $field['after']; |
| 1745 |
|
| 1746 |
if ( $field['type'] == 'availability' ) |
| 1747 |
{ |
| 1748 |
$availability_departments = get_option( 'propertyhive_availability_departments', array() ); |
| 1749 |
if ( !is_array($availability_departments) ) { $availability_departments = array(); } |
| 1750 |
|
| 1751 |
if ( !empty($availability_departments) ) |
| 1752 |
{ |
| 1753 |
?> |
| 1754 |
<script> |
| 1755 |
var selected_availability = '<?php echo ( isset($_REQUEST[$key]) && $_REQUEST[$key] != '' ? (int)$_REQUEST[$key] : '' ); ?>'; |
| 1756 |
var availability_departments = <?php echo json_encode($availability_departments); ?>; |
| 1757 |
var availabilities = <?php echo json_encode($options); ?>; |
| 1758 |
var availabilities_order = <?php echo json_encode(array_keys($options)); ?>; |
| 1759 |
</script> |
| 1760 |
<?php |
| 1761 |
} |
| 1762 |
} |
| 1763 |
} |
| 1764 |
} |
| 1765 |
} |
| 1766 |
} |
| 1767 |
|
| 1768 |
echo $output; |
| 1769 |
} |