PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / admin / settings / class-ph-settings-custom-fields.php

class-ph-settings-custom-fields.php in Property Hive 2.3.0, at includes/admin/settings/class-ph-settings-custom-fields.php

3,967 lines 194.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean
3 // ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate.
4
5 /**
6 * PropertyHive Custom Fields Settings
7 *
8 * @author PropertyHive
9 * @category Admin
10 * @package PropertyHive/Admin
11 * @version 1.0.0
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly
16 }
17
18 if ( ! class_exists( 'PH_Settings_Custom_Fields' ) ) :
19
20 /**
21 * PH_Settings_General
22 */
23 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Settings_Custom_Fields; preserving the existing PH_* class name is required for plugin and extension compatibility.
24 class PH_Settings_Custom_Fields extends PH_Settings_Page {
25
26 const LINKED_POSTS_COLUMN_HEADING = 'Assigned Properties';
27
28 private $custom_field_sections;
29
30 /**
31 * Constructor.
32 */
33 public function __construct() {
34 $this->id = 'customfields';
35 $this->label = __( 'Field Manager', 'propertyhive' );
36
37 add_action( 'admin_init', array( $this, 'check_for_delete_additional_field') );
38 add_action( 'admin_init', array( $this, 'check_for_reorder_additional_fields') );
39
40 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 15 );
41 add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) );
42 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
43 add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
44
45 add_action( 'propertyhive_admin_field_additional_fields_table', array( $this, 'additional_fields_table' ) );
46
47 add_action( 'propertyhive_admin_field_additional_field_dropdown_options', array( $this, 'additional_field_dropdown_options' ) );
48
49 $this->get_custom_field_sections();
50 }
51
52 public function check_for_delete_additional_field()
53 {
54 if (
55 ! isset( $_GET['action'] ) ||
56 'deleteadditionalfield' !== $_GET['action']
57 ) {
58 return;
59 }
60
61 if ( ! current_user_can( 'manage_options' ) ) {
62 wp_die(
63 esc_html__( 'You do not have permission to manage Property Hive fields.', 'propertyhive' ),
64 '',
65 array( 'response' => 403 )
66 );
67 }
68
69 check_admin_referer( 'propertyhive_delete_additional_field' );
70
71 $current_id = isset( $_GET['id'] ) && is_string( $_GET['id'] )
72 ? sanitize_title( wp_unslash( $_GET['id'] ) )
73 : '';
74
75 if ( '' === $current_id ) {
76 wp_die(
77 esc_html__( 'Invalid additional field.', 'propertyhive' ),
78 '',
79 array( 'response' => 400 )
80 );
81 }
82
83 $current_settings = get_option(
84 'propertyhive_template_assistant',
85 array()
86 );
87
88 $existing_custom_fields =
89 isset( $current_settings['custom_fields'] )
90 && is_array( $current_settings['custom_fields'] )
91 ? $current_settings['custom_fields']
92 : array();
93
94 if ( ! isset( $existing_custom_fields[ $current_id ] ) ) {
95 wp_die(
96 esc_html__( 'The additional field does not exist.', 'propertyhive' ),
97 '',
98 array( 'response' => 404 )
99 );
100 }
101
102 unset( $existing_custom_fields[ $current_id ] );
103
104 $current_settings['custom_fields'] = $existing_custom_fields;
105
106 update_option(
107 'propertyhive_template_assistant',
108 $current_settings
109 );
110
111 wp_safe_redirect(
112 admin_url(
113 'admin.php?page=ph-settings&tab=customfields&section=additional&ph_message=' . __( 'Additional field deleted successfully', 'propertyhive' )
114 )
115 );
116 exit;
117 }
118
119 public function check_for_reorder_additional_fields()
120 {
121 if ( ! isset( $_GET['neworder'] ) ) {
122 return;
123 }
124
125 if ( ! current_user_can( 'manage_options' ) ) {
126 wp_die(
127 esc_html__( 'You do not have permission to manage Property Hive fields.', 'propertyhive' ),
128 '',
129 array( 'response' => 403 )
130 );
131 }
132
133 check_admin_referer( 'propertyhive_reorder_additional_fields' );
134
135 if ( ! is_string( $_GET['neworder'] ) ) {
136 wp_die( esc_html__( 'Invalid additional field order.', 'propertyhive' ), '', array( 'response' => 400 ) );
137 }
138
139 $new_order = array_map(
140 'sanitize_title',
141 explode(
142 ',',
143 sanitize_text_field(
144 wp_unslash( $_GET['neworder'] )
145 )
146 )
147 );
148
149 $current_settings = get_option(
150 'propertyhive_template_assistant',
151 array()
152 );
153
154 $existing_custom_fields =
155 isset( $current_settings['custom_fields'] )
156 && is_array( $current_settings['custom_fields'] )
157 ? $current_settings['custom_fields']
158 : array();
159
160 if (
161 count( $new_order ) !== count( $existing_custom_fields ) ||
162 array_diff( $new_order, array_keys( $existing_custom_fields ) ) ||
163 array_diff( array_keys( $existing_custom_fields ), $new_order )
164 ) {
165 wp_die(
166 esc_html__( 'Invalid additional field order.', 'propertyhive' ),
167 '',
168 array( 'response' => 400 )
169 );
170 }
171
172 $new_custom_fields = array();
173
174 foreach ( $new_order as $id ) {
175 $new_custom_fields[ $id ] = $existing_custom_fields[ $id ];
176 }
177
178 $current_settings['custom_fields'] = $new_custom_fields;
179
180 update_option(
181 'propertyhive_template_assistant',
182 $current_settings
183 );
184
185 wp_safe_redirect(
186 admin_url(
187 'admin.php?page=ph-settings&tab=customfields&section=additional&ph_message=' . __( 'Additional fields reordered successfully', 'propertyhive' )
188 )
189 );
190 exit;
191 }
192
193 /**
194 * Get sections
195 *
196 * @return array
197 */
198 public function get_sections() {
199 $sections = array(
200 '' => __( 'Field Values', 'propertyhive' ),
201 'additional' => __( 'Additional Fields', 'propertyhive' )
202 );
203
204 return $sections;
205 }
206
207 public function get_custom_field_sections()
208 {
209 $sections = array();
210
211 $residential_active = false;
212 $residential_sales_active = false;
213 $residential_lettings_active = false;
214 $commercial_active = false;
215
216 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
217 {
218 $residential_active = true;
219 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
220 {
221 $residential_sales_active = true;
222 }
223 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
224 {
225 $residential_lettings_active = true;
226 }
227 }
228 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
229 {
230 $commercial_active = true;
231 }
232
233 $default_departments = ph_get_departments(true);
234 $custom_departments = ph_get_custom_departments(false);
235 if ( $custom_departments )
236 {
237 foreach ( $custom_departments as $key => $custom_department )
238 {
239 if ( isset($custom_department['based_on']) && get_option('propertyhive_active_departments_' . $key) == 'yes' )
240 {
241 foreach ( $default_departments as $dept_key => $value )
242 {
243 if ( $custom_department['based_on'] == $dept_key )
244 {
245 switch ( $custom_department['based_on'] )
246 {
247 case "residential-sales": { $residential_active = true; $residential_sales_active = true; }
248 case "residential-lettings": { $residential_active = true; $residential_lettings_active = true; }
249 case "commercial": { $commercial_active = true; }
250 }
251 }
252 }
253 }
254 }
255 }
256
257 // Residential Custom Fields
258 $sections[ 'availability' ] = __( 'Availabilities', 'propertyhive' );
259 add_action( 'propertyhive_admin_field_custom_fields_availability', array( $this, 'custom_fields_availability_setting' ) );
260
261 if ( $residential_active )
262 {
263 $sections[ 'property-type' ] = ( $commercial_active ? __( 'Residential ', 'propertyhive' ) . ' ' : '' ) . __( 'Property Types', 'propertyhive' );
264 add_action( 'propertyhive_admin_field_custom_fields_property_type', array( $this, 'custom_fields_property_type_setting' ) );
265 }
266 if ( $commercial_active )
267 {
268 $sections[ 'commercial-property-type' ] = ( $residential_active ? __( 'Commercial', 'propertyhive' ) . ' ' : '' ) . __( 'Property Types', 'propertyhive' );
269 add_action( 'propertyhive_admin_field_custom_fields_commercial_property_type', array( $this, 'custom_fields_commercial_property_type_setting' ) );
270 }
271
272 $sections[ 'location' ] = __( 'Locations', 'propertyhive' );
273 add_action( 'propertyhive_admin_field_custom_fields_location', array( $this, 'custom_fields_location_setting' ) );
274
275 if ( $residential_active )
276 {
277 $sections[ 'parking' ] = __( 'Parking', 'propertyhive' );
278 add_action( 'propertyhive_admin_field_custom_fields_parking', array( $this, 'custom_fields_parking_setting' ) );
279
280 $sections[ 'outside-space' ] = __( 'Outside Spaces', 'propertyhive' );
281 add_action( 'propertyhive_admin_field_custom_fields_outside_space', array( $this, 'custom_fields_outside_space_setting' ) );
282 }
283
284 if ( $residential_sales_active || $commercial_active )
285 {
286 $sections[ 'price-qualifier' ] = __( 'Price Qualifiers', 'propertyhive' );
287 add_action( 'propertyhive_admin_field_custom_fields_price_qualifier', array( $this, 'custom_fields_price_qualifier_setting' ) );
288
289 $sections[ 'sale-by' ] = __( 'Sale By', 'propertyhive' );
290 add_action( 'propertyhive_admin_field_custom_fields_sale_by', array( $this, 'custom_fields_sale_by_setting' ) );
291 }
292
293 if ( $residential_active )
294 {
295 $sections[ 'tenure' ] = ( $commercial_active ? __( 'Residential', 'propertyhive' ) . ' ' : '' ) . __( 'Tenures', 'propertyhive' );
296 add_action( 'propertyhive_admin_field_custom_fields_tenure', array( $this, 'custom_fields_tenure_setting' ) );
297 }
298 if ( $commercial_active )
299 {
300 $sections[ 'commercial-tenure' ] = ( $residential_active ? __( 'Commercial', 'propertyhive' ) . ' ' : '' ) . __( 'Tenures', 'propertyhive' );
301 add_action( 'propertyhive_admin_field_custom_fields_commercial_tenure', array( $this, 'custom_fields_commercial_tenure_setting' ) );
302 }
303
304 if ( $residential_lettings_active )
305 {
306 $sections[ 'furnished' ] = __( 'Furnished', 'propertyhive' );
307 add_action( 'propertyhive_admin_field_custom_fields_furnished', array( $this, 'custom_fields_furnished_setting' ) );
308
309 if ( get_option( 'propertyhive_module_disabled_tenancies', '' ) != 'yes' )
310 {
311 $sections[ 'management-key-date-type' ] = __( 'Management Date Types', 'propertyhive' );
312 add_action( 'propertyhive_admin_field_custom_fields_management_key_date_type', array( $this, 'custom_fields_management_key_date_type_setting' ) );
313 }
314 }
315
316 // Other
317 $sections[ 'marketing-flag' ] = __( 'Marketing Flags', 'propertyhive' );
318 add_action( 'propertyhive_admin_field_custom_fields_marketing_flag', array( $this, 'custom_fields_marketing_flag_setting' ) );
319
320 if ( get_option('propertyhive_features_type') == 'checkbox' )
321 {
322 $sections[ 'property-feature' ] = __( 'Property Features', 'propertyhive' );
323 add_action( 'propertyhive_admin_field_custom_fields_property_feature', array( $this, 'custom_fields_property_feature_setting' ) );
324 }
325
326 $sections = apply_filters( 'propertyhive_admin_field_custom_fields_sections', $sections );
327
328 $this->custom_field_sections = $sections;
329 }
330
331 /**
332 * Get settings array
333 *
334 * @return array
335 */
336 public function get_settings() {
337
338 global $hide_save_button;
339
340 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
341 $hide_save_button = true;
342
343 $i = 0;
344 $html = '<div class="ph-custom-fields-grid">';
345 foreach ( $this->custom_field_sections as $key => $value )
346 {
347 $image = 'default.png';
348 if ( file_exists(PH()->plugin_path() . '/assets/images/admin/settings/custom-fields/' . $key . '.png') )
349 {
350 $image = $key . '.png';
351 }
352 $html .= '<div>
353 <div class="ph-grid-image">
354 <div class="ph-grid-image-bg"><img alt="" src="' . esc_url(PH()->plugin_url() . '/assets/images/admin/settings/custom-fields/' . $image) . '" /></div>
355 </div>
356 <div class="feature-card-content">
357 <h3>' . esc_html($value) . '</h3>
358 <p style="margin-top:12px;"><a href="' . esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=' . $key )) . '" class="button-primary">Manage values</a></p>
359 </div>
360 </div>';
361 }
362 $html .= '</div>';
363
364 return apply_filters( 'propertyhive_custom_fields_settings', array(
365
366 array( 'title' => __( 'Field Values', 'propertyhive' ), 'type' => 'title', 'desc' => __( 'Manage the values used in dropdowns, filters and fields across properties, contacts and other records.', 'propertyhive' ), 'id' => 'custom_field_options' ),
367
368 array(
369 'type' => 'html',
370 'title' => '',
371 'html' => $html,
372 'full_width' => true
373 ),
374
375 array( 'type' => 'sectionend', 'id' => 'custom_field_options')
376
377 ));
378 }
379
380 /**
381 * Output the settings
382 */
383 public function output() {
384 global $current_section, $redirect_after_save;
385
386 if ( $current_section )
387 {
388 switch ( $current_section )
389 {
390 case "additional":
391 {
392 global $hide_save_button;
393
394 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
395 $hide_save_button = true;
396
397 // The main custom field screen listing them in a table
398 $settings = $this->get_custom_fields_additional_fields_setting();
399
400 PH_Admin_Settings::output_fields( $settings );
401 break;
402 }
403 case "addadditionalfield":
404 case "editadditionalfield":
405 {
406 $settings = $this->get_custom_fields_additional_field_settings();
407
408 $redirect_after_save = admin_url('admin.php?page=ph-settings&tab=customfields&section=additional');
409
410 PH_Admin_Settings::output_fields( $settings );
411
412 break;
413 }
414 default:
415 {
416 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This branch only renders a settings form from an optional id; it does not mutate state. The corresponding save path verifies the settings nonce and capability.
417 if ( isset( $_REQUEST['id'] ) ) // we're either adding or editing
418 {
419 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This id is used only to render a settings form; the corresponding save path verifies the settings nonce and capability.
420 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '';
421
422 switch ($current_section)
423 {
424 case "availability": { $settings = $this->get_custom_fields_availability_setting(); break; }
425 case "availability-delete": { $settings = $this->get_custom_fields_delete($current_id, 'availability', __( 'Availability', 'propertyhive' )); break; }
426 case "property-type": { $settings = $this->get_custom_fields_property_type_setting(); break; }
427 case "property-type-delete": { $settings = $this->get_custom_fields_delete($current_id, 'property_type', __( 'Property Type', 'propertyhive' )); break; }
428 case "commercial-property-type": { $settings = $this->get_custom_fields_commercial_property_type_setting(); break; }
429 case "commercial-property-type-delete": { $settings = $this->get_custom_fields_delete($current_id, 'commercial_property_type', __( 'Property Type', 'propertyhive' )); break; }
430 case "location": { $settings = $this->get_custom_fields_location_setting(); break; }
431 case "location-delete": { $settings = $this->get_custom_fields_delete($current_id, 'location', __( 'Location', 'propertyhive' )); break; }
432 case "parking": { $settings = $this->get_custom_fields_parking_setting(); break; }
433 case "parking-delete": { $settings = $this->get_custom_fields_delete($current_id, 'parking', __( 'Parking', 'propertyhive' )); break; }
434 case "outside-space": { $settings = $this->get_custom_fields_outside_space_setting(); break; }
435 case "outside-space-delete": { $settings = $this->get_custom_fields_delete($current_id, 'outside_space', __( 'Outside Space', 'propertyhive' )); break; }
436
437 case "price-qualifier": { $settings = $this->get_custom_fields_price_qualifier_setting(); break; }
438 case "price-qualifier-delete": { $settings = $this->get_custom_fields_delete($current_id, 'price_qualifier', __( 'Price Qualifier', 'propertyhive' )); break; }
439 case "sale-by": { $settings = $this->get_custom_fields_sale_by_setting(); break; }
440 case "sale-by-delete": { $settings = $this->get_custom_fields_delete($current_id, 'sale_by', __( 'Sale By', 'propertyhive' )); break; }
441 case "tenure": { $settings = $this->get_custom_fields_tenure_setting(); break; }
442 case "tenure-delete": { $settings = $this->get_custom_fields_delete($current_id, 'tenure', __( 'Tenure', 'propertyhive' )); break; }
443 case "commercial-tenure": { $settings = $this->get_custom_fields_commercial_tenure_setting(); break; }
444 case "commercial-tenure-delete": { $settings = $this->get_custom_fields_delete($current_id, 'commercial_tenure', __( 'Tenure', 'propertyhive' )); break; }
445
446 case "furnished": { $settings = $this->get_custom_fields_furnished_setting(); break; }
447 case "furnished-delete": { $settings = $this->get_custom_fields_delete($current_id, 'furnished', __( 'Furnished', 'propertyhive' )); break; }
448 case "management-key-date-type": { $settings = $this->get_custom_fields_management_key_date_type_setting(); break; }
449 case "management-key-date-type-delete": { $settings = $this->get_custom_fields_delete($current_id, 'management_key_date_type', __( 'Management Date Types', 'propertyhive' )); break; }
450
451 case "marketing-flag": { $settings = $this->get_custom_fields_marketing_flag_setting(); break; }
452 case "marketing-flag-delete": { $settings = $this->get_custom_fields_delete($current_id, 'marketing_flag', __( 'Marketing Flag', 'propertyhive' )); break; }
453
454 case "property-feature": { $settings = $this->get_custom_fields_property_feature_setting(); break; }
455 case "property-feature-delete": { $settings = $this->get_custom_fields_delete($current_id, 'property_feature', __( 'Property Feature', 'propertyhive' )); break; }
456
457 default:
458 {
459 $settings = apply_filters( 'propertyhive_custom_fields_section_settings', array(), $current_section );
460
461 if ( empty($settings) )
462 {
463 echo 'UNKNOWN CUSTOM FIELD';
464 }
465 }
466 }
467
468 if ( strpos($current_section, '-delete') === FALSE )
469 {
470 $redirect_after_save = admin_url('admin.php?page=ph-settings&tab=customfields&section=' . $current_section);
471 }
472
473 PH_Admin_Settings::output_fields( $settings );
474 }
475 else
476 {
477 global $hide_save_button;
478
479 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
480 $hide_save_button = true;
481
482 // The main custom field screen listing them in a table
483 $settings = $this->get_custom_fields_setting($current_section);
484
485 PH_Admin_Settings::output_fields( $settings );
486 }
487 }
488 }
489 }
490 else
491 {
492 $settings = $this->get_settings();
493
494 PH_Admin_Settings::output_fields( $settings );
495 }
496 }
497
498 public function get_custom_fields_additional_field_settings()
499 {
500 global $current_section;
501
502 $current_settings = get_option( 'propertyhive_template_assistant', array() );
503
504 if ( !isset($current_settings['custom_fields']) )
505 {
506 $current_settings['custom_fields'] = array();
507 }
508
509 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
510 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
511
512 $custom_field_details = array();
513
514 if ($current_id != '')
515 {
516 $custom_fields = $current_settings['custom_fields'];
517
518 if (isset($custom_fields[$current_id]))
519 {
520 $custom_field_details = $custom_fields[$current_id];
521 }
522 else
523 {
524 die('Trying to edit an additional field which does not exist. Please go back and try again.');
525 }
526 }
527
528 $settings = array(
529
530 array( 'title' => ( $current_section == 'addadditionalfield' ? __( 'Add Additional Field', 'propertyhive' ) : __( 'Edit Additional Field', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'customfield' ),
531
532 );
533
534 $settings[] = array(
535 'title' => __( 'Field Label', 'propertyhive' ),
536 'id' => 'field_label',
537 'default' => ( (isset($custom_field_details['field_label'])) ? $custom_field_details['field_label'] : ''),
538 'type' => 'text',
539 'desc_tip' => false,
540 'custom_attributes' => array(
541 'placeholder' => 'My New Field'
542 )
543 );
544
545 if ( isset($custom_field_details['field_name']) )
546 {
547 $settings[] = array(
548 'title' => __( 'Field Name', 'propertyhive' ),
549 'id' => 'field_name',
550 'default' => ( (isset($custom_field_details['field_name'])) ? $custom_field_details['field_name'] : ''),
551 'type' => 'text',
552 'desc' => __( 'Please note that changing this after properties have been saved will result in any data entered being lost', 'propertyhive' ),
553 );
554 }
555
556 $settings[] = array(
557 'title' => __( 'Field Type', 'propertyhive' ),
558 'id' => 'field_type',
559 'default' => ( (isset($custom_field_details['field_type'])) ? $custom_field_details['field_type'] : 'text'),
560 'type' => 'select',
561 'desc_tip' => false,
562 'options' => array(
563 'text' => 'Text',
564 'textarea' => 'Textarea',
565 'select' => 'Dropdown',
566 'multiselect' => 'Multi-Select',
567 'checkbox' => 'Checkbox',
568 'date' => 'Date',
569 'image' => 'Image',
570 'file' => 'File',
571 )
572 );
573
574 $settings[] = array(
575 'title' => __( 'Dropdown Options', 'propertyhive' ),
576 'id' => 'dropdown_options',
577 'type' => 'additional_field_dropdown_options',
578 );
579
580 $options = array(
581 'property_address' => 'Property Address',
582 'property_department' => 'Property Department',
583 );
584
585 if ( get_option( 'propertyhive_active_departments_sales', '' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings', '' ) == 'yes' )
586 {
587 $options['property_residential_details'] = __( 'Property Residential Details', 'propertyhive' );
588
589 if ( get_option( 'propertyhive_active_departments_sales', '' ) == 'yes' )
590 {
591 $options['property_residential_sales_details'] = __( 'Property Residential Sales Details', 'propertyhive' );
592 }
593 if ( get_option( 'propertyhive_active_departments_lettings', '' ) == 'yes' )
594 {
595 $options['property_residential_lettings_details'] = __( 'Property Residential Lettings Details', 'propertyhive' );
596 }
597 }
598
599 if ( get_option( 'propertyhive_active_departments_commercial', '' ) == 'yes' )
600 {
601 $options['property_commercial_details'] = __( 'Property Commercial Details', 'propertyhive' );
602 }
603
604 $options['property_marketing'] = __( 'Property Marketing', 'propertyhive' );
605
606 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
607 {
608 $options['contact_correspondence_address'] = __( 'Contact Correspondence Address', 'propertyhive' );
609 $options['contact_contact_details'] = __( 'Contact Contact Details', 'propertyhive' );
610 }
611
612 if ( get_option('propertyhive_module_disabled_enquiries', '') != 'yes' )
613 {
614 $options['enquiry_record_details'] = __( 'Enquiry Record Details', 'propertyhive' );
615 }
616
617 if ( get_option('propertyhive_module_disabled_appraisals', '') != 'yes' )
618 {
619 $options['appraisal_details'] = __( 'Appraisal Details', 'propertyhive' );
620 $options['appraisal_event'] = __( 'Appraisal Event Details', 'propertyhive' );
621 }
622
623 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
624 {
625 $options['viewing_details'] = __( 'Viewing Details', 'propertyhive' );
626 $options['viewing_event'] = __( 'Viewing Event Details', 'propertyhive' );
627 }
628
629 if ( get_option('propertyhive_module_disabled_offers_sales', '') != 'yes' )
630 {
631 $options['offer_details'] = __( 'Offer Details', 'propertyhive' );
632 $options['sale_details'] = __( 'Sale Details', 'propertyhive' );
633 }
634
635 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' && get_option('propertyhive_module_disabled_tenancies', '') != 'yes' )
636 {
637 $options['tenancy_details'] = __( 'Tenancy Details', 'propertyhive' );
638 $options['tenancy_management_details'] = __( 'Tenancy Management Details', 'propertyhive' );
639 $options['tenancy_deposit_scheme'] = __( 'Tenancy Deposit Scheme Details', 'propertyhive' );
640 $options['tenancy_meter_readings'] = __( 'Tenancy Meter Readings', 'propertyhive' );
641 }
642
643 $options['office_details'] = __( 'Office Details', 'propertyhive' );
644
645 $options = apply_filters( 'propertyhive_template_assistant_custom_field_sections', $options );
646
647 $settings[] = array(
648 'title' => __( 'Section', 'propertyhive' ),
649 'id' => 'meta_box',
650 'default' => ( (isset($custom_field_details['meta_box'])) ? $custom_field_details['meta_box'] : ''),
651 'type' => 'select',
652 'desc' => __( 'Please select which meta box on the property record this field should appear in', 'propertyhive' ),
653 'options' => $options
654 );
655
656 $settings[] = array(
657 'title' => __( 'Display On Website', 'propertyhive' ),
658 'id' => 'display_on_website',
659 'default' => ( (isset($custom_field_details['display_on_website']) && $custom_field_details['display_on_website'] == '1') ? 'yes' : ''),
660 'type' => 'checkbox',
661 );
662
663 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
664 {
665 $settings[] = array(
666 'title' => __( 'Add As Match Field To Applicant Requirements', 'propertyhive' ),
667 'id' => 'display_on_applicant_requirements',
668 'default' => ( (isset($custom_field_details['display_on_applicant_requirements']) && $custom_field_details['display_on_applicant_requirements'] == '1') ? 'yes' : ''),
669 'type' => 'checkbox',
670 );
671 }
672
673 $settings[] = array(
674 'title' => __( 'Exact Match Only If Searching On Field', 'propertyhive' ),
675 'id' => 'exact_match',
676 'default' => ( (isset($custom_field_details['exact_match']) && $custom_field_details['exact_match'] == '1') ? 'yes' : ''),
677 'type' => 'checkbox',
678 'desc' => __( 'If you\'re using this checkbox in property searches or matches tick this if properties should only be returned with the same ticked status. Alternatively, leave unticked for scenarios like \'Pets Allowed\' whereby properties with it ticked should come back whether search is ticked or not, but not vice versa.', 'propertyhive' ),
679 );
680
681 $settings[] = array(
682 'title' => __( 'Display On Registration Form / My Account', 'propertyhive' ),
683 'id' => 'display_on_user_details',
684 'default' => ( (isset($custom_field_details['display_on_user_details']) && $custom_field_details['display_on_user_details'] == '1') ? 'yes' : ''),
685 'type' => 'checkbox',
686 );
687
688 $settings[] = array(
689 'title' => __( 'Show In Admin List', 'propertyhive' ),
690 'id' => 'admin_list',
691 'default' => ( (isset($custom_field_details['admin_list']) && $custom_field_details['admin_list'] == '1') ? 'yes' : ''),
692 'type' => 'checkbox',
693 );
694
695 $settings[] = array(
696 'title' => __( 'Sortable In Admin List', 'propertyhive' ),
697 'id' => 'admin_list_sortable',
698 'default' => ( (isset($custom_field_details['admin_list_sortable']) && $custom_field_details['admin_list_sortable'] == '1') ? 'yes' : ''),
699 'type' => 'checkbox',
700 );
701
702 $settings[] = array( 'type' => 'sectionend', 'id' => 'customfield');
703
704 $settings[] = array(
705 'type' => 'html',
706 'html' => '<script>
707
708 jQuery(document).ready(function()
709 {
710 ph_hide_show_type_related_checkboxes();
711
712 jQuery(\'#meta_box\').change(function()
713 {
714 ph_hide_show_type_related_checkboxes();
715 });
716
717 jQuery(\'#field_type\').change(function()
718 {
719 ph_hide_show_type_related_checkboxes();
720 });
721 });
722
723 function ph_hide_show_type_related_checkboxes()
724 {
725 var meta_box = jQuery(\'#meta_box\').val();
726
727 jQuery(\'#row_display_on_website\').hide();
728 jQuery(\'#row_display_on_applicant_requirements\').hide();
729 jQuery(\'#row_display_on_user_details\').hide();
730 jQuery(\'#row_exact_match\').hide();
731
732 jQuery(\'#row_admin_list\').show();
733 jQuery(\'#row_admin_list_sortable\').show();
734
735 if ( meta_box.indexOf(\'property_\') != -1 )
736 {
737 jQuery(\'#row_display_on_website\').show();
738
739 if ( jQuery(\'#field_type\').val() == \'select\' || jQuery(\'#field_type\').val() == \'multiselect\' || jQuery(\'#field_type\').val() == \'checkbox\' )
740 {
741 jQuery(\'#row_display_on_applicant_requirements\').show();
742 }
743
744 if ( jQuery(\'#field_type\').val() == \'checkbox\' )
745 {
746 jQuery(\'#row_exact_match\').show();
747 }
748 }
749 if ( meta_box.indexOf(\'contact_\') != -1 )
750 {
751 jQuery(\'#row_display_on_user_details\').show();
752 }
753 if ( meta_box == \'tenancy_management_details\' )
754 {
755 jQuery(\'#row_admin_list\').hide();
756 jQuery(\'#row_admin_list_sortable\').hide();
757 }
758 }
759
760 </script>'
761 );
762
763 return $settings;
764 }
765
766 public function additional_field_dropdown_options()
767 {
768 $current_settings = get_option( 'propertyhive_template_assistant', array() );
769
770 if ( !isset($current_settings['custom_fields']) )
771 {
772 $current_settings['custom_fields'] = array();
773 }
774
775 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
776 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
777
778 $custom_field_details = array();
779
780 if ($current_id != '')
781 {
782 $custom_fields = $current_settings['custom_fields'];
783
784 if (isset($custom_fields[$current_id]))
785 {
786 $custom_field_details = $custom_fields[$current_id];
787 }
788 else
789 {
790 die('Trying to edit an additional field which does not exist. Please go back and try again.');
791 }
792 }
793
794 echo '
795 <tr valign="top" id="row_dropdown_options">
796 <th scope="row" class="titledesc">
797 <label for="field_type">Dropdown Options</label>
798 </th>
799 <td class="forminp forminp-dropdown-options"><div id="sortable_options_' . esc_attr( $current_id ) . '">';
800 if ( isset($custom_field_details['dropdown_options']) && !empty($custom_field_details['dropdown_options']) )
801 {
802 foreach ( $custom_field_details['dropdown_options'] as $dropdown_option )
803 {
804 echo '
805 <div><i class="fa fa-reorder" style="cursor:pointer; opacity:0.3"></i> <input type="text" name="dropdown_options[]" value="' . esc_attr( $dropdown_option ) . '"> <a href="" class="delete-dropdown-option">Delete Option</a></div>
806 ';
807 }
808 }
809 else
810 {
811 // None exist
812 echo '
813 <div><i class="fa fa-reorder" style="cursor:pointer; opacity:0.3"></i> <input type="text" name="dropdown_options[]" placeholder="Add Option"> <a href="" class="delete-dropdown-option">Delete Option</a></div>
814 ';
815 }
816 echo '
817 </div>
818 <a href="" class="add-dropdown-option">Add New Option</a>
819 </td>
820 </tr>
821
822 <script>
823 jQuery(document).ready(function()
824 {
825 toggle_dropdown_options();
826
827 jQuery(\'#field_type\').change(function()
828 {
829 toggle_dropdown_options();
830 });
831
832 jQuery(\'body\').on(\'click\', \'a.add-dropdown-option\', function(e)
833 {
834 e.preventDefault();
835
836 jQuery(\'.forminp-dropdown-options > div\').append(\'<div><i class="fa fa-reorder" style="cursor:pointer; opacity:0.3"></i> <input type="text" name="dropdown_options[]" placeholder="Add Option"> <a href="" class="delete-dropdown-option">Delete Option</a></div>\');
837 });
838
839 jQuery(\'body\').on(\'click\', \'a.delete-dropdown-option\', function(e)
840 {
841 e.preventDefault();
842
843 var confirmBox = confirm(\'Are you sure you wish to delete this option?\');
844
845 if ( confirmBox )
846 {
847 jQuery(this).parent().remove();
848 }
849 });
850
851 jQuery( \'#sortable_options_' . esc_js( $current_id ) . '\' )
852 .sortable({
853 axis: "y",
854 handle: "i",
855 stop: function( event, ui )
856 {
857 // IE doesn\'t register the blur when sorting
858 // so trigger focusout handlers to remove .ui-state-focus
859 //ui.item.children( "h3" ).triggerHandler( "focusout" );
860
861 // Refresh accordion to handle new order
862 //jQuery( this ).accordion( "refresh" );
863 },
864 update: function( event, ui )
865 {
866 // Update hidden fields
867 var fields_order = jQuery(this).sortable(\'toArray\');
868
869 //$(\'#active_fields_order\').val( fields_order.join("|") );
870 }
871 });
872 });
873
874 function toggle_dropdown_options()
875 {
876 if ( jQuery(\'#field_type\').val() == \'select\' || jQuery(\'#field_type\').val() == \'multiselect\' )
877 {
878 jQuery(\'#row_dropdown_options\').show();
879 }
880 else
881 {
882 jQuery(\'#row_dropdown_options\').hide();
883 }
884 }
885 </script>
886 ';
887 }
888
889 public function get_custom_fields_additional_fields_setting()
890 {
891 return apply_filters( 'propertyhive_custom_fields_settings', array(
892
893 array( 'title' => __( 'Additional Fields', 'propertyhive' ), 'type' => 'title', 'desc' => __( 'Create new fields to store information not included by default.', 'propertyhive' ), 'id' => 'additional_field_options' ),
894
895 array(
896 'type' => 'additional_fields_table',
897 ),
898
899 array( 'type' => 'sectionend', 'id' => 'additional_field_options')
900
901 ));
902 }
903
904 /**
905 * Output list of additional fields
906 *
907 * @access public
908 * @return void
909 */
910 public function additional_fields_table() {
911 global $wpdb, $post;
912
913 $current_settings = get_option( 'propertyhive_template_assistant', array() );
914 $custom_fields = array();
915 if ($current_settings !== FALSE)
916 {
917 if (isset($current_settings['custom_fields']))
918 {
919 $custom_fields = $current_settings['custom_fields'];
920 }
921 }
922 ?>
923 <tr valign="top">
924 <td class="forminp forminp-button">
925 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=addadditionalfield' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Field', 'propertyhive' )); ?></a>
926 </td>
927 </tr>
928 <tr valign="top">
929 <td class="forminp">
930 <style type="text/css">
931 .ui-sortable-helper {
932 display: table;
933 }
934 </style>
935 <table class="ph_additional_fields widefat" cellspacing="0">
936 <thead>
937 <tr>
938 <th style="padding:8px 10px;" class="field-label"><?php esc_html_e( 'Field Name', 'propertyhive' ); ?></th>
939 <th style="padding:8px 10px;" class="section"><?php esc_html_e( 'Section', 'propertyhive' ); ?></th>
940 <th style="padding:8px 10px;" class="usage"><?php esc_html_e( 'Usage', 'propertyhive' ); ?></th>
941 <th style="padding:8px 10px;" class="website"><?php esc_html_e( 'Display On Website', 'propertyhive' ); ?></th>
942 <th style="padding:8px 10px;" class="admin-list"><?php esc_html_e( 'Show In Admin List', 'propertyhive' ); ?></th>
943 <th style="padding:8px 10px;" class="admin-list-sorting"><?php esc_html_e( 'Sortable In Admin List', 'propertyhive' ); ?></th>
944 <th style="padding:8px 10px;" class="settings">&nbsp;</th>
945 </tr>
946 </thead>
947 <tbody class="<?php echo !empty($custom_fields) ? 'has-rows' : ''; ?>">
948 <?php
949
950 if (!empty($custom_fields))
951 {
952 foreach ($custom_fields as $id => $custom_field)
953 {
954 echo '<tr id="custom_field_' . esc_attr($id) . '">';
955 echo '<td class="field-label"><span class="sort_anchor" style="cursor:grab "> �
956 </span>' . esc_html($custom_field['field_label']) . '</td>';
957 echo '<td class="section">' . esc_html(ucwords( str_replace("_", " ", $custom_field['meta_box']) )) . '</td>';
958 echo '<td class="usage">';
959 if ( substr( $custom_field['meta_box'], 0, 8 ) == 'property' ) { echo '<pre style="background:#EEE; padding:5px; display:inline">&lt;?php $property->' . esc_html(ltrim( $custom_field['field_name'], '_' )) . '; ?&gt;</pre>'; }else{ echo '-';}
960 echo '</td>';
961 echo '<td class="website">';
962 if ( substr( $custom_field['meta_box'], 0, 8 ) == 'property' ) { echo esc_html( ( ( isset($custom_field['display_on_website']) && $custom_field['display_on_website'] == '1' ) ? __( 'Yes', 'propertyhive' ) : __( 'No', 'propertyhive' ) ) ); }else{ echo '-'; }
963 echo '</td>';
964 echo '<td class="admin-list">';
965 echo esc_html( ( ( isset($custom_field['admin_list']) && $custom_field['admin_list'] == '1' ) ? __( 'Yes', 'propertyhive' ) : __( 'No', 'propertyhive' ) ) );
966 echo '</td>';
967 echo '<td class="sorting">';
968 if ( ( isset($custom_field['admin_list']) && $custom_field['admin_list'] == '1' ) )
969 {
970 echo esc_html( ( ( isset($custom_field['admin_list_sortable']) && $custom_field['admin_list_sortable'] == '1' ) ? __( 'Yes', 'propertyhive' ) : __( 'No', 'propertyhive' ) ) );
971 }
972 else
973 {
974 echo '-';
975 }
976 echo '</td>';
977
978 $delete_url = wp_nonce_url(
979 admin_url(
980 'admin.php?page=ph-settings&tab=customfields&section=additional&action=deleteadditionalfield&id=' . rawurlencode( $id )
981 ),
982 'propertyhive_delete_additional_field'
983 );
984
985 echo '<td class="settings">
986 <a class="button" href="' . esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=editadditionalfield&id=' . $id )) . '">' . esc_html(__( 'Edit Field', 'propertyhive' )) . '</a>
987 <a class="button" href="' . esc_url( $delete_url ) . '" onclick="var confirmBox = confirm(\'Are you sure you wish to delete this custom field?\'); return confirmBox;">' . esc_html(__( 'Delete', 'propertyhive' )) . '</a>
988 </td>';
989 echo '</tr>';
990 }
991 }
992 else
993 {
994 echo '<tr>';
995 echo '<td align="center" colspan="7">' . esc_html(__( 'No additional fields exist', 'propertyhive' )) . '</td>';
996 echo '</tr>';
997 }
998 ?>
999 </tbody>
1000 </table>
1001
1002 <script>
1003 jQuery( function($){
1004
1005 $('.ph_additional_fields tbody.has-rows').sortable({
1006 opacity: 0.8,
1007 revert: true,
1008 handle: ".sort_anchor",
1009 update : function (event, ui)
1010 {
1011 $('.ph_additional_fields tbody.has-rows').sortable( "destroy" );
1012
1013 var new_order = '';
1014 jQuery('.ph_additional_fields tbody.has-rows').find('tr').each( function ()
1015 {
1016 if (new_order != '')
1017 {
1018 new_order += ',';
1019 }
1020 new_order = new_order + jQuery(this).attr('id').replace('custom_field_', '');
1021 });
1022
1023 // reload page
1024 window.location.href = <?php echo wp_json_encode( add_query_arg( '_wpnonce', wp_create_nonce( 'propertyhive_reorder_additional_fields' ), admin_url( 'admin.php?page=ph-settings&tab=customfields&section=additional' ) ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); ?> + '&neworder=' + encodeURIComponent( new_order );
1025 }
1026 });
1027
1028 });
1029 </script>
1030 </td>
1031 </tr>
1032 <tr valign="top">
1033 <td class="forminp forminp-button">
1034 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=addadditionalfield' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Field', 'propertyhive' )); ?></a>
1035 </td>
1036 </tr>
1037 <?php
1038 }
1039
1040 /**
1041 * Output custom fields settings.
1042 *
1043 * @access public
1044 * @return void
1045 */
1046 public function get_custom_fields_setting($current_section) {
1047
1048 $sections = $this->custom_field_sections;
1049
1050 return apply_filters( 'propertyhive_custom_fields_' . $current_section . '_settings', array(
1051
1052 array( 'title' => $sections[$current_section], 'type' => 'title', 'desc' => '', 'id' => 'custom_fields_' . $current_section . '_options' ),
1053
1054 array(
1055 'type' => 'custom_fields_' . str_replace("-", "_", $current_section),
1056 ),
1057
1058 array( 'type' => 'sectionend', 'id' => 'custom_fields_' . $current_section . '_options'),
1059
1060 ));
1061
1062 }
1063
1064 /**
1065 * Output list of availabilities
1066 *
1067 * @access public
1068 * @return void
1069 */
1070 public function custom_fields_availability_setting() {
1071 global $post;
1072
1073 $departments = ph_get_departments();
1074
1075 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
1076 if ( !is_array($availability_departments) ) { $availability_departments = array(); }
1077 ?>
1078 <tr valign="top">
1079 <th scope="row" class="titledesc">
1080 &nbsp;
1081 </th>
1082 <td class="forminp forminp-button">
1083 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1084 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Availability', 'propertyhive' )); ?></a>
1085 </td>
1086 </tr>
1087 <tr valign="top">
1088 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Availability Options', 'propertyhive' )); ?></th>
1089 <td class="forminp">
1090 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="availability" cellspacing="0">
1091 <thead>
1092 <tr>
1093 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1094 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1095 <?php do_action( 'propertyhive_custom_field_availability_table_before_header_column' ); ?>
1096 <th class="type"><?php echo esc_html(__( 'Availability', 'propertyhive' )); ?></th>
1097 <th class="department"><?php echo esc_html(__( 'Applies To', 'propertyhive' )); ?></th>
1098 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1099 <th class="settings">&nbsp;</th>
1100 </tr>
1101 </thead>
1102 <tbody>
1103 <?php
1104 $args = array(
1105 'hide_empty' => false,
1106 'parent' => 0
1107 );
1108 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'availability' ) ) );
1109
1110 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1111 {
1112 foreach ( $terms as $term )
1113 {
1114 ?>
1115 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1116 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1117 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1118 <?php do_action( 'propertyhive_custom_field_availability_table_before_row_column', $term->term_id ); ?>
1119 <td class="type"><?php echo esc_html($term->name); ?></td>
1120 <td class="department"><?php
1121 $this_availability_departments = array();
1122 if ( isset($availability_departments[$term->term_id]) )
1123 {
1124 foreach ( $availability_departments[$term->term_id] as $availability_department )
1125 {
1126 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $availability_department) ) == 'yes' )
1127 {
1128 $this_availability_departments[] = $departments[$availability_department];
1129 }
1130 }
1131 }
1132 else
1133 {
1134 foreach ( $departments as $key => $value )
1135 {
1136 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
1137 {
1138 $this_availability_departments[] = $value;
1139 }
1140 }
1141 }
1142
1143 echo !empty($this_availability_departments) ? esc_html(implode(", ", $this_availability_departments)) : '-';
1144 ?></td>
1145 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1146 <td class="settings">
1147 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1148 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1149 </td>
1150 </tr>
1151 <?php
1152 }
1153 }
1154 else
1155 {
1156 ?>
1157 <tr>
1158 <td colspan="6"><?php echo esc_html(__( 'No availability options found', 'propertyhive' )); ?></td>
1159 </tr>
1160 <?php
1161 }
1162 ?>
1163 </tbody>
1164 </table>
1165 </td>
1166 </tr>
1167 <tr valign="top">
1168 <th scope="row" class="titledesc">
1169 &nbsp;
1170 </th>
1171 <td class="forminp forminp-button">
1172 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1173 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Availability', 'propertyhive' )); ?></a>
1174 </td>
1175 </tr>
1176 <?php
1177 }
1178
1179 /**
1180 * Output list of residential property types
1181 *
1182 * @access public
1183 * @return void
1184 */
1185 public function custom_fields_property_type_setting() {
1186 global $post;
1187 ?>
1188 <tr valign="top">
1189 <th scope="row" class="titledesc">
1190 &nbsp;
1191 </th>
1192 <td class="forminp forminp-button">
1193 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1194 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Type', 'propertyhive' )); ?></a>
1195 </td>
1196 </tr>
1197 <tr valign="top">
1198 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Types', 'propertyhive' )); ?></th>
1199 <td class="forminp">
1200 <table class="ph_customfields widefat" cellspacing="0">
1201 <thead>
1202 <tr>
1203 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1204 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1205 <?php do_action( 'propertyhive_custom_field_property_type_table_before_header_column' ); ?>
1206 <th class="type"><?php echo esc_html(__( 'Property Type', 'propertyhive' )); ?></th>
1207 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1208 <th class="settings">&nbsp;</th>
1209 </tr>
1210 </thead>
1211 <tbody>
1212 <?php
1213 $args = array(
1214 'hide_empty' => false,
1215 'parent' => 0
1216 );
1217 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
1218
1219 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1220 {
1221 foreach ($terms as $term)
1222 {
1223 $parent_term_id = $term->term_id;
1224
1225 $args = array(
1226 'hide_empty' => false,
1227 'parent' => $parent_term_id
1228 );
1229 $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
1230 ?>
1231 <tr>
1232 <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1233 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1234 <?php do_action( 'propertyhive_custom_field_property_type_table_before_row_column', $term->term_id ); ?>
1235 <td class="type"><?php echo esc_html($term->name); ?></td>
1236 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1237 <td class="settings">
1238 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1239 <?php if ( empty( $subterms ) ) { ?>
1240 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1241 <?php } ?>
1242 </td>
1243 </tr>
1244 <?php
1245 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1246 {
1247 foreach ($subterms as $term)
1248 {
1249 ?>
1250 <tr>
1251 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1252 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1253 <?php do_action( 'propertyhive_custom_field_property_type_table_before_row_column', $term->term_id, $parent_term_id ); ?>
1254 <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1255 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1256 <td class="settings">
1257 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1258 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1259 </td>
1260 </tr>
1261 <?php
1262 }
1263 }
1264 ?>
1265 <?php
1266 }
1267 }
1268 else
1269 {
1270 ?>
1271 <tr>
1272 <td colspan="5"><?php echo esc_html(__( 'No property types found', 'propertyhive' )); ?></td>
1273 </tr>
1274 <?php
1275 }
1276 ?>
1277 </tbody>
1278 </table>
1279 </td>
1280 </tr>
1281 <tr valign="top">
1282 <th scope="row" class="titledesc">
1283 &nbsp;
1284 </th>
1285 <td class="forminp forminp-button">
1286 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1287 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Type', 'propertyhive' )); ?></a>
1288 </td>
1289 </tr>
1290 <?php
1291 }
1292
1293 /**
1294 * Output list of commercial property types
1295 *
1296 * @access public
1297 * @return void
1298 */
1299 public function custom_fields_commercial_property_type_setting() {
1300 global $post;
1301 ?>
1302 <tr valign="top">
1303 <th scope="row" class="titledesc">
1304 &nbsp;
1305 </th>
1306 <td class="forminp forminp-button">
1307 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1308 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Type', 'propertyhive' )); ?></a>
1309 </td>
1310 </tr>
1311 <tr valign="top">
1312 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Types', 'propertyhive' )); ?></th>
1313 <td class="forminp">
1314 <table class="ph_customfields widefat" cellspacing="0">
1315 <thead>
1316 <tr>
1317 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1318 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1319 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_header_column' ); ?>
1320 <th class="type"><?php echo esc_html(__( 'Property Type', 'propertyhive' )); ?></th>
1321 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1322 <th class="settings">&nbsp;</th>
1323 </tr>
1324 </thead>
1325 <tbody>
1326 <?php
1327 $args = array(
1328 'hide_empty' => false,
1329 'parent' => 0
1330 );
1331 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
1332
1333 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1334 {
1335 foreach ($terms as $term)
1336 {
1337 $parent_term_id = $term->term_id;
1338
1339 $args = array(
1340 'hide_empty' => false,
1341 'parent' => $parent_term_id
1342 );
1343 $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
1344 ?>
1345 <tr>
1346 <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1347 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1348 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_row_column', $term->term_id ); ?>
1349 <td class="type"><?php echo esc_html($term->name); ?></td>
1350 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1351 <td class="settings">
1352 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1353 <?php if ( empty( $subterms ) ) { ?>
1354 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1355 <?php } ?>
1356 </td>
1357 </tr>
1358 <?php
1359 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1360 {
1361 foreach ($subterms as $term)
1362 {
1363 ?>
1364 <tr>
1365 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1366 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1367 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_row_column', $term->term_id, $parent_term_id ); ?>
1368 <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1369 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1370 <td class="settings">
1371 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1372 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1373 </td>
1374 </tr>
1375 <?php
1376 }
1377 }
1378 ?>
1379 <?php
1380 }
1381 }
1382 else
1383 {
1384 ?>
1385 <tr>
1386 <td colspan="5"><?php echo esc_html(__( 'No property types found', 'propertyhive' )); ?></td>
1387 </tr>
1388 <?php
1389 }
1390 ?>
1391 </tbody>
1392 </table>
1393 </td>
1394 </tr>
1395 <tr valign="top">
1396 <th scope="row" class="titledesc">
1397 &nbsp;
1398 </th>
1399 <td class="forminp forminp-button">
1400 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1401 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Type', 'propertyhive' )); ?></a>
1402 </td>
1403 </tr>
1404 <?php
1405 }
1406
1407 /**
1408 * Output list of locations
1409 *
1410 * @access public
1411 * @return void
1412 */
1413 public function custom_fields_location_setting() {
1414 global $post;
1415 ?>
1416 <tr valign="top">
1417 <th scope="row" class="titledesc">
1418 &nbsp;
1419 </th>
1420 <td class="forminp forminp-button">
1421 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1422 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Location', 'propertyhive' )); ?></a>
1423 </td>
1424 </tr>
1425 <tr valign="top">
1426 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Locations', 'propertyhive' )); ?></th>
1427 <td class="forminp">
1428 <table class="ph_customfields widefat" cellspacing="0">
1429 <thead>
1430 <tr>
1431 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1432 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1433 <th class="type"><?php echo esc_html(__( 'Location', 'propertyhive' )); ?></th>
1434 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1435 <th class="settings">&nbsp;</th>
1436 </tr>
1437 </thead>
1438 <tbody>
1439 <?php
1440 $args = array(
1441 'hide_empty' => false,
1442 'parent' => 0
1443 );
1444 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
1445
1446 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1447 {
1448 foreach ($terms as $term)
1449 {
1450 $args = array(
1451 'hide_empty' => false,
1452 'parent' => $term->term_id
1453 );
1454 $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
1455 ?>
1456 <tr>
1457 <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1458 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1459 <td class="type"><?php echo esc_html($term->name); ?></td>
1460 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1461 <td class="settings">
1462 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1463 <?php if ( empty( $subterms ) ) { ?>
1464 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1465 <?php } ?>
1466 </td>
1467 </tr>
1468 <?php
1469 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1470 {
1471 foreach ($subterms as $term)
1472 {
1473 $args = array(
1474 'hide_empty' => false,
1475 'parent' => $term->term_id
1476 );
1477 $subsubterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
1478 ?>
1479 <tr>
1480 <td class="cb"><?php if ( empty( $subsubterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1481 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1482 <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1483 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1484 <td class="settings">
1485 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1486 <?php if ( empty( $subsubterms ) ) { ?>
1487 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1488 <?php } ?>
1489 </td>
1490 </tr>
1491 <?php
1492 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1493 {
1494 foreach ($subsubterms as $term)
1495 {
1496 ?>
1497 <tr>
1498 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1499 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1500 <td class="type subtype">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1501 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1502 <td class="settings">
1503 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1504 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1505 </td>
1506 </tr>
1507 <?php
1508 }
1509 }
1510 }
1511 }
1512 ?>
1513 <?php
1514 }
1515 }
1516 else
1517 {
1518 ?>
1519 <tr>
1520 <td colspan="5"><?php echo esc_html(__( 'No locations found', 'propertyhive' )); ?></td>
1521 </tr>
1522 <?php
1523 }
1524 ?>
1525 </tbody>
1526 </table>
1527 </td>
1528 </tr>
1529 <tr valign="top">
1530 <th scope="row" class="titledesc">
1531 &nbsp;
1532 </th>
1533 <td class="forminp forminp-button">
1534 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1535 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Location', 'propertyhive' )); ?></a>
1536 </td>
1537 </tr>
1538 <?php
1539 }
1540
1541 /**
1542 * Output list of parking
1543 *
1544 * @access public
1545 * @return void
1546 */
1547 public function custom_fields_parking_setting() {
1548 global $post;
1549 ?>
1550 <tr valign="top">
1551 <th scope="row" class="titledesc">
1552 &nbsp;
1553 </th>
1554 <td class="forminp forminp-button">
1555 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1556 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Parking', 'propertyhive' )); ?></a>
1557 </td>
1558 </tr>
1559 <tr valign="top">
1560 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Parking Options', 'propertyhive' )); ?></th>
1561 <td class="forminp">
1562 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="parking" cellspacing="0">
1563 <thead>
1564 <tr>
1565 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1566 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1567 <th class="type"><?php echo esc_html(__( 'Parking', 'propertyhive' )); ?></th>
1568 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1569 <th class="settings">&nbsp;</th>
1570 </tr>
1571 </thead>
1572 <tbody>
1573 <?php
1574 $args = array(
1575 'hide_empty' => false,
1576 'parent' => 0
1577 );
1578 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'parking' ) ) );
1579
1580 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1581 {
1582 foreach ($terms as $term)
1583 {
1584 ?>
1585 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1586 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1587 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1588 <td class="type"><?php echo esc_html($term->name); ?></td>
1589 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1590 <td class="settings">
1591 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1592 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1593 </td>
1594 </tr>
1595 <?php
1596 }
1597 }
1598 else
1599 {
1600 ?>
1601 <tr>
1602 <td colspan="5"><?php echo esc_html(__( 'No parking options found', 'propertyhive' )); ?></td>
1603 </tr>
1604 <?php
1605 }
1606 ?>
1607 </tbody>
1608 </table>
1609 </td>
1610 </tr>
1611 <tr valign="top">
1612 <th scope="row" class="titledesc">
1613 &nbsp;
1614 </th>
1615 <td class="forminp forminp-button">
1616 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1617 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Parking', 'propertyhive' )); ?></a>
1618 </td>
1619 </tr>
1620 <?php
1621 }
1622
1623 /**
1624 * Output list of outside spaces
1625 *
1626 * @access public
1627 * @return void
1628 */
1629 public function custom_fields_outside_space_setting() {
1630 global $post;
1631 ?>
1632 <tr valign="top">
1633 <th scope="row" class="titledesc">
1634 &nbsp;
1635 </th>
1636 <td class="forminp forminp-button">
1637 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1638 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Outside Space', 'propertyhive' )); ?></a>
1639 </td>
1640 </tr>
1641 <tr valign="top">
1642 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Outside Spaces', 'propertyhive' )); ?></th>
1643 <td class="forminp">
1644 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="outside_space" cellspacing="0">
1645 <thead>
1646 <tr>
1647 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1648 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1649 <th class="type"><?php echo esc_html(__( 'Outside Space', 'propertyhive' )); ?></th>
1650 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1651 <th class="settings">&nbsp;</th>
1652 </tr>
1653 </thead>
1654 <tbody>
1655 <?php
1656 $args = array(
1657 'hide_empty' => false,
1658 'parent' => 0
1659 );
1660 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'outside_space' ) ) );
1661
1662 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1663 {
1664 foreach ($terms as $term)
1665 {
1666 ?>
1667 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1668 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1669 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1670 <td class="type"><?php echo esc_html($term->name); ?></td>
1671 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1672 <td class="settings">
1673 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1674 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1675 </td>
1676 </tr>
1677 <?php
1678 }
1679 }
1680 else
1681 {
1682 ?>
1683 <tr>
1684 <td colspan="5"><?php echo esc_html(__( 'No outside spaces found', 'propertyhive' )); ?></td>
1685 </tr>
1686 <?php
1687 }
1688 ?>
1689 </tbody>
1690 </table>
1691 </td>
1692 </tr>
1693 <tr valign="top">
1694 <th scope="row" class="titledesc">
1695 &nbsp;
1696 </th>
1697 <td class="forminp forminp-button">
1698 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1699 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Outside Space', 'propertyhive' )); ?></a>
1700 </td>
1701 </tr>
1702 <?php
1703 }
1704
1705 /**
1706 * Output list of price qualifiers
1707 *
1708 * @access public
1709 * @return void
1710 */
1711 public function custom_fields_price_qualifier_setting() {
1712 global $post;
1713 ?>
1714 <tr valign="top">
1715 <th scope="row" class="titledesc">
1716 &nbsp;
1717 </th>
1718 <td class="forminp forminp-button">
1719 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1720 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Price Qualifier', 'propertyhive' )); ?></a>
1721 </td>
1722 </tr>
1723 <tr valign="top">
1724 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Price Qualifiers', 'propertyhive' )); ?></th>
1725 <td class="forminp">
1726 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="price_qualifier" cellspacing="0">
1727 <thead>
1728 <tr>
1729 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1730 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1731 <th class="type"><?php echo esc_html(__( 'Price Qualifier', 'propertyhive' )); ?></th>
1732 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1733 <th class="settings">&nbsp;</th>
1734 </tr>
1735 </thead>
1736 <tbody>
1737 <?php
1738 $args = array(
1739 'hide_empty' => false,
1740 'parent' => 0
1741 );
1742 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'price_qualifier' ) ) );
1743
1744 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1745 {
1746 foreach ($terms as $term)
1747 {
1748 ?>
1749 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1750 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1751 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1752 <td class="type"><?php echo esc_html($term->name); ?></td>
1753 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1754 <td class="settings">
1755 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1756 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1757 </td>
1758 </tr>
1759 <?php
1760 }
1761 }
1762 else
1763 {
1764 ?>
1765 <tr>
1766 <td colspan="5"><?php echo esc_html(__( 'No price qualifiers found', 'propertyhive' )); ?></td>
1767 </tr>
1768 <?php
1769 }
1770 ?>
1771 </tbody>
1772 </table>
1773 </td>
1774 </tr>
1775 <tr valign="top">
1776 <th scope="row" class="titledesc">
1777 &nbsp;
1778 </th>
1779 <td class="forminp forminp-button">
1780 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1781 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Price Qualifier', 'propertyhive' )); ?></a>
1782 </td>
1783 </tr>
1784 <?php
1785 }
1786
1787 /**
1788 * Output list of sale by options
1789 *
1790 * @access public
1791 * @return void
1792 */
1793 public function custom_fields_sale_by_setting() {
1794 global $post;
1795 ?>
1796 <tr valign="top">
1797 <th scope="row" class="titledesc">
1798 &nbsp;
1799 </th>
1800 <td class="forminp forminp-button">
1801 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1802 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Sale By', 'propertyhive' )); ?></a>
1803 </td>
1804 </tr>
1805 <tr valign="top">
1806 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Sale By Options', 'propertyhive' )); ?></th>
1807 <td class="forminp">
1808 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="sale_by" cellspacing="0">
1809 <thead>
1810 <tr>
1811 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1812 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1813 <th class="type"><?php echo esc_html(__( 'Sale By', 'propertyhive' )); ?></th>
1814 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1815 <th class="settings">&nbsp;</th>
1816 </tr>
1817 </thead>
1818 <tbody>
1819 <?php
1820 $args = array(
1821 'hide_empty' => false,
1822 'parent' => 0
1823 );
1824 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'sale_by' ) ) );
1825
1826 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1827 {
1828 foreach ($terms as $term)
1829 {
1830 ?>
1831 <tr>
1832 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1833 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1834 <td class="type"><?php echo esc_html($term->name); ?></td>
1835 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1836 <td class="settings">
1837 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1838 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1839 </td>
1840 </tr>
1841 <?php
1842 }
1843 }
1844 else
1845 {
1846 ?>
1847 <tr>
1848 <td colspan="5"><?php echo esc_html(__( 'No sale by options found', 'propertyhive' )); ?></td>
1849 </tr>
1850 <?php
1851 }
1852 ?>
1853 </tbody>
1854 </table>
1855 </td>
1856 </tr>
1857 <tr valign="top">
1858 <th scope="row" class="titledesc">
1859 &nbsp;
1860 </th>
1861 <td class="forminp forminp-button">
1862 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1863 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Sale By', 'propertyhive' )); ?></a>
1864 </td>
1865 </tr>
1866 <?php
1867 }
1868
1869 /**
1870 * Output list of residential tenure options
1871 *
1872 * @access public
1873 * @return void
1874 */
1875 public function custom_fields_tenure_setting() {
1876 global $post;
1877 ?>
1878 <tr valign="top">
1879 <th scope="row" class="titledesc">
1880 &nbsp;
1881 </th>
1882 <td class="forminp forminp-button">
1883 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1884 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Tenure', 'propertyhive' )); ?></a>
1885 </td>
1886 </tr>
1887 <tr valign="top">
1888 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Tenures', 'propertyhive' )); ?></th>
1889 <td class="forminp">
1890 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="tenure" cellspacing="0">
1891 <thead>
1892 <tr>
1893 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1894 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1895 <th class="type"><?php echo esc_html(__( 'Tenure', 'propertyhive' )); ?></th>
1896 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1897 <th class="settings">&nbsp;</th>
1898 </tr>
1899 </thead>
1900 <tbody>
1901 <?php
1902 $args = array(
1903 'hide_empty' => false,
1904 'parent' => 0
1905 );
1906 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'tenure' ) ) );
1907
1908 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1909 {
1910 foreach ($terms as $term)
1911 {
1912 ?>
1913 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1914 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1915 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1916 <td class="type"><?php echo esc_html($term->name); ?></td>
1917 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1918 <td class="settings">
1919 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
1920 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
1921 </td>
1922 </tr>
1923 <?php
1924 }
1925 }
1926 else
1927 {
1928 ?>
1929 <tr>
1930 <td colspan="5"><?php echo esc_html(__( 'No tenure found', 'propertyhive' )); ?></td>
1931 </tr>
1932 <?php
1933 }
1934 ?>
1935 </tbody>
1936 </table>
1937 </td>
1938 </tr>
1939 <tr valign="top">
1940 <th scope="row" class="titledesc">
1941 &nbsp;
1942 </th>
1943 <td class="forminp forminp-button">
1944 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1945 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Tenure', 'propertyhive' )); ?></a>
1946 </td>
1947 </tr>
1948 <?php
1949 }
1950
1951 /**
1952 * Output list of commercial tenure options
1953 *
1954 * @access public
1955 * @return void
1956 */
1957 public function custom_fields_commercial_tenure_setting() {
1958 global $post;
1959 ?>
1960 <tr valign="top">
1961 <th scope="row" class="titledesc">
1962 &nbsp;
1963 </th>
1964 <td class="forminp forminp-button">
1965 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1966 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Tenure', 'propertyhive' )); ?></a>
1967 </td>
1968 </tr>
1969 <tr valign="top">
1970 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Tenures', 'propertyhive' )); ?></th>
1971 <td class="forminp">
1972 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="commercial_tenure" cellspacing="0">
1973 <thead>
1974 <tr>
1975 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1976 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1977 <th class="type"><?php echo esc_html(__( 'Tenure', 'propertyhive' )); ?></th>
1978 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1979 <th class="settings">&nbsp;</th>
1980 </tr>
1981 </thead>
1982 <tbody>
1983 <?php
1984 $args = array(
1985 'hide_empty' => false,
1986 'parent' => 0
1987 );
1988 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_tenure' ) ) );
1989
1990 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1991 {
1992 foreach ($terms as $term)
1993 {
1994 ?>
1995 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1996 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1997 <td class="id"><?php echo esc_html($term->term_id); ?></td>
1998 <td class="type"><?php echo esc_html($term->name); ?></td>
1999 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
2000 <td class="settings">
2001 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
2002 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
2003 </td>
2004 </tr>
2005 <?php
2006 }
2007 }
2008 else
2009 {
2010 ?>
2011 <tr>
2012 <td colspan="5"><?php echo esc_html(__( 'No tenure found', 'propertyhive' )); ?></td>
2013 </tr>
2014 <?php
2015 }
2016 ?>
2017 </tbody>
2018 </table>
2019 </td>
2020 </tr>
2021 <tr valign="top">
2022 <th scope="row" class="titledesc">
2023 &nbsp;
2024 </th>
2025 <td class="forminp forminp-button">
2026 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2027 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Tenure', 'propertyhive' )); ?></a>
2028 </td>
2029 </tr>
2030 <?php
2031 }
2032
2033 /**
2034 * Output list of furnished options
2035 *
2036 * @access public
2037 * @return void
2038 */
2039 public function custom_fields_furnished_setting() {
2040 global $post;
2041 ?>
2042 <tr valign="top">
2043 <th scope="row" class="titledesc">
2044 &nbsp;
2045 </th>
2046 <td class="forminp forminp-button">
2047 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2048 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Furnished Option', 'propertyhive' )); ?></a>
2049 </td>
2050 </tr>
2051 <tr valign="top">
2052 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Furnished Options', 'propertyhive' )); ?></th>
2053 <td class="forminp">
2054 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="furnished" cellspacing="0">
2055 <thead>
2056 <tr>
2057 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2058 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2059 <th class="type"><?php echo esc_html(__( 'Furnished', 'propertyhive' )); ?></th>
2060 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
2061 <th class="settings">&nbsp;</th>
2062 </tr>
2063 </thead>
2064 <tbody>
2065 <?php
2066 $args = array(
2067 'hide_empty' => false,
2068 'parent' => 0
2069 );
2070 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'furnished' ) ) );
2071
2072 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2073 {
2074 foreach ($terms as $term)
2075 {
2076 ?>
2077 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
2078 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2079 <td class="id"><?php echo esc_html($term->term_id); ?></td>
2080 <td class="type"><?php echo esc_html($term->name); ?></td>
2081 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
2082 <td class="settings">
2083 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
2084 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
2085 </td>
2086 </tr>
2087 <?php
2088 }
2089 }
2090 else
2091 {
2092 ?>
2093 <tr>
2094 <td colspan="5"><?php echo esc_html(__( 'No furnished options found', 'propertyhive' )); ?></td>
2095 </tr>
2096 <?php
2097 }
2098 ?>
2099 </tbody>
2100 </table>
2101 </td>
2102 </tr>
2103 <tr valign="top">
2104 <th scope="row" class="titledesc">
2105 &nbsp;
2106 </th>
2107 <td class="forminp forminp-button">
2108 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2109 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Furnished Option', 'propertyhive' )); ?></a>
2110 </td>
2111 </tr>
2112 <?php
2113 }
2114
2115 public function custom_fields_management_key_date_type_setting() {
2116 ?>
2117 <tr valign="top">
2118 <th scope="row" class="titledesc">
2119 &nbsp;
2120 </th>
2121 <td class="forminp forminp-button">
2122 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2123 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=management-key-date-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Management Date Type', 'propertyhive' )); ?></a>
2124 </td>
2125 </tr>
2126 <?php foreach( array ('property_management' => __( 'Property Management', 'propertyhive' ), 'tenancy_management' => __( 'Tenancy Management', 'propertyhive' ) ) as $type => $title): ?>
2127 <tr valign="top">
2128 <th scope="row" class="titledesc no-auto"><?php echo esc_html( $title ); ?></th>
2129 <td class="forminp no-auto">
2130 <table class="ph_customfields widefat" cellspacing="0">
2131 <thead>
2132 <tr>
2133 <th style="width:1px;">&nbsp;</th>
2134 <th style="width:40%;"><?php echo esc_html(__( 'Description', 'propertyhive' )); ?></th>
2135 <th><?php echo esc_html(__( 'Recurrence', 'propertyhive' )); ?></th>
2136 <th>&nbsp;</th>
2137 </tr>
2138 </thead>
2139 <tbody>
2140 <?php
2141 $args = array(
2142 'hide_empty' => false,
2143 'parent' => 0
2144 );
2145 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'management_key_date_type' ) ) );
2146
2147 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2148 {
2149 $recurrence_rules = get_option( 'propertyhive_key_date_type', array() );
2150 $recurrence_rules = is_array( $recurrence_rules ) ? $recurrence_rules : array();
2151
2152 foreach ($terms as $term)
2153 {
2154 $recurrence_type = isset($recurrence_rules[$term->term_id]) ? $recurrence_rules[$term->term_id]['recurrence_type'] : '';
2155
2156 if ( $recurrence_type !== $type)
2157 {
2158 continue;
2159 }
2160
2161
2162 $recurrence_rule = isset($recurrence_rules[$term->term_id]) ? $recurrence_rules[$term->term_id]['recurrence_rule'] : '';
2163 $recurrence = array('FREQ' => '', 'INTERVAL' => '');
2164 foreach (explode(';', $recurrence_rule) as $key_value_pair) {
2165 list($key, $value) = explode('=', $key_value_pair);
2166 $recurrence[$key] = $value;
2167 }
2168
2169 $frequency = '';
2170 if ($recurrence['INTERVAL'] <= 1)
2171 {
2172 $frequencies = array(
2173 'ONCE' => __( 'Once', 'propertyhive' ),
2174 'DAILY' => __( 'Daily', 'propertyhive' ),
2175 'WEEKLY' => __( 'Weekly', 'propertyhive' ),
2176 'MONTHLY' => __( 'Monthly', 'propertyhive' ),
2177 'YEARLY' => __( 'Annually', 'propertyhive' ),
2178 );
2179
2180 $frequency = $frequencies[$recurrence['FREQ']];
2181 }
2182 else
2183 {
2184 $interval = $recurrence['INTERVAL'];
2185 if (extension_loaded('intl'))
2186 {
2187 $formatter = new NumberFormatter(get_locale(), NumberFormatter::SPELLOUT);
2188 $interval = $formatter->format($recurrence['INTERVAL']);
2189 }
2190
2191 $periods = array(
2192 'DAILY' => __( 'days', 'propertyhive' ),
2193 'WEEKLY' => __( 'weeks', 'propertyhive' ),
2194 'MONTHLY' => __( 'months', 'propertyhive' ),
2195 'YEARLY' => __( 'years', 'propertyhive' ),
2196 );
2197
2198
2199 $frequency = sprintf('Every %s %s', $interval, $periods[$recurrence['FREQ']]);
2200 }
2201
2202 ?>
2203 <tr>
2204 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2205 <td><?php echo esc_html($term->name); ?></td>
2206 <td><?php echo esc_html($frequency); ?></td>
2207 <td class="settings">
2208 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=management-key-date-type&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
2209 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=management-key-date-type-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
2210 </td>
2211 </tr>
2212 <?php
2213 }
2214 }
2215 else
2216 {
2217 ?>
2218 <tr>
2219 <td colspan="4"><?php echo esc_html(__( 'No management date types found', 'propertyhive' )); ?></td>
2220 </tr>
2221 <?php
2222 }
2223 ?>
2224 </tbody>
2225 </table>
2226 </td>
2227 </tr>
2228 <?php endforeach; ?>
2229 <tr valign="top">
2230 <th scope="row" class="titledesc">
2231 &nbsp;
2232 </th>
2233 <td class="forminp forminp-button">
2234 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2235 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=management-key-date-type&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Management Date Type', 'propertyhive' )); ?></a>
2236 </td>
2237 </tr>
2238 <?php
2239 }
2240
2241 /**
2242 * Output list of marketing flag options
2243 *
2244 * @access public
2245 * @return void
2246 */
2247 public function custom_fields_marketing_flag_setting() {
2248 global $post;
2249 ?>
2250 <tr valign="top">
2251 <th scope="row" class="titledesc">
2252 &nbsp;
2253 </th>
2254 <td class="forminp forminp-button">
2255 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2256 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Marketing Flag', 'propertyhive' )); ?></a>
2257 </td>
2258 </tr>
2259 <tr valign="top">
2260 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Marketing Flags', 'propertyhive' )); ?></th>
2261 <td class="forminp">
2262 <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="marketing_flag" cellspacing="0">
2263 <thead>
2264 <tr>
2265 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2266 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2267 <th class="type"><?php echo esc_html(__( 'Marketing Flag', 'propertyhive' )); ?></th>
2268 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
2269 <th class="settings">&nbsp;</th>
2270 </tr>
2271 </thead>
2272 <tbody>
2273 <?php
2274 $args = array(
2275 'hide_empty' => false,
2276 'parent' => 0
2277 );
2278 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'marketing_flag' ) ) );
2279
2280 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2281 {
2282 foreach ($terms as $term)
2283 {
2284 ?>
2285 <tr id="term-<?php echo esc_attr($term->term_id); ?>">
2286 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2287 <td class="id"><?php echo esc_html($term->term_id); ?></td>
2288 <td class="type"><?php echo esc_html($term->name); ?></td>
2289 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
2290 <td class="settings">
2291 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
2292 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
2293 </td>
2294 </tr>
2295 <?php
2296 }
2297 }
2298 else
2299 {
2300 ?>
2301 <tr>
2302 <td colspan="5"><?php echo esc_html(__( 'No marketing flags found', 'propertyhive' )); ?></td>
2303 </tr>
2304 <?php
2305 }
2306 ?>
2307 </tbody>
2308 </table>
2309 </td>
2310 </tr>
2311 <tr valign="top">
2312 <th scope="row" class="titledesc">
2313 &nbsp;
2314 </th>
2315 <td class="forminp forminp-button">
2316 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2317 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Marketing Flag', 'propertyhive' )); ?></a>
2318 </td>
2319 </tr>
2320 <?php
2321 }
2322
2323 /**
2324 * Output list of property feature options
2325 *
2326 * @access public
2327 * @return void
2328 */
2329 public function custom_fields_property_feature_setting() {
2330 global $post;
2331 ?>
2332 <tr valign="top">
2333 <th scope="row" class="titledesc">
2334 &nbsp;
2335 </th>
2336 <td class="forminp forminp-button">
2337 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2338 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Feature', 'propertyhive' )); ?></a>
2339 </td>
2340 </tr>
2341 <tr valign="top">
2342 <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Features', 'propertyhive' )); ?></th>
2343 <td class="forminp">
2344 <table class="ph_customfields widefat" cellspacing="0">
2345 <thead>
2346 <tr>
2347 <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2348 <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2349 <th class="type"><?php echo esc_html(__( 'Property Feature', 'propertyhive' )); ?></th>
2350 <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
2351 <th class="settings">&nbsp;</th>
2352 </tr>
2353 </thead>
2354 <tbody>
2355 <?php
2356 $args = array(
2357 'hide_empty' => false,
2358 'parent' => 0
2359 );
2360 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_feature' ) ) );
2361
2362 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2363 {
2364 foreach ($terms as $term)
2365 {
2366 ?>
2367 <tr>
2368 <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2369 <td class="id"><?php echo esc_html($term->term_id); ?></td>
2370 <td class="type"><?php echo esc_html($term->name); ?></td>
2371 <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
2372 <td class="settings">
2373 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Edit', 'propertyhive' )); ?></a>
2374 <a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature-delete&id=' . $term->term_id )); ?>"><?php echo esc_html(__( 'Delete', 'propertyhive' )); ?></a>
2375 </td>
2376 </tr>
2377 <?php
2378 }
2379 }
2380 else
2381 {
2382 ?>
2383 <tr>
2384 <td colspan="5"><?php echo esc_html(__( 'No property features found', 'propertyhive' )); ?></td>
2385 </tr>
2386 <?php
2387 }
2388 ?>
2389 </tbody>
2390 </table>
2391 </td>
2392 </tr>
2393 <tr valign="top">
2394 <th scope="row" class="titledesc">
2395 &nbsp;
2396 </th>
2397 <td class="forminp forminp-button">
2398 <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2399 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Property Feature', 'propertyhive' )); ?></a>
2400 </td>
2401 </tr>
2402 <?php
2403 }
2404
2405 /**
2406 * Show availability add/edit options
2407 *
2408 * @access public
2409 * @return string
2410 */
2411 public function get_custom_fields_availability_setting()
2412 {
2413 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2414 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2415
2416 $taxonomy = 'availability';
2417 $term_name = '';
2418 if ($current_id != '')
2419 {
2420 $term = get_term( $current_id, $taxonomy );
2421 $term_name = $term->name;
2422 }
2423
2424 $departments = ph_get_departments();
2425
2426 $args = array(
2427
2428 array( 'title' => ( $current_id == '' ? __( 'Add New Availability Option', 'propertyhive' ) : __( 'Edit Availability', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_availability_settings' ),
2429
2430 array(
2431 'title' => __( 'Availability', 'propertyhive' ),
2432 'id' => 'availability_name',
2433 'default' => $term_name,
2434 'type' => 'text',
2435 'desc_tip' => false,
2436 ),
2437
2438 );
2439
2440 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
2441
2442 $i = 0;
2443 foreach ( $departments as $key => $value )
2444 {
2445 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
2446 {
2447 $args[] = array(
2448 'title' => __( 'Applies To', 'propertyhive' ),
2449 'name' => 'department[' . $key . ']',
2450 'id' => 'department_' . $key,
2451 //'default' => $term_name,
2452 'value' => ( !isset($availability_departments[$current_id]) || in_array($key, $availability_departments[$current_id]) ? 'yes' : '' ),
2453 'type' => 'checkbox',
2454 'desc_tip' => false,
2455 'desc' => $value,
2456 'checkboxgroup' => ( $i == 0 ? 'start' : ( $i == count($departments)-1 ? 'end' : '' ) ),
2457 );
2458
2459 ++$i;
2460 }
2461 }
2462
2463 $args[] = array(
2464 'type' => 'hidden',
2465 'id' => 'taxonomy',
2466 'default' => $taxonomy
2467 );
2468
2469 $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_availability_settings' );
2470
2471 return apply_filters( 'propertyhive_custom_field_availability_settings', $args );
2472 }
2473
2474 /**
2475 * Show residential property type add/edit options
2476 *
2477 * @access public
2478 * @return string
2479 */
2480 public function get_custom_fields_property_type_setting()
2481 {
2482 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2483 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2484
2485 $taxonomy = 'property_type';
2486 $term_name = '';
2487 $term_parent = '';
2488 if ($current_id != '')
2489 {
2490 $term = get_term( $current_id, $taxonomy );
2491 $term_name = $term->name;
2492 $term_parent = $term->parent;
2493 }
2494
2495 $existing_terms = array('' => '(' . __ ( 'no parent', 'propertyhive') . ')');
2496
2497 $args = array(
2498 'hide_empty' => false,
2499 'parent' => 0,
2500 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Edit screens exclude only the currently edited term from its own parent choices. Each line is exclude=>array($current_id), where current_id is cast to int from the request; one term ID prevents self-parenting.
2501 'exclude' => array($current_id)
2502 );
2503 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
2504 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2505 {
2506 foreach ($terms as $term)
2507 {
2508 $existing_terms[$term->term_id] = $term->name;
2509 }
2510 }
2511
2512 $args = array(
2513
2514 array( 'title' => ( $current_id == '' ? __( 'Add New Property Type', 'propertyhive' ) : __( 'Edit Property Type', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_type_settings' ),
2515
2516 array(
2517 'title' => __( 'Property Type', 'propertyhive' ),
2518 'id' => 'property_type_name',
2519 'default' => $term_name,
2520 'type' => 'text',
2521 'desc_tip' => false,
2522 ),
2523
2524 array(
2525 'title' => __( 'Parent', 'propertyhive' ),
2526 'id' => 'parent_property_type_id',
2527 'default' => $term_parent,
2528 'options' => $existing_terms,
2529 'type' => 'select',
2530 'desc_tip' => false,
2531 'desc' => ''
2532 ),
2533
2534 array(
2535 'type' => 'hidden',
2536 'id' => 'taxonomy',
2537 'default' => $taxonomy
2538 ),
2539
2540 array( 'type' => 'sectionend', 'id' => 'custom_field_property_type_settings' )
2541
2542 );
2543
2544 return apply_filters( 'propertyhive_custom_field_property_type_settings', $args );
2545 }
2546
2547 /**
2548 * Show commercial property type add/edit options
2549 *
2550 * @access public
2551 * @return string
2552 */
2553 public function get_custom_fields_commercial_property_type_setting()
2554 {
2555 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2556 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2557
2558 $taxonomy = 'commercial_property_type';
2559 $term_name = '';
2560 $term_parent = '';
2561 if ($current_id != '')
2562 {
2563 $term = get_term( $current_id, $taxonomy );
2564 $term_name = $term->name;
2565 $term_parent = $term->parent;
2566 }
2567
2568 $existing_terms = array('' => '(' . __ ( 'no parent', 'propertyhive') . ')');
2569
2570 $args = array(
2571 'hide_empty' => false,
2572 'parent' => 0,
2573 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Edit screens exclude only the currently edited term from its own parent choices. Each line is exclude=>array($current_id), where current_id is cast to int from the request; one term ID prevents self-parenting.
2574 'exclude' => array($current_id)
2575 );
2576 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
2577 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2578 {
2579 foreach ($terms as $term)
2580 {
2581 $existing_terms[$term->term_id] = $term->name;
2582 }
2583 }
2584
2585 $args = array(
2586
2587 array( 'title' => ( $current_id == '' ? __( 'Add New Property Type', 'propertyhive' ) : __( 'Edit Property Type', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_property_type_settings' ),
2588
2589 array(
2590 'title' => __( 'Property Type', 'propertyhive' ),
2591 'id' => 'commercial_property_type_name',
2592 'default' => $term_name,
2593 'type' => 'text',
2594 'desc_tip' => false,
2595 ),
2596
2597 array(
2598 'title' => __( 'Parent', 'propertyhive' ),
2599 'id' => 'parent_commercial_property_type_id',
2600 'default' => $term_parent,
2601 'options' => $existing_terms,
2602 'type' => 'select',
2603 'desc_tip' => false,
2604 'desc' => ''
2605 ),
2606
2607 array(
2608 'type' => 'hidden',
2609 'id' => 'taxonomy',
2610 'default' => $taxonomy
2611 ),
2612
2613 array( 'type' => 'sectionend', 'id' => 'custom_field_commercial_property_type_settings' )
2614
2615 );
2616
2617 return apply_filters( 'propertyhive_custom_field_commercial_property_type_settings', $args );
2618 }
2619
2620 /**
2621 * Show location add/edit options
2622 *
2623 * @access public
2624 * @return string
2625 */
2626 public function get_custom_fields_location_setting()
2627 {
2628 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2629 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2630
2631 $taxonomy = 'location';
2632 $term_name = '';
2633 $term_parent = '';
2634 if ($current_id != '')
2635 {
2636 $term = get_term( $current_id, $taxonomy );
2637 $term_name = $term->name;
2638 $term_parent = $term->parent;
2639 }
2640
2641 $existing_terms = array('' => '(' . __ ( 'no parent', 'propertyhive') . ')');
2642
2643 $args = array(
2644 'hide_empty' => false,
2645 'parent' => 0,
2646 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Edit screens exclude only the currently edited term from its own parent choices. Each line is exclude=>array($current_id), where current_id is cast to int from the request; one term ID prevents self-parenting.
2647 'exclude' => array($current_id)
2648 );
2649 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => $taxonomy ) ) );
2650 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2651 {
2652 foreach ($terms as $term)
2653 {
2654 $existing_terms[$term->term_id] = '- '.$term->name;
2655
2656 $args = array(
2657 'hide_empty' => false,
2658 'parent' => $term->term_id,
2659 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Edit screens exclude only the currently edited term from its own parent choices. Each line is exclude=>array($current_id), where current_id is cast to int from the request; one term ID prevents self-parenting.
2660 'exclude' => array($current_id)
2661 );
2662 $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => $taxonomy ) ) );
2663 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2664 {
2665 foreach ($terms as $term)
2666 {
2667 $existing_terms[$term->term_id] = '- - '.$term->name;
2668 }
2669 }
2670 }
2671 }
2672
2673 $args = array(
2674
2675 array( 'title' => ( $current_id == '' ? __( 'Add New Location', 'propertyhive' ) : __( 'Edit Location', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_location_settings' ),
2676
2677 array(
2678 'title' => __( 'Location', 'propertyhive' ),
2679 'id' => 'location_name',
2680 'default' => $term_name,
2681 'type' => 'text',
2682 'desc_tip' => false,
2683 ),
2684
2685 array(
2686 'title' => __( 'Parent', 'propertyhive' ),
2687 'id' => 'parent_location_id',
2688 'default' => $term_parent,
2689 'options' => $existing_terms,
2690 'type' => 'select',
2691 'desc_tip' => false,
2692 'desc' => ''
2693 ),
2694
2695 array(
2696 'type' => 'hidden',
2697 'id' => 'taxonomy',
2698 'default' => $taxonomy
2699 ),
2700
2701 array( 'type' => 'sectionend', 'id' => 'custom_field_location_settings' )
2702
2703 );
2704
2705 return apply_filters( 'propertyhive_custom_field_location_settings', $args );
2706 }
2707
2708 /**
2709 * Show parking add/edit options
2710 *
2711 * @access public
2712 * @return string
2713 */
2714 public function get_custom_fields_parking_setting()
2715 {
2716 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2717 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2718
2719 $taxonomy = 'parking';
2720 $term_name = '';
2721 if ($current_id != '')
2722 {
2723 $term = get_term( $current_id, $taxonomy );
2724 $term_name = $term->name;
2725 }
2726
2727 $args = array(
2728
2729 array( 'title' => ( $current_id == '' ? __( 'Add New Parking Option', 'propertyhive' ) : __( 'Edit Parking', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_parking_settings' ),
2730
2731 array(
2732 'title' => __( 'Parking', 'propertyhive' ),
2733 'id' => 'parking_name',
2734 'default' => $term_name,
2735 'type' => 'text',
2736 'desc_tip' => false,
2737 ),
2738
2739 array(
2740 'type' => 'hidden',
2741 'id' => 'taxonomy',
2742 'default' => $taxonomy
2743 ),
2744
2745 array( 'type' => 'sectionend', 'id' => 'custom_field_parking_settings' )
2746
2747 );
2748
2749 return apply_filters( 'propertyhive_custom_field_parking_settings', $args );
2750 }
2751
2752 /**
2753 * Show outside space add/edit options
2754 *
2755 * @access public
2756 * @return string
2757 */
2758 public function get_custom_fields_outside_space_setting()
2759 {
2760 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2761 $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
2762
2763 $taxonomy = 'outside_space';
2764 $term_name = '';
2765 if ($current_id != '')
2766 {
2767 $term = get_term( $current_id, $taxonomy );
2768 $term_name = $term->name;
2769 }
2770
2771 $args = array(
2772
2773 array( 'title' => ( $current_id == '' ? __( 'Add New Outside Space', 'propertyhive' ) : __( 'Edit Outside Space', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_outside_space_settings' ),
2774
2775 array(
2776 'title' => __( 'Outside Space', 'propertyhive' ),
2777 'id' => 'outside_space_name',
2778 'default' => $term_name,
2779 'type' => 'text',
2780 'desc_tip' => false,
2781 ),
2782
2783 array(
2784 'type' => 'hidden',
2785 'id' => 'taxonomy',
2786 'default' => $taxonomy
2787 ),
2788
2789 array( 'type' => 'sectionend', 'id' => 'custom_field_outside_space_settings' )
2790
2791 );
2792
2793 return apply_filters( 'propertyhive_custom_field_outside_space_settings', $args );
2794 }
2795
2796 /**
2797 * Show custom field delete options
2798 *
2799 * @access public
2800 * @return string
2801 */
2802 public function get_custom_fields_delete($current_id, $taxonomy, $taxonomy_name)
2803 {
2804 global $save_button_text;
2805
2806 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
2807 $save_button_text = __( 'Delete', 'propertyhive' );
2808
2809 //$taxonomy = 'outside_space';
2810 //$taxonomy_name = __( 'Outside Space', 'propertyhive' );
2811
2812 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This branch only selects a read-only success view; the deletion mutation occurs in save() after the settings nonce and capability checks.
2813 $confirm_removal = ( isset( $_POST['confirm_removal'] ) && is_string( $_POST['confirm_removal'] ) ) ? sanitize_text_field( wp_unslash( $_POST['confirm_removal'] ) ) : '';
2814 if ( '1' === $confirm_removal )
2815 {
2816 // A term has just been deleted
2817 global $hide_save_button, $show_cancel_button, $cancel_button_href;
2818
2819 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
2820 $hide_save_button = TRUE;
2821 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
2822 $show_cancel_button = TRUE;
2823 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global.
2824 $cancel_button_href = admin_url( 'admin.php?page=ph-settings&tab=customfields&section=' . str_replace("_", "-", $taxonomy) );
2825
2826 $args = array();
2827
2828 $args[] = array( 'title' => __( 'Successfully Deleted', 'propertyhive' ) . ' ' . $taxonomy_name, 'type' => 'title', 'desc' => '', 'id' => 'custom_field_' . $taxonomy . '_delete' );
2829
2830 $args[] = array(
2831 'title' => __( 'Term Deleted', 'propertyhive' ),
2832 'id' => '',
2833 'html' => $taxonomy_name . __(' deleted successfully', 'propertyhive' ) . ' <a href="' . admin_url( 'admin.php?page=ph-settings&tab=customfields&section=' . str_replace("_", "-", $taxonomy) ) . '">' . __( 'Go Back', 'propertyhive' ) . '</a>',
2834 'type' => 'html',
2835 'desc_tip' => false,
2836 );
2837
2838 $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_' . $taxonomy . '_delete' );
2839 }
2840 else
2841 {
2842 $term_name = '';
2843 if ($current_id == '')
2844 {
2845 die("ID not passed");
2846 }
2847 else
2848 {
2849 $term_ids = explode("-", $current_id);
2850
2851 $args = array();
2852
2853 foreach ( $term_ids as $current_id )
2854 {
2855 $term = get_term( $current_id, $taxonomy );
2856
2857 if ( is_null($term) || is_wp_error($term) )
2858 {
2859 die("Invalid term trying to be deleted");
2860 }
2861 else
2862 {
2863 $term_name = $term->name;
2864
2865 $args[] = array( 'title' => __( 'Delete', 'propertyhive' ) . ' ' . $taxonomy_name . ': ' . $term_name, 'type' => 'title', 'desc' => '', 'id' => 'custom_field_' . $taxonomy . '_' . $current_id . '_delete' );
2866
2867 // Get number of properties assigned to this term
2868 $query_args = array(
2869 'post_type' => 'property',
2870 'nopaging' => true,
2871 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2872 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Term deletion/reassignment must locate all properties or key dates attached to this selected term before removing it.
2873 'tax_query' => array(
2874 array(
2875 'taxonomy' => $taxonomy,
2876 'field' => 'id',
2877 'terms' => $current_id,
2878 ),
2879 ),
2880 );
2881 $property_query = new WP_Query( $query_args );
2882
2883 $num_properties = $property_query->found_posts;
2884
2885 wp_reset_postdata();
2886
2887 // Get number of applicants assigned to this term
2888 $num_applicants = 0;
2889 if ( $taxonomy == 'property_type' || $taxonomy == 'commercial_property_type' || $taxonomy == 'location' )
2890 {
2891 $query_args = array(
2892 'post_type' => 'contact',
2893 'nopaging' => true,
2894 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2895 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Applicant preferences are serialized profile metadata; deletion/reassignment must inspect every applicant profile to preserve its other selections.
2896 'meta_query' => array(
2897 array(
2898 'key' => '_contact_types',
2899 'value' => 'applicant',
2900 'compare' => 'LIKE'
2901 ),
2902 ),
2903 );
2904 $applicant_query = new WP_Query( $query_args );
2905
2906 if ( $applicant_query->have_posts() )
2907 {
2908 while ( $applicant_query->have_posts() )
2909 {
2910 $applicant_query->the_post();
2911
2912 $applicant_has_taxonomy = false;
2913
2914 $num_applicant_profiles = get_post_meta( get_the_ID(), '_applicant_profiles', TRUE );
2915 if ( $num_applicant_profiles == '' )
2916 {
2917 $num_applicant_profiles = 0;
2918 }
2919
2920 if ( $num_applicant_profiles > 0 )
2921 {
2922 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
2923 {
2924 $applicant_profile = get_post_meta( get_the_ID(), '_applicant_profile_' . $i, TRUE );
2925
2926 if ( isset($applicant_profile[$taxonomy.'s']) && is_array($applicant_profile[$taxonomy.'s']) && !empty($applicant_profile[$taxonomy.'s']) )
2927 {
2928 if (in_array($current_id, $applicant_profile[$taxonomy.'s']))
2929 {
2930 $applicant_has_taxonomy = true;
2931 }
2932 }
2933 }
2934 }
2935
2936 if ( $applicant_has_taxonomy )
2937 {
2938 ++$num_applicants;
2939 }
2940 }
2941 }
2942
2943 wp_reset_postdata();
2944 }
2945
2946 // Get number of key dates assigned to this term
2947 $num_key_dates= 0;
2948 if ( $taxonomy == 'management_key_date_type' )
2949 {
2950 $query_args = array(
2951 'post_type' => 'key_date',
2952 'nopaging' => true,
2953 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2954 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Term deletion/reassignment must locate all properties or key dates attached to this selected term before removing it.
2955 'tax_query' => array(
2956 array(
2957 'taxonomy' => $taxonomy,
2958 'field' => 'id',
2959 'terms' => $current_id,
2960 ),
2961 ),
2962 );
2963 $key_date_query = new WP_Query( $query_args );
2964
2965 $num_key_dates = $key_date_query->found_posts;
2966
2967 wp_reset_postdata();
2968 }
2969
2970 if ($num_properties > 0 || $num_applicants > 0 || $num_key_dates > 0 )
2971 {
2972 $alternative_terms = array();
2973
2974 $alternative_terms['none'] = '-- ' . __( 'Don\'t Reassign', 'propertyhive' ) . ' --';
2975
2976 $term_args = array(
2977 'hide_empty' => false,
2978 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- This is a get_terms argument excluding the terms being deleted from reassignment choices, not a posts exclusion query.
2979 'exclude' => $term_ids,
2980 'parent' => 0
2981 );
2982 $terms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
2983
2984 if ( !empty( $terms ) && !is_wp_error( $terms ) )
2985 {
2986 foreach ($terms as $term)
2987 {
2988 $alternative_terms[$term->term_id] = $term->name;
2989
2990 $term_args = array(
2991 'hide_empty' => false,
2992 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- This is a get_terms argument excluding the terms being deleted from reassignment choices, not a posts exclusion query.
2993 'exclude' => $term_ids,
2994 'parent' => $term->term_id
2995 );
2996 $subterms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
2997
2998 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
2999 {
3000 foreach ($subterms as $term)
3001 {
3002 $alternative_terms[$term->term_id] = '- ' . $term->name;
3003
3004 $term_args = array(
3005 'hide_empty' => false,
3006 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- This is a get_terms argument excluding the terms being deleted from reassignment choices, not a posts exclusion query.
3007 'exclude' => $term_ids,
3008 'parent' => $term->term_id
3009 );
3010 $subsubterms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
3011
3012 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
3013 {
3014 foreach ($subsubterms as $term)
3015 {
3016 $alternative_terms[$term->term_id] = '- - ' . $term->name;
3017 }
3018 }
3019 }
3020 }
3021 }
3022 }
3023
3024 // There are properties assigned to this term
3025 $args[] = array(
3026 'title' => __( 'Re-assign to', 'propertyhive' ),
3027 'id' => 'reassign_to_' . $current_id,
3028 'default' => '',
3029 'options' => $alternative_terms,
3030 'type' => 'select',
3031 'desc_tip' => false,
3032 'desc' => __( 'There are properties, applicants or management dates that have this term assigned to them. Which, if any, term should they be reassigned to?' , 'propertyhive' )
3033 );
3034 }
3035
3036 $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_' . $taxonomy . '_' . $current_id . '_delete' );
3037 }
3038 }
3039
3040 $args[] = array( 'title' => __( 'Confirm Removal', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_confirm_delete' );
3041
3042 $args[] = array(
3043 'title' => __( 'Confirm Removal?', 'propertyhive' ),
3044 'id' => 'confirm_removal',
3045 'type' => 'checkbox',
3046 'desc_tip' => false,
3047 );
3048
3049 $args[] = array(
3050 'type' => 'hidden',
3051 'id' => 'taxonomy',
3052 'default' => $taxonomy
3053 );
3054
3055 $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_confirm_delete' );
3056 }
3057 }
3058
3059 return apply_filters( 'propertyhive_custom_field_' . $taxonomy . '_delete', $args );
3060 }
3061
3062 /**
3063 * Show price qualifier add/edit options
3064 *
3065 * @access public
3066 * @return string
3067 */
3068 public function get_custom_fields_price_qualifier_setting()
3069 {
3070 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3071 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3072
3073 $taxonomy = 'price_qualifier';
3074 $term_name = '';
3075 if ($current_id != '')
3076 {
3077 $term = get_term( $current_id, $taxonomy );
3078 $term_name = $term->name;
3079 }
3080
3081 $args = array(
3082
3083 array( 'title' => ( $current_id == '' ? __( 'Add New Price Qualifier', 'propertyhive' ) : __( 'Edit Price Qualifier', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_price_qualifier_settings' ),
3084
3085 array(
3086 'title' => __( 'Price Qualifier', 'propertyhive' ),
3087 'id' => 'price_qualifier_name',
3088 'default' => $term_name,
3089 'type' => 'text',
3090 'desc_tip' => false,
3091 ),
3092
3093 array(
3094 'type' => 'hidden',
3095 'id' => 'taxonomy',
3096 'default' => $taxonomy
3097 ),
3098
3099 array( 'type' => 'sectionend', 'id' => 'custom_field_price_qualifier_settings' )
3100
3101 );
3102
3103 return apply_filters( 'propertyhive_custom_field_price_qualifier_settings', $args );
3104 }
3105
3106 /**
3107 * Show sale by add/edit options
3108 *
3109 * @access public
3110 * @return string
3111 */
3112 public function get_custom_fields_sale_by_setting()
3113 {
3114 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3115 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3116
3117 $taxonomy = 'sale_by';
3118 $term_name = '';
3119 if ($current_id != '')
3120 {
3121 $term = get_term( $current_id, $taxonomy );
3122 $term_name = $term->name;
3123 }
3124
3125 $args = array(
3126
3127 array( 'title' => ( $current_id == '' ? __( 'Add New Sale By', 'propertyhive' ) : __( 'Edit Sale By', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_sale_by_settings' ),
3128
3129 array(
3130 'title' => __( 'Sale By', 'propertyhive' ),
3131 'id' => 'sale_by_name',
3132 'default' => $term_name,
3133 'type' => 'text',
3134 'desc_tip' => false,
3135 ),
3136
3137 array(
3138 'type' => 'hidden',
3139 'id' => 'taxonomy',
3140 'default' => $taxonomy
3141 ),
3142
3143 array( 'type' => 'sectionend', 'id' => 'custom_field_sale_by_settings' )
3144
3145 );
3146
3147 return apply_filters( 'propertyhive_custom_field_sale_by_settings', $args );
3148 }
3149
3150 /**
3151 * Show tenure add/edit options
3152 *
3153 * @access public
3154 * @return string
3155 */
3156 public function get_custom_fields_tenure_setting()
3157 {
3158 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3159 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3160
3161 $taxonomy = 'tenure';
3162 $term_name = '';
3163 if ($current_id != '')
3164 {
3165 $term = get_term( $current_id, $taxonomy );
3166 $term_name = $term->name;
3167 }
3168
3169 $args = array(
3170
3171 array( 'title' => ( $current_id == '' ? __( 'Add New Tenure', 'propertyhive' ) : __( 'Edit Tenure', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_tenure_settings' ),
3172
3173 array(
3174 'title' => __( 'Tenure', 'propertyhive' ),
3175 'id' => 'tenure_name',
3176 'default' => $term_name,
3177 'type' => 'text',
3178 'desc_tip' => false,
3179 ),
3180
3181 array(
3182 'type' => 'hidden',
3183 'id' => 'taxonomy',
3184 'default' => $taxonomy
3185 ),
3186
3187 array( 'type' => 'sectionend', 'id' => 'custom_field_tenure_settings' )
3188
3189 );
3190
3191 return apply_filters( 'propertyhive_custom_field_tenure_settings', $args );
3192 }
3193
3194 /**
3195 * Show commercial tenure add/edit options
3196 *
3197 * @access public
3198 * @return string
3199 */
3200 public function get_custom_fields_commercial_tenure_setting()
3201 {
3202 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3203 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3204
3205 $taxonomy = 'commercial_tenure';
3206 $term_name = '';
3207 if ($current_id != '')
3208 {
3209 $term = get_term( $current_id, $taxonomy );
3210 $term_name = $term->name;
3211 }
3212
3213 $args = array(
3214
3215 array( 'title' => ( $current_id == '' ? __( 'Add New Tenure', 'propertyhive' ) : __( 'Edit Tenure', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_tenure_settings' ),
3216
3217 array(
3218 'title' => __( 'Tenure', 'propertyhive' ),
3219 'id' => 'commercial_tenure_name',
3220 'default' => $term_name,
3221 'type' => 'text',
3222 'desc_tip' => false,
3223 ),
3224
3225 array(
3226 'type' => 'hidden',
3227 'id' => 'taxonomy',
3228 'default' => $taxonomy
3229 ),
3230
3231 array( 'type' => 'sectionend', 'id' => 'custom_field_commercial_tenure_settings' )
3232
3233 );
3234
3235 return apply_filters( 'propertyhive_custom_field_commercial_tenure_settings', $args );
3236 }
3237
3238 /**
3239 * Show furnished add/edit options
3240 *
3241 * @access public
3242 * @return string
3243 */
3244 public function get_custom_fields_furnished_setting()
3245 {
3246 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3247 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3248
3249 $taxonomy = 'furnished';
3250 $term_name = '';
3251 if ($current_id != '')
3252 {
3253 $term = get_term( $current_id, $taxonomy );
3254 $term_name = $term->name;
3255 }
3256
3257 $args = array(
3258
3259 array( 'title' => ( $current_id == '' ? __( 'Add New Furnished', 'propertyhive' ) : __( 'Edit Furnished', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_furnished_settings' ),
3260
3261 array(
3262 'title' => __( 'Furnished', 'propertyhive' ),
3263 'id' => 'furnished_name',
3264 'default' => $term_name,
3265 'type' => 'text',
3266 'desc_tip' => false,
3267 ),
3268
3269 array(
3270 'type' => 'hidden',
3271 'id' => 'taxonomy',
3272 'default' => $taxonomy
3273 ),
3274
3275 array( 'type' => 'sectionend', 'id' => 'custom_field_furnished_settings' )
3276
3277 );
3278
3279 return apply_filters( 'propertyhive_custom_field_furnished_settings', $args );
3280 }
3281
3282 /**
3283 * Show key date add/edit options
3284 *
3285 * @return string
3286 */
3287 public function get_custom_fields_management_key_date_type_setting()
3288 {
3289 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3290 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3291
3292 $taxonomy = 'management_key_date_type';
3293 $term_name = '';
3294 if ($current_id != '')
3295 {
3296 $term = get_term( $current_id, $taxonomy );
3297 $term_name = $term->name;
3298 }
3299
3300 $recurrence = get_option( 'propertyhive_key_date_type', array() );
3301 if ( ! is_array($recurrence) )
3302 {
3303 $recurrence = array();
3304 }
3305 $recurrence_rule = isset($recurrence[$current_id]) ? $recurrence[$current_id]['recurrence_rule'] : '';
3306 $recurrence_type = isset($recurrence[$current_id]) ? $recurrence[$current_id]['recurrence_type'] : '';
3307
3308 $recurrence = array(
3309 'FREQ' => 'ONCE',
3310 'INTERVAL' => '1',
3311 );
3312
3313 if ( !empty($recurrence_rule) )
3314 {
3315 foreach (explode(';', $recurrence_rule) as $key_value_pair){
3316 list($key, $value) = explode('=', $key_value_pair);
3317 $recurrence[$key] = $value;
3318 }
3319 }
3320
3321 $interval_disabled = $recurrence['FREQ'] == 'ONCE' ? array('disabled' => 'disabled') : array();
3322
3323 $args = array(
3324
3325 array( 'title' => ( $current_id == '' ? __( 'Add New Management Date Type', 'propertyhive' ) : __( 'Edit Management Date Type', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_management_key_date_type_settings' ),
3326
3327 array(
3328 'title' => __( 'Description', 'propertyhive' ),
3329 'id' => 'management_key_date_type_name',
3330 'default' => $term_name,
3331 'type' => 'text',
3332 'desc_tip' => false,
3333 ),
3334
3335 array(
3336 'title' => __( 'Type', 'propertyhive' ),
3337 'id' => 'management_key_date_type_recurrence_type',
3338 'default' => $recurrence_type,
3339 'type' => 'select',
3340 'desc_tip' => false,
3341 'options' => array(
3342 'tenancy_management' => __( 'Tenancy Management', 'propertyhive' ),
3343 'property_management' => __( 'Property Management', 'propertyhive' ),
3344 ),
3345 ),
3346
3347 array(
3348 'title' => __( 'Frequency', 'propertyhive' ),
3349 'id' => 'management_key_date_type_recurrence_freq',
3350 'default' => $recurrence['FREQ'],
3351 'type' => 'select',
3352 'desc_tip' => false,
3353 'options' => array(
3354 'ONCE' => __( 'Once', 'propertyhive' ),
3355 'DAILY' => __( 'Daily', 'propertyhive' ),
3356 'WEEKLY' => __( 'Weekly', 'propertyhive' ),
3357 'MONTHLY' => __( 'Monthly', 'propertyhive' ),
3358 'YEARLY' => __( 'Yearly', 'propertyhive' ),
3359 ),
3360 'custom_attributes' => array('onchange' => "
3361 jQuery('#management_key_date_type_recurrence_interval').prop( 'disabled', this.value == 'ONCE');
3362 "),
3363 ),
3364
3365 array(
3366 'title' => __( 'Interval', 'propertyhive' ),
3367 'id' => 'management_key_date_type_recurrence_interval',
3368 'default' => $recurrence['INTERVAL'],
3369 'type' => 'number',
3370 'custom_attributes' => array_merge( array( 'min' => '1', 'required' => 'true'), $interval_disabled ),
3371 'desc' => '<p>When setting a key date to Complete, these settings are used to calculate the date the next one should occur.<br>For example, if a key date should happen every 3 months, set Frequency to "Monthly" and Interval to "3".</p>',
3372 ),
3373
3374 array(
3375 'type' => 'hidden',
3376 'id' => 'taxonomy',
3377 'default' => $taxonomy
3378 ),
3379
3380 array( 'type' => 'sectionend', 'id' => 'custom_field_management_key_date_type_settings' )
3381
3382 );
3383
3384 return apply_filters( 'propertyhive_custom_field_management_key_date_type_setting', $args );
3385 }
3386
3387 /**
3388 * Show marketing flag add/edit options
3389 *
3390 * @access public
3391 * @return string
3392 */
3393 public function get_custom_fields_marketing_flag_setting()
3394 {
3395 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3396 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3397
3398 $taxonomy = 'marketing_flag';
3399 $term_name = '';
3400 if ($current_id != '')
3401 {
3402 $term = get_term( $current_id, $taxonomy );
3403 $term_name = $term->name;
3404 }
3405
3406 $args = array(
3407
3408 array( 'title' => ( $current_id == '' ? __( 'Add New Marketing Flag', 'propertyhive' ) : __( 'Edit Marketing Flag', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_marketing_flag_settings' ),
3409
3410 array(
3411 'title' => __( 'Marketing Flag', 'propertyhive' ),
3412 'id' => 'marketing_flag_name',
3413 'default' => $term_name,
3414 'type' => 'text',
3415 'desc_tip' => false,
3416 ),
3417
3418 array(
3419 'type' => 'hidden',
3420 'id' => 'taxonomy',
3421 'default' => $taxonomy
3422 ),
3423
3424 array( 'type' => 'sectionend', 'id' => 'custom_field_marketing_flag_settings' )
3425
3426 );
3427
3428 return apply_filters( 'propertyhive_custom_field_marketing_flag_settings', $args );
3429 }
3430
3431 /**
3432 * Show property feature add/edit options
3433 *
3434 * @access public
3435 * @return string
3436 */
3437 public function get_custom_fields_property_feature_setting()
3438 {
3439 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3440 $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3441
3442 $taxonomy = 'property_feature';
3443 $term_name = '';
3444 if ($current_id != '')
3445 {
3446 $term = get_term( $current_id, $taxonomy );
3447 $term_name = $term->name;
3448 }
3449
3450 $args = array(
3451
3452 array( 'title' => ( $current_id == '' ? __( 'Add New Property Feature', 'propertyhive' ) : __( 'Edit Property Feature', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_feature_settings' ),
3453
3454 array(
3455 'title' => __( 'Property Feature', 'propertyhive' ),
3456 'id' => 'property_feature_name',
3457 'default' => $term_name,
3458 'type' => 'text',
3459 'desc_tip' => false,
3460 ),
3461
3462 array(
3463 'type' => 'hidden',
3464 'id' => 'taxonomy',
3465 'default' => $taxonomy
3466 ),
3467
3468 array( 'type' => 'sectionend', 'id' => 'custom_field_property_feature_settings' )
3469
3470 );
3471
3472 return apply_filters( 'propertyhive_custom_field_property_feature_settings', $args );
3473 }
3474
3475 private function normalize_custom_fields_field_type( $value ) {
3476 if ( ! is_string( $value ) ) {
3477 return 'text';
3478 }
3479
3480 $field_type = sanitize_key( $value );
3481 $allowed_types = array( 'text', 'textarea', 'select', 'multiselect', 'checkbox', 'date', 'image', 'file' );
3482
3483 return in_array( $field_type, $allowed_types, true ) ? $field_type : 'text';
3484 }
3485
3486 private function normalize_custom_fields_dropdown_options( $value ) {
3487 if ( ! is_array( $value ) ) {
3488 return '';
3489 }
3490
3491 $options = array();
3492 foreach ( $value as $option ) {
3493 if ( ! is_string( $option ) ) {
3494 return '';
3495 }
3496 $options[] = sanitize_text_field( $option );
3497 }
3498
3499 return $options;
3500 }
3501
3502 private function normalize_custom_fields_checkbox( $value ) {
3503 return ( is_string( $value ) && '1' === $value ) ? '1' : '';
3504 }
3505
3506 private function normalize_custom_fields_meta_box( $value ) {
3507 return is_string( $value ) ? sanitize_key( $value ) : '';
3508 }
3509
3510 private function normalize_custom_fields_term_id( $value, $allow_empty = true ) {
3511 if ( ! is_string( $value ) ) {
3512 return null;
3513 }
3514
3515 $value = trim( $value );
3516 if ( '' === $value ) {
3517 return $allow_empty ? '' : null;
3518 }
3519
3520 if ( ! preg_match( '/^[0-9]+$/D', $value ) ) {
3521 return null;
3522 }
3523
3524 $term_id = absint( $value );
3525 return $term_id > 0 ? (string) $term_id : null;
3526 }
3527
3528 private function normalize_custom_fields_render_term_id( $value ) {
3529 $term_id = $this->normalize_custom_fields_term_id( $value );
3530 return ( null === $term_id || '' === $term_id ) ? '' : absint( $term_id );
3531 }
3532
3533 private function normalize_custom_fields_parent_id( $value ) {
3534 if ( ! is_string( $value ) ) {
3535 return null;
3536 }
3537
3538 $value = trim( $value );
3539 if ( '' === $value ) {
3540 return 0;
3541 }
3542
3543 if ( ! preg_match( '/^[0-9]+$/D', $value ) ) {
3544 return null;
3545 }
3546
3547 return absint( $value );
3548 }
3549
3550 private function normalize_custom_fields_term_id_list( $value ) {
3551 if ( ! is_string( $value ) || '' === trim( $value ) ) {
3552 return array();
3553 }
3554
3555 $term_ids = array();
3556 foreach ( explode( '-', trim( $value ) ) as $term_id ) {
3557 if ( ! preg_match( '/^[0-9]+$/D', $term_id ) ) {
3558 return array();
3559 }
3560
3561 $term_id = absint( $term_id );
3562 if ( $term_id < 1 || in_array( (string) $term_id, $term_ids, true ) ) {
3563 return array();
3564 }
3565
3566 $term_ids[] = (string) $term_id;
3567 }
3568
3569 return $term_ids;
3570 }
3571
3572 private function normalize_custom_fields_reassignment( $value, $deleted_ids ) {
3573 if ( ! is_string( $value ) ) {
3574 return null;
3575 }
3576
3577 $value = trim( $value );
3578 if ( '' === $value || 'none' === $value || ! preg_match( '/^[0-9]+$/D', $value ) ) {
3579 return null;
3580 }
3581
3582 $term_id = (string) absint( $value );
3583 if ( '0' === $term_id || in_array( $term_id, $deleted_ids, true ) ) {
3584 return null;
3585 }
3586
3587 return $term_id;
3588 }
3589
3590 private function get_custom_fields_taxonomy_for_section( $section ) {
3591 $taxonomies = array(
3592 'availability' => 'availability',
3593 'property-type' => 'property_type',
3594 'commercial-property-type' => 'commercial_property_type',
3595 'location' => 'location',
3596 'parking' => 'parking',
3597 'outside-space' => 'outside_space',
3598 'price-qualifier' => 'price_qualifier',
3599 'sale-by' => 'sale_by',
3600 'tenure' => 'tenure',
3601 'commercial-tenure' => 'commercial_tenure',
3602 'furnished' => 'furnished',
3603 'management-key-date-type' => 'management_key_date_type',
3604 'marketing-flag' => 'marketing_flag',
3605 'property-feature' => 'property_feature',
3606 );
3607
3608 if ( isset( $taxonomies[ $section ] ) ) {
3609 return $taxonomies[ $section ];
3610 }
3611
3612 if ( is_string( $section ) && '-delete' === substr( $section, -7 ) ) {
3613 $base_section = substr( $section, 0, -7 );
3614 return isset( $taxonomies[ $base_section ] ) ? $taxonomies[ $base_section ] : '';
3615 }
3616
3617 return '';
3618 }
3619
3620 /**
3621 * Save settings.
3622 */
3623 public function save() {
3624 if ( ! current_user_can( 'manage_options' ) || ! isset( $_REQUEST['_wpnonce'] ) || ! is_string( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'propertyhive-settings' ) ) {
3625 return;
3626 }
3627
3628 global $current_section, $post;
3629
3630 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing shared settings-router global; normalization preserves the public settings page contract.
3631 $current_section = is_string( $current_section ) ? $current_section : '';
3632 $request_id_present = isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] );
3633 $request_id = $request_id_present ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '';
3634 $post_data = is_array( $_POST ) ? wp_unslash( $_POST ) : array();
3635
3636 if ( '' === $current_section ) {
3637 return;
3638 }
3639
3640 switch ( $current_section ) {
3641 case 'addadditionalfield':
3642 case 'editadditionalfield':
3643 $current_settings = get_option( 'propertyhive_template_assistant', array() );
3644 if ( ! is_array( $current_settings ) ) {
3645 $current_settings = array();
3646 }
3647
3648 $current_id = $request_id_present ? sanitize_title( $request_id ) : '';
3649 $existing_custom_fields = ( isset( $current_settings['custom_fields'] ) && is_array( $current_settings['custom_fields'] ) ) ? $current_settings['custom_fields'] : array();
3650
3651 if ( 'editadditionalfield' === $current_section && 'default' !== $current_id && ! isset( $existing_custom_fields[ $current_id ] ) ) {
3652 die( 'Trying to edit a non-existant custom field. Please go back and try again' );
3653 }
3654
3655 $field_label = ( isset( $post_data['field_label'] ) && is_string( $post_data['field_label'] ) ) ? sanitize_text_field( $post_data['field_label'] ) : '';
3656 $field_name = ( isset( $post_data['field_name'] ) && is_string( $post_data['field_name'] ) ) ? sanitize_title( $post_data['field_name'] ) : '';
3657 if ( '' === trim( $field_name ) ) {
3658 $field_name = str_replace( '-', '_', sanitize_title( $field_label ) );
3659 }
3660 $field_name = '_' . ltrim( $field_name, '_' );
3661
3662 $field_type = $this->normalize_custom_fields_field_type( isset( $post_data['field_type'] ) ? $post_data['field_type'] : '' );
3663 $dropdown_options = ( in_array( $field_type, array( 'select', 'multiselect' ), true ) && isset( $post_data['dropdown_options'] ) ) ? $this->normalize_custom_fields_dropdown_options( $post_data['dropdown_options'] ) : '';
3664 $field_settings = array(
3665 'field_label' => $field_label,
3666 'field_name' => $field_name,
3667 'field_type' => $field_type,
3668 'dropdown_options' => $dropdown_options,
3669 'meta_box' => $this->normalize_custom_fields_meta_box( isset( $post_data['meta_box'] ) ? $post_data['meta_box'] : '' ),
3670 'display_on_website' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_website'] ) ? $post_data['display_on_website'] : '' ),
3671 'display_on_applicant_requirements' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_applicant_requirements'] ) ? $post_data['display_on_applicant_requirements'] : '' ),
3672 'exact_match' => $this->normalize_custom_fields_checkbox( isset( $post_data['exact_match'] ) ? $post_data['exact_match'] : '' ),
3673 'display_on_user_details' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_user_details'] ) ? $post_data['display_on_user_details'] : '' ),
3674 'admin_list' => $this->normalize_custom_fields_checkbox( isset( $post_data['admin_list'] ) ? $post_data['admin_list'] : '' ),
3675 'admin_list_sortable' => $this->normalize_custom_fields_checkbox( isset( $post_data['admin_list_sortable'] ) ? $post_data['admin_list_sortable'] : '' ),
3676 );
3677
3678 if ( 'addadditionalfield' === $current_section ) {
3679 $existing_custom_fields[] = $field_settings;
3680 } else {
3681 $existing_custom_fields[ $current_id ] = $field_settings;
3682 }
3683
3684 $current_settings['custom_fields'] = $existing_custom_fields;
3685
3686 if ( 'addadditionalfield' !== $current_section && ! empty( $current_settings['search_forms'] ) && is_array( $current_settings['search_forms'] ) ) {
3687 foreach ( $current_settings['search_forms'] as $search_form_id => $search_form ) {
3688 if ( isset( $search_form['active_fields'] ) && is_array( $search_form['active_fields'] ) ) {
3689 foreach ( $search_form['active_fields'] as $field_id => $field_data ) {
3690 if ( $field_name === $field_id ) {
3691 $current_settings['search_forms'][ $search_form_id ]['active_fields'][ $field_id ]['type'] = $field_type;
3692 }
3693 }
3694 }
3695
3696 if ( isset( $search_form['inactive_fields'] ) && is_array( $search_form['inactive_fields'] ) ) {
3697 foreach ( $search_form['inactive_fields'] as $field_id => $field_data ) {
3698 if ( $field_name === $field_id ) {
3699 $current_settings['search_forms'][ $search_form_id ]['inactive_fields'][ $field_id ]['type'] = $field_type;
3700 }
3701 }
3702 }
3703 }
3704 }
3705
3706 update_option( 'propertyhive_template_assistant', $current_settings );
3707 break;
3708
3709 default:
3710 if ( ! $request_id_present ) {
3711 break;
3712 }
3713
3714 $taxonomy = $this->get_custom_fields_taxonomy_for_section( $current_section );
3715 $is_delete_section = '-delete' === substr( $current_section, -7 );
3716
3717 if ( '' !== $taxonomy ) {
3718 if ( $is_delete_section ) {
3719 $term_ids = $this->normalize_custom_fields_term_id_list( $request_id );
3720 if ( empty( $term_ids ) ) {
3721 return;
3722 }
3723 $current_id = implode( '-', $term_ids );
3724 } else {
3725 $current_id = $this->normalize_custom_fields_term_id( $request_id );
3726 if ( null === $current_id ) {
3727 return;
3728 }
3729 }
3730 } else {
3731 $current_id = sanitize_text_field( $request_id );
3732 }
3733
3734 switch ( $current_section ) {
3735 case 'property-type':
3736 case 'commercial-property-type':
3737 case 'location':
3738 $term_name_key = $taxonomy . '_name';
3739 $parent_key = 'parent_' . $taxonomy . '_id';
3740 $term_name = ( isset( $post_data[ $term_name_key ] ) && is_string( $post_data[ $term_name_key ] ) ) ? sanitize_text_field( $post_data[ $term_name_key ] ) : '';
3741 $parent_id = $this->normalize_custom_fields_parent_id( isset( $post_data[ $parent_key ] ) ? $post_data[ $parent_key ] : '' );
3742 if ( '' === $term_name || null === $parent_id ) {
3743 return;
3744 }
3745
3746 if ( '' === $current_id ) {
3747 wp_insert_term(
3748 $term_name,
3749 $taxonomy,
3750 array( 'parent' => $parent_id )
3751 );
3752 } else {
3753 wp_update_term(
3754 absint( $current_id ),
3755 $taxonomy,
3756 array(
3757 'name' => $term_name,
3758 'parent' => $parent_id,
3759 )
3760 );
3761 }
3762 break;
3763
3764 case 'availability':
3765 case 'outside-space':
3766 case 'parking':
3767 case 'price-qualifier':
3768 case 'sale-by':
3769 case 'tenure':
3770 case 'commercial-tenure':
3771 case 'furnished':
3772 case 'management-key-date-type':
3773 case 'marketing-flag':
3774 case 'property-feature':
3775 $term_name_key = $taxonomy . '_name';
3776 $term_name = ( isset( $post_data[ $term_name_key ] ) && is_string( $post_data[ $term_name_key ] ) ) ? sanitize_text_field( $post_data[ $term_name_key ] ) : '';
3777 if ( '' === $term_name ) {
3778 return;
3779 }
3780
3781 if ( '' === $current_id ) {
3782 $term = wp_insert_term( $term_name, $taxonomy );
3783 if ( ! is_wp_error( $term ) ) {
3784 $current_id = isset( $term['term_id'] ) ? (string) absint( $term['term_id'] ) : '0';
3785 }
3786 } else {
3787 wp_update_term( absint( $current_id ), $taxonomy, array( 'name' => $term_name ) );
3788 }
3789
3790 if ( 'availability' === $current_section ) {
3791 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
3792 if ( ! is_array( $availability_departments ) ) {
3793 $availability_departments = array();
3794 }
3795
3796 $departments = ph_get_departments();
3797 $posted_departments = ( isset( $post_data['department'] ) && is_array( $post_data['department'] ) ) ? $post_data['department'] : array();
3798 $availability_departments[ $current_id ] = array();
3799 foreach ( $departments as $key => $value ) {
3800 if ( isset( $posted_departments[ $key ] ) && is_string( $posted_departments[ $key ] ) && '1' === $posted_departments[ $key ] ) {
3801 $availability_departments[ $current_id ][] = $key;
3802 }
3803 }
3804 update_option( 'propertyhive_availability_departments', $availability_departments );
3805 }
3806
3807 if ( 'management-key-date-type' === $current_section ) {
3808 $options = get_option( 'propertyhive_key_date_type', array() );
3809 if ( ! is_array( $options ) ) {
3810 $options = array();
3811 }
3812
3813 $recurrence = array();
3814 $frequency = ( isset( $post_data['management_key_date_type_recurrence_freq'] ) && is_string( $post_data['management_key_date_type_recurrence_freq'] ) ) ? strtoupper( sanitize_text_field( $post_data['management_key_date_type_recurrence_freq'] ) ) : '';
3815 if ( in_array( $frequency, array( 'ONCE', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY' ), true ) ) {
3816 $recurrence[] = 'FREQ=' . $frequency;
3817 }
3818
3819 $interval = ( isset( $post_data['management_key_date_type_recurrence_interval'] ) && is_string( $post_data['management_key_date_type_recurrence_interval'] ) ) ? trim( $post_data['management_key_date_type_recurrence_interval'] ) : '';
3820 if ( '' !== $interval && preg_match( '/^[1-9][0-9]*$/D', $interval ) ) {
3821 $recurrence[] = 'INTERVAL=' . absint( $interval );
3822 }
3823
3824 $recurrence_type = ( isset( $post_data['management_key_date_type_recurrence_type'] ) && is_string( $post_data['management_key_date_type_recurrence_type'] ) ) ? sanitize_key( $post_data['management_key_date_type_recurrence_type'] ) : '';
3825 if ( ! in_array( $recurrence_type, array( 'tenancy_management', 'property_management' ), true ) ) {
3826 $recurrence_type = '';
3827 }
3828
3829 $options[ $current_id ]['recurrence_rule'] = join( ';', $recurrence );
3830 $options[ $current_id ]['recurrence_type'] = $recurrence_type;
3831 update_option( 'propertyhive_key_date_type', $options );
3832 }
3833 break;
3834
3835 case 'availability-delete':
3836 case 'property-type-delete':
3837 case 'commercial-property-type-delete':
3838 case 'location-delete':
3839 case 'parking-delete':
3840 case 'outside-space-delete':
3841 case 'price-qualifier-delete':
3842 case 'sale-by-delete':
3843 case 'tenure-delete':
3844 case 'commercial-tenure-delete':
3845 case 'furnished-delete':
3846 case 'management-key-date-type-delete':
3847 case 'marketing-flag-delete':
3848 case 'property-feature-delete':
3849 if ( ! isset( $post_data['confirm_removal'] ) || ! is_string( $post_data['confirm_removal'] ) || '1' !== $post_data['confirm_removal'] ) {
3850 break;
3851 }
3852
3853 foreach ( $term_ids as $current_id ) {
3854 $query_args = array(
3855 'post_type' => 'property',
3856 'nopaging' => true,
3857 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
3858 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Term deletion/reassignment must locate all properties or key dates attached to this selected term before removing it.
3859 'tax_query' => array(
3860 array(
3861 'taxonomy' => $taxonomy,
3862 'field' => 'id',
3863 'terms' => $current_id,
3864 ),
3865 ),
3866 );
3867 $property_query = new WP_Query( $query_args );
3868
3869 if ( $property_query->have_posts() ) {
3870 while ( $property_query->have_posts() ) {
3871 $property_query->the_post();
3872 wp_remove_object_terms( $post->ID, $current_id, $taxonomy );
3873
3874 $new_id = $this->normalize_custom_fields_reassignment( isset( $post_data[ 'reassign_to_' . $current_id ] ) ? $post_data[ 'reassign_to_' . $current_id ] : '', $term_ids );
3875 if ( null !== $new_id ) {
3876 wp_set_post_terms( $post->ID, $new_id, $taxonomy, true );
3877 }
3878 }
3879 }
3880 wp_reset_postdata();
3881
3882 if ( 'availability-delete' === $current_section ) {
3883 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
3884 if ( is_array( $availability_departments ) && isset( $availability_departments[ $current_id ] ) ) {
3885 unset( $availability_departments[ $current_id ] );
3886 update_option( 'propertyhive_availability_departments', $availability_departments );
3887 }
3888 }
3889
3890 if ( in_array( $taxonomy, array( 'property_type', 'commercial_property_type', 'location' ), true ) ) {
3891 $query_args = array(
3892 'post_type' => 'contact',
3893 'nopaging' => true,
3894 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
3895 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Applicant preferences are serialized profile metadata; deletion/reassignment must inspect every applicant profile to preserve its other selections.
3896 'meta_query' => array(
3897 array(
3898 'key' => '_contact_types',
3899 'value' => 'applicant',
3900 'compare' => 'LIKE',
3901 ),
3902 ),
3903 );
3904 $applicant_query = new WP_Query( $query_args );
3905
3906 if ( $applicant_query->have_posts() ) {
3907 while ( $applicant_query->have_posts() ) {
3908 $applicant_query->the_post();
3909 $num_applicant_profiles = get_post_meta( get_the_ID(), '_applicant_profiles', true );
3910 if ( '' === $num_applicant_profiles ) {
3911 $num_applicant_profiles = 0;
3912 }
3913
3914 if ( $num_applicant_profiles > 0 ) {
3915 for ( $i = 0; $i < $num_applicant_profiles; ++$i ) {
3916 $applicant_profile = get_post_meta( get_the_ID(), '_applicant_profile_' . $i, true );
3917 $profile_key = $taxonomy . 's';
3918 if ( ! is_array( $applicant_profile ) || ! isset( $applicant_profile[ $profile_key ] ) || ! is_array( $applicant_profile[ $profile_key ] ) ) {
3919 continue;
3920 }
3921
3922 $profile_terms = array();
3923 foreach ( $applicant_profile[ $profile_key ] as $profile_term_id ) {
3924 if ( is_scalar( $profile_term_id ) ) {
3925 $profile_terms[] = (string) absint( $profile_term_id );
3926 }
3927 }
3928 if ( ! in_array( (string) $current_id, $profile_terms, true ) ) {
3929 continue;
3930 }
3931
3932 $profile_terms = array_values( array_filter( $profile_terms, static function ( $profile_term_id ) use ( $current_id ) {
3933 return (string) $profile_term_id !== (string) $current_id;
3934 } ) );
3935 $new_id = $this->normalize_custom_fields_reassignment( isset( $post_data[ 'reassign_to_' . $current_id ] ) ? $post_data[ 'reassign_to_' . $current_id ] : '', $term_ids );
3936 if ( null !== $new_id ) {
3937 $profile_terms[] = $new_id;
3938 }
3939 $applicant_profile[ $profile_key ] = array_values( array_unique( $profile_terms ) );
3940 update_post_meta( get_the_ID(), '_applicant_profile_' . $i, wp_slash( $applicant_profile ) );
3941 }
3942 }
3943 }
3944 }
3945 wp_reset_postdata();
3946 }
3947
3948 wp_delete_term( absint( $current_id ), $taxonomy );
3949 }
3950 break;
3951
3952 default:
3953 $section_found = apply_filters( 'propertyhive_custom_fields_save_section', false, $current_section, $current_id );
3954 if ( ! $section_found ) {
3955 echo 'UNKNOWN CUSTOM FIELD';
3956 }
3957 break;
3958 }
3959 break;
3960 }
3961 }
3962 }
3963
3964 endif;
3965
3966 return new PH_Settings_Custom_Fields();
3967