PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 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 All 261 releases
← All changes | includes/admin/settings/class-ph-settings-custom-fields.php +1976 -556 1.4.52.3.1 View file →
@@ -1,5 +1,8 @@
1 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 +
2 5 /**
3 6 * PropertyHive Custom Fields Settings
4 7 *
5 8 * @author PropertyHive
@@ -16,23 +19,178 @@
16 19
17 20 /**
18 21 * PH_Settings_General
19 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.
20 24 class PH_Settings_Custom_Fields extends PH_Settings_Page {
21 25
26 + const LINKED_POSTS_COLUMN_HEADING = 'Assigned Properties';
27 +
28 + private $custom_field_sections;
29 +
22 30 /**
23 31 * Constructor.
24 32 */
25 33 public function __construct() {
26 34 $this->id = 'customfields';
27 - $this->label = __( 'Custom Fields', 'propertyhive' );
35 + $this->label = __( 'Field Manager', 'propertyhive' );
28 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 +
29 40 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 15 );
30 41 add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) );
31 42 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
32 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();
33 50 }
34 -
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 +
35 193 /**
36 194 * Get sections
37 195 *
38 196 * @return array
@@ -38,32 +196,64 @@
38 196 * @return array
39 197 */
40 198 public function get_sections() {
41 199 $sections = array(
42 - '' => __( 'Custom Fields', 'propertyhive' )
200 + '' => __( 'Field Values', 'propertyhive' ),
201 + 'additional' => __( 'Additional Fields', 'propertyhive' )
43 202 );
44 203
45 - $residential_active = false;
46 - $residential_sales_active = false;
47 - $residential_lettings_active = false;
48 - $commercial_active = false;
204 + return $sections;
205 + }
49 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 +
50 216 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
51 217 {
52 - $residential_active = true;
218 + $residential_active = true;
53 219 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
54 220 {
55 - $residential_sales_active = true;
221 + $residential_sales_active = true;
56 222 }
57 223 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
58 224 {
59 - $residential_lettings_active = true;
225 + $residential_lettings_active = true;
60 226 }
61 227 }
62 228 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
63 229 {
64 - $commercial_active = true;
230 + $commercial_active = true;
65 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 + }
66 256
67 257 // Residential Custom Fields
68 258 $sections[ 'availability' ] = __( 'Availabilities', 'propertyhive' );
69 259 add_action( 'propertyhive_admin_field_custom_fields_availability', array( $this, 'custom_fields_availability_setting' ) );
@@ -114,8 +304,14 @@
114 304 if ( $residential_lettings_active )
115 305 {
116 306 $sections[ 'furnished' ] = __( 'Furnished', 'propertyhive' );
117 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 + }
118 314 }
119 315
120 316 // Other
121 317 $sections[ 'marketing-flag' ] = __( 'Marketing Flags', 'propertyhive' );
@@ -126,9 +322,11 @@
126 322 $sections[ 'property-feature' ] = __( 'Property Features', 'propertyhive' );
127 323 add_action( 'propertyhive_admin_field_custom_fields_property_feature', array( $this, 'custom_fields_property_feature_setting' ) );
128 324 }
129 325
130 - return $sections;
326 + $sections = apply_filters( 'propertyhive_admin_field_custom_fields_sections', $sections );
327 +
328 + $this->custom_field_sections = $sections;
131 329 }
132 330
133 331 /**
134 332 * Get settings array
@@ -138,36 +336,44 @@
138 336 public function get_settings() {
139 337
140 338 global $hide_save_button;
141 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.
142 341 $hide_save_button = true;
143 342
144 - $html = '';
145 -
146 - $sections = $this->get_sections();
147 -
148 - //$sections = array_shift($sections); // Remove 'Custom Fields' from list of custom fields sections
149 343 $i = 0;
150 - foreach ($sections as $key => $value)
344 + $html = '<div class="ph-custom-fields-grid">';
345 + foreach ( $this->custom_field_sections as $key => $value )
151 346 {
152 - if ($i > 0)
347 + $image = 'default.png';
348 + if ( file_exists(PH()->plugin_path() . '/assets/images/admin/settings/custom-fields/' . $key . '.png') )
153 349 {
154 - $html .= '<p><a href="' . admin_url( 'admin.php?page=ph-settings&tab=customfields&section=' . $key ) . '">' . $value . '</a></p>';
350 + $image = $key . '.png';
155 351 }
156 - ++$i;
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>';
157 361 }
362 + $html .= '</div>';
158 363
159 364 return apply_filters( 'propertyhive_custom_fields_settings', array(
160 365
161 - array( 'title' => __( 'Custom Fields', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_options' ),
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' ),
162 367
163 368 array(
164 369 'type' => 'html',
165 - 'title' => __( 'Custom Fields', 'propertyhive' ),
166 - 'html' => $html
370 + 'title' => '',
371 + 'html' => $html,
372 + 'full_width' => true
167 373 ),
168 374
169 - array( 'type' => 'sectionend', 'id' => 'custom_field_options'),
375 + array( 'type' => 'sectionend', 'id' => 'custom_field_options')
170 376
171 377 ));
172 378 }
173 379
@@ -174,72 +380,661 @@
174 380 /**
175 381 * Output the settings
176 382 */
177 383 public function output() {
178 - global $current_section;
384 + global $current_section, $redirect_after_save;
179 385
180 - if ( $current_section ) {
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;
181 396
182 - if (isset($_REQUEST['id'])) // we're either adding or editing
183 - {
184 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
397 + // The main custom field screen listing them in a table
398 + $settings = $this->get_custom_fields_additional_fields_setting();
185 399
186 - switch ($current_section)
400 + PH_Admin_Settings::output_fields( $settings );
401 + break;
402 + }
403 + case "addadditionalfield":
404 + case "editadditionalfield":
187 405 {
188 - case "availability": { $settings = $this->get_custom_fields_availability_setting(); break; }
189 - case "availability-delete": { $settings = $this->get_custom_fields_delete($current_id, 'availability', __( 'Availability', 'propertyhive' )); break; }
190 - case "property-type": { $settings = $this->get_custom_fields_property_type_setting(); break; }
191 - case "property-type-delete": { $settings = $this->get_custom_fields_delete($current_id, 'property_type', __( 'Property Type', 'propertyhive' )); break; }
192 - case "commercial-property-type": { $settings = $this->get_custom_fields_commercial_property_type_setting(); break; }
193 - case "commercial-property-type-delete": { $settings = $this->get_custom_fields_delete($current_id, 'commercial_property_type', __( 'Property Type', 'propertyhive' )); break; }
194 - case "location": { $settings = $this->get_custom_fields_location_setting(); break; }
195 - case "location-delete": { $settings = $this->get_custom_fields_delete($current_id, 'location', __( 'Location', 'propertyhive' )); break; }
196 - case "parking": { $settings = $this->get_custom_fields_parking_setting(); break; }
197 - case "parking-delete": { $settings = $this->get_custom_fields_delete($current_id, 'parking', __( 'Parking', 'propertyhive' )); break; }
198 - case "outside-space": { $settings = $this->get_custom_fields_outside_space_setting(); break; }
199 - case "outside-space-delete": { $settings = $this->get_custom_fields_delete($current_id, 'outside_space', __( 'Outside Space', 'propertyhive' )); break; }
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);
200 484
201 - case "price-qualifier": { $settings = $this->get_custom_fields_price_qualifier_setting(); break; }
202 - case "price-qualifier-delete": { $settings = $this->get_custom_fields_delete($current_id, 'price_qualifier', __( 'Price Qualifier', 'propertyhive' )); break; }
203 - case "sale-by": { $settings = $this->get_custom_fields_sale_by_setting(); break; }
204 - case "sale-by-delete": { $settings = $this->get_custom_fields_delete($current_id, 'sale_by', __( 'Sale By', 'propertyhive' )); break; }
205 - case "tenure": { $settings = $this->get_custom_fields_tenure_setting(); break; }
206 - case "tenure-delete": { $settings = $this->get_custom_fields_delete($current_id, 'tenure', __( 'Tenure', 'propertyhive' )); break; }
207 - case "commercial-tenure": { $settings = $this->get_custom_fields_commercial_tenure_setting(); break; }
208 - case "commercial-tenure-delete": { $settings = $this->get_custom_fields_delete($current_id, 'commercial_tenure', __( 'Tenure', 'propertyhive' )); break; }
209 -
210 - case "furnished": { $settings = $this->get_custom_fields_furnished_setting(); break; }
211 - case "furnished-delete": { $settings = $this->get_custom_fields_delete($current_id, 'furnished', __( 'Furnished', 'propertyhive' )); break; }
485 + PH_Admin_Settings::output_fields( $settings );
486 + }
487 + }
488 + }
489 + }
490 + else
491 + {
492 + $settings = $this->get_settings();
212 493
213 - case "marketing-flag": { $settings = $this->get_custom_fields_marketing_flag_setting(); break; }
214 - case "marketing-flag-delete": { $settings = $this->get_custom_fields_delete($current_id, 'marketing_flag', __( 'Marketing Flag', 'propertyhive' )); break; }
215 -
216 - case "property-feature": { $settings = $this->get_custom_fields_property_feature_setting(); break; }
217 - case "property-feature-delete": { $settings = $this->get_custom_fields_delete($current_id, 'property_feature', __( 'Property Feature', 'propertyhive' )); break; }
218 -
494 + PH_Admin_Settings::output_fields( $settings );
495 + }
496 + }
219 497
220 - default: { echo 'UNKNOWN CUSTOM FIELD'; }
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 + }
221 758 }
222 -
223 - PH_Admin_Settings::output_fields( $settings );
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];
224 787 }
225 788 else
226 789 {
227 - global $hide_save_button;
228 -
229 - $hide_save_button = true;
230 -
231 - // The main custom field screen listing them in a table
232 - $settings = $this->get_custom_fields_setting($current_section);
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' ),
233 894
234 - PH_Admin_Settings::output_fields( $settings );
235 - }
895 + array(
896 + 'type' => 'additional_fields_table',
897 + ),
236 898
237 - } else {
238 - $settings = $this->get_settings();
899 + array( 'type' => 'sectionend', 'id' => 'additional_field_options')
900 +
901 + ));
902 + }
239 903
240 - PH_Admin_Settings::output_fields( $settings );
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 + }
241 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 "> ⇅ </span>' . esc_html($custom_field['field_label']) . '</td>';
956 + echo '<td class="section">' . esc_html(ucwords( str_replace("_", " ", $custom_field['meta_box']) )) . '</td>';
957 + echo '<td class="usage">';
958 + 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 '-';}
959 + echo '</td>';
960 + echo '<td class="website">';
961 + 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 '-'; }
962 + echo '</td>';
963 + echo '<td class="admin-list">';
964 + echo esc_html( ( ( isset($custom_field['admin_list']) && $custom_field['admin_list'] == '1' ) ? __( 'Yes', 'propertyhive' ) : __( 'No', 'propertyhive' ) ) );
965 + echo '</td>';
966 + echo '<td class="sorting">';
967 + if ( ( isset($custom_field['admin_list']) && $custom_field['admin_list'] == '1' ) )
968 + {
969 + echo esc_html( ( ( isset($custom_field['admin_list_sortable']) && $custom_field['admin_list_sortable'] == '1' ) ? __( 'Yes', 'propertyhive' ) : __( 'No', 'propertyhive' ) ) );
970 + }
971 + else
972 + {
973 + echo '-';
974 + }
975 + echo '</td>';
976 +
977 + $delete_url = wp_nonce_url(
978 + admin_url(
979 + 'admin.php?page=ph-settings&tab=customfields&section=additional&action=deleteadditionalfield&id=' . rawurlencode( $id )
980 + ),
981 + 'propertyhive_delete_additional_field'
982 + );
983 +
984 + echo '<td class="settings">
985 + <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>
986 + <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>
987 + </td>';
988 + echo '</tr>';
989 + }
990 + }
991 + else
992 + {
993 + echo '<tr>';
994 + echo '<td align="center" colspan="7">' . esc_html(__( 'No additional fields exist', 'propertyhive' )) . '</td>';
995 + echo '</tr>';
996 + }
997 + ?>
998 + </tbody>
999 + </table>
1000 +
1001 + <script>
1002 + jQuery( function($){
1003 +
1004 + $('.ph_additional_fields tbody.has-rows').sortable({
1005 + opacity: 0.8,
1006 + revert: true,
1007 + handle: ".sort_anchor",
1008 + update : function (event, ui)
1009 + {
1010 + $('.ph_additional_fields tbody.has-rows').sortable( "destroy" );
1011 +
1012 + var new_order = '';
1013 + jQuery('.ph_additional_fields tbody.has-rows').find('tr').each( function ()
1014 + {
1015 + if (new_order != '')
1016 + {
1017 + new_order += ',';
1018 + }
1019 + new_order = new_order + jQuery(this).attr('id').replace('custom_field_', '');
1020 + });
1021 +
1022 + // reload page
1023 + 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 );
1024 + }
1025 + });
1026 +
1027 + });
1028 + </script>
1029 + </td>
1030 + </tr>
1031 + <tr valign="top">
1032 + <td class="forminp forminp-button">
1033 + <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>
1034 + </td>
1035 + </tr>
1036 +<?php
242 1037 }
243 1038
244 1039 /**
245 1040 * Output custom fields settings.
@@ -248,9 +1043,9 @@
248 1043 * @return void
249 1044 */
250 1045 public function get_custom_fields_setting($current_section) {
251 1046
252 - $sections = $this->get_sections();
1047 + $sections = $this->custom_field_sections;
253 1048
254 1049 return apply_filters( 'propertyhive_custom_fields_' . $current_section . '_settings', array(
255 1050
256 1051 array( 'title' => $sections[$current_section], 'type' => 'title', 'desc' => '', 'id' => 'custom_fields_' . $current_section . '_options' ),
@@ -272,8 +1067,13 @@
272 1067 * @return void
273 1068 */
274 1069 public function custom_fields_availability_setting() {
275 1070 global $post;
1071 +
1072 + $departments = ph_get_departments();
1073 +
1074 + $availability_departments = get_option( 'propertyhive_availability_departments', array() );
1075 + if ( !is_array($availability_departments) ) { $availability_departments = array(); }
276 1076 ?>
277 1077 <tr valign="top">
278 1078 <th scope="row" class="titledesc">
279 1079 &nbsp;
@@ -278,20 +1078,24 @@
278 1078 <th scope="row" class="titledesc">
279 1079 &nbsp;
280 1080 </th>
281 1081 <td class="forminp forminp-button">
282 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
283 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Availability', 'propertyhive' ); ?></a>
1082 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1083 + <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>
284 1084 </td>
285 1085 </tr>
286 1086 <tr valign="top">
287 - <th scope="row" class="titledesc"><?php _e( 'Availability Options', 'propertyhive' ) ?></th>
1087 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Availability Options', 'propertyhive' )); ?></th>
288 1088 <td class="forminp">
289 - <table class="ph_customfields widefat" cellspacing="0">
1089 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="availability" cellspacing="0">
290 1090 <thead>
291 1091 <tr>
292 - <th class="cb" style="width:1px;">&nbsp;</th>
293 - <th class="type"><?php _e( 'Availability', 'propertyhive' ); ?></th>
1092 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1093 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1094 + <?php do_action( 'propertyhive_custom_field_availability_table_before_header_column' ); ?>
1095 + <th class="type"><?php echo esc_html(__( 'Availability', 'propertyhive' )); ?></th>
1096 + <th class="department"><?php echo esc_html(__( 'Applies To', 'propertyhive' )); ?></th>
1097 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
294 1098 <th class="settings">&nbsp;</th>
295 1099 </tr>
296 1100 </thead>
297 1101 <tbody>
@@ -299,21 +1103,49 @@
299 1103 $args = array(
300 1104 'hide_empty' => false,
301 1105 'parent' => 0
302 1106 );
303 - $terms = get_terms( 'availability', $args );
1107 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'availability' ) ) );
304 1108
305 1109 if ( !empty( $terms ) && !is_wp_error( $terms ) )
306 1110 {
307 - foreach ($terms as $term)
308 - {
1111 + foreach ( $terms as $term )
1112 + {
309 1113 ?>
310 - <tr>
311 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
312 - <td class="type"><?php echo $term->name; ?></td>
1114 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1115 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1116 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1117 + <?php do_action( 'propertyhive_custom_field_availability_table_before_row_column', $term->term_id ); ?>
1118 + <td class="type"><?php echo esc_html($term->name); ?></td>
1119 + <td class="department"><?php
1120 + $this_availability_departments = array();
1121 + if ( isset($availability_departments[$term->term_id]) )
1122 + {
1123 + foreach ( $availability_departments[$term->term_id] as $availability_department )
1124 + {
1125 + if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $availability_department) ) == 'yes' )
1126 + {
1127 + $this_availability_departments[] = $departments[$availability_department];
1128 + }
1129 + }
1130 + }
1131 + else
1132 + {
1133 + foreach ( $departments as $key => $value )
1134 + {
1135 + if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
1136 + {
1137 + $this_availability_departments[] = $value;
1138 + }
1139 + }
1140 + }
1141 +
1142 + echo !empty($this_availability_departments) ? esc_html(implode(", ", $this_availability_departments)) : '-';
1143 + ?></td>
1144 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
313 1145 <td class="settings">
314 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
315 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1146 + <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>
1147 + <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>
316 1148 </td>
317 1149 </tr>
318 1150 <?php
319 1151 }
@@ -321,12 +1153,9 @@
321 1153 else
322 1154 {
323 1155 ?>
324 1156 <tr>
325 - <td><?php echo __( 'No availability options found', 'propertyhive' ); ?></td>
326 - <td class="settings">
327 -
328 - </td>
1157 + <td colspan="6"><?php echo esc_html(__( 'No availability options found', 'propertyhive' )); ?></td>
329 1158 </tr>
330 1159 <?php
331 1160 }
332 1161 ?>
@@ -338,10 +1167,10 @@
338 1167 <th scope="row" class="titledesc">
339 1168 &nbsp;
340 1169 </th>
341 1170 <td class="forminp forminp-button">
342 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
343 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=availability&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Availability', 'propertyhive' ); ?></a>
1171 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1172 + <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>
344 1173 </td>
345 1174 </tr>
346 1175 <?php
347 1176 }
@@ -359,21 +1188,23 @@
359 1188 <th scope="row" class="titledesc">
360 1189 &nbsp;
361 1190 </th>
362 1191 <td class="forminp forminp-button">
363 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
364 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Type', 'propertyhive' ); ?></a>
1192 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1193 + <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>
365 1194 </td>
366 1195 </tr>
367 1196 <tr valign="top">
368 - <th scope="row" class="titledesc"><?php _e( 'Property Types', 'propertyhive' ) ?></th>
1197 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Types', 'propertyhive' )); ?></th>
369 1198 <td class="forminp">
370 1199 <table class="ph_customfields widefat" cellspacing="0">
371 1200 <thead>
372 1201 <tr>
373 - <th class="cb" style="width:1px;">&nbsp;</th>
1202 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1203 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
374 1204 <?php do_action( 'propertyhive_custom_field_property_type_table_before_header_column' ); ?>
375 - <th class="type"><?php _e( 'Property Type', 'propertyhive' ); ?></th>
1205 + <th class="type"><?php echo esc_html(__( 'Property Type', 'propertyhive' )); ?></th>
1206 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
376 1207 <th class="settings">&nbsp;</th>
377 1208 </tr>
378 1209 </thead>
379 1210 <tbody>
@@ -381,10 +1212,10 @@
381 1212 $args = array(
382 1213 'hide_empty' => false,
383 1214 'parent' => 0
384 1215 );
385 - $terms = get_terms( 'property_type', $args );
386 -
1216 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
1217 +
387 1218 if ( !empty( $terms ) && !is_wp_error( $terms ) )
388 1219 {
389 1220 foreach ($terms as $term)
390 1221 {
@@ -393,18 +1224,20 @@
393 1224 $args = array(
394 1225 'hide_empty' => false,
395 1226 'parent' => $parent_term_id
396 1227 );
397 - $subterms = get_terms( 'property_type', $args );
1228 + $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
398 1229 ?>
399 1230 <tr>
400 - <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1231 + <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>
1232 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
401 1233 <?php do_action( 'propertyhive_custom_field_property_type_table_before_row_column', $term->term_id ); ?>
402 - <td class="type"><?php echo $term->name; ?></td>
1234 + <td class="type"><?php echo esc_html($term->name); ?></td>
1235 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
403 1236 <td class="settings">
404 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1237 + <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>
405 1238 <?php if ( empty( $subterms ) ) { ?>
406 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1239 + <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>
407 1240 <?php } ?>
408 1241 </td>
409 1242 </tr>
410 1243 <?php
@@ -413,14 +1246,16 @@
413 1246 foreach ($subterms as $term)
414 1247 {
415 1248 ?>
416 1249 <tr>
417 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1250 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1251 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
418 1252 <?php do_action( 'propertyhive_custom_field_property_type_table_before_row_column', $term->term_id, $parent_term_id ); ?>
419 - <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo $term->name; ?></td>
1253 + <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1254 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
420 1255 <td class="settings">
421 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
422 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1256 + <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>
1257 + <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>
423 1258 </td>
424 1259 </tr>
425 1260 <?php
426 1261 }
@@ -432,9 +1267,9 @@
432 1267 else
433 1268 {
434 1269 ?>
435 1270 <tr>
436 - <td colspan="3"><?php echo __( 'No property types found', 'propertyhive' ); ?></td>
1271 + <td colspan="5"><?php echo esc_html(__( 'No property types found', 'propertyhive' )); ?></td>
437 1272 </tr>
438 1273 <?php
439 1274 }
440 1275 ?>
@@ -446,10 +1281,10 @@
446 1281 <th scope="row" class="titledesc">
447 1282 &nbsp;
448 1283 </th>
449 1284 <td class="forminp forminp-button">
450 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
451 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-type&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Type', 'propertyhive' ); ?></a>
1285 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1286 + <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>
452 1287 </td>
453 1288 </tr>
454 1289 <?php
455 1290 }
@@ -467,21 +1302,23 @@
467 1302 <th scope="row" class="titledesc">
468 1303 &nbsp;
469 1304 </th>
470 1305 <td class="forminp forminp-button">
471 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
472 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Type', 'propertyhive' ); ?></a>
1306 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1307 + <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>
473 1308 </td>
474 1309 </tr>
475 1310 <tr valign="top">
476 - <th scope="row" class="titledesc"><?php _e( 'Property Types', 'propertyhive' ) ?></th>
1311 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Types', 'propertyhive' )); ?></th>
477 1312 <td class="forminp">
478 1313 <table class="ph_customfields widefat" cellspacing="0">
479 1314 <thead>
480 1315 <tr>
481 - <th class="cb" style="width:1px;">&nbsp;</th>
1316 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1317 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
482 1318 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_header_column' ); ?>
483 - <th class="type"><?php _e( 'Property Type', 'propertyhive' ); ?></th>
1319 + <th class="type"><?php echo esc_html(__( 'Property Type', 'propertyhive' )); ?></th>
1320 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
484 1321 <th class="settings">&nbsp;</th>
485 1322 </tr>
486 1323 </thead>
487 1324 <tbody>
@@ -489,9 +1326,9 @@
489 1326 $args = array(
490 1327 'hide_empty' => false,
491 1328 'parent' => 0
492 1329 );
493 - $terms = get_terms( 'commercial_property_type', $args );
1330 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
494 1331
495 1332 if ( !empty( $terms ) && !is_wp_error( $terms ) )
496 1333 {
497 1334 foreach ($terms as $term)
@@ -501,18 +1338,20 @@
501 1338 $args = array(
502 1339 'hide_empty' => false,
503 1340 'parent' => $parent_term_id
504 1341 );
505 - $subterms = get_terms( 'commercial_property_type', $args );
1342 + $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
506 1343 ?>
507 1344 <tr>
508 - <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"><?php }else{ echo '&nbsp;'; } ?></td>
1345 + <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>
1346 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
509 1347 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_row_column', $term->term_id ); ?>
510 - <td class="type"><?php echo $term->name; ?></td>
1348 + <td class="type"><?php echo esc_html($term->name); ?></td>
1349 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
511 1350 <td class="settings">
512 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1351 + <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>
513 1352 <?php if ( empty( $subterms ) ) { ?>
514 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1353 + <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>
515 1354 <?php } ?>
516 1355 </td>
517 1356 </tr>
518 1357 <?php
@@ -521,14 +1360,16 @@
521 1360 foreach ($subterms as $term)
522 1361 {
523 1362 ?>
524 1363 <tr>
525 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1364 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1365 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
526 1366 <?php do_action( 'propertyhive_custom_field_commercial_property_type_table_before_row_column', $term->term_id, $parent_term_id ); ?>
527 - <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo $term->name; ?></td>
1367 + <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1368 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
528 1369 <td class="settings">
529 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
530 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1370 + <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>
1371 + <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>
531 1372 </td>
532 1373 </tr>
533 1374 <?php
534 1375 }
@@ -540,9 +1381,9 @@
540 1381 else
541 1382 {
542 1383 ?>
543 1384 <tr>
544 - <td colspan="3"><?php echo __( 'No property types found', 'propertyhive' ); ?></td>
1385 + <td colspan="5"><?php echo esc_html(__( 'No property types found', 'propertyhive' )); ?></td>
545 1386 </tr>
546 1387 <?php
547 1388 }
548 1389 ?>
@@ -554,10 +1395,10 @@
554 1395 <th scope="row" class="titledesc">
555 1396 &nbsp;
556 1397 </th>
557 1398 <td class="forminp forminp-button">
558 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
559 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-property-type&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Type', 'propertyhive' ); ?></a>
1399 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1400 + <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>
560 1401 </td>
561 1402 </tr>
562 1403 <?php
563 1404 }
@@ -575,20 +1416,22 @@
575 1416 <th scope="row" class="titledesc">
576 1417 &nbsp;
577 1418 </th>
578 1419 <td class="forminp forminp-button">
579 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
580 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Location', 'propertyhive' ); ?></a>
1420 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1421 + <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>
581 1422 </td>
582 1423 </tr>
583 1424 <tr valign="top">
584 - <th scope="row" class="titledesc"><?php _e( 'Locations', 'propertyhive' ) ?></th>
1425 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Locations', 'propertyhive' )); ?></th>
585 1426 <td class="forminp">
586 1427 <table class="ph_customfields widefat" cellspacing="0">
587 1428 <thead>
588 1429 <tr>
589 - <th class="cb" style="width:1px;">&nbsp;</th>
590 - <th class="type"><?php _e( 'Location', 'propertyhive' ); ?></th>
1430 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1431 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1432 + <th class="type"><?php echo esc_html(__( 'Location', 'propertyhive' )); ?></th>
1433 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
591 1434 <th class="settings">&nbsp;</th>
592 1435 </tr>
593 1436 </thead>
594 1437 <tbody>
@@ -596,9 +1439,9 @@
596 1439 $args = array(
597 1440 'hide_empty' => false,
598 1441 'parent' => 0
599 1442 );
600 - $terms = get_terms( 'location', $args );
1443 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
601 1444
602 1445 if ( !empty( $terms ) && !is_wp_error( $terms ) )
603 1446 {
604 1447 foreach ($terms as $term)
@@ -606,17 +1449,19 @@
606 1449 $args = array(
607 1450 'hide_empty' => false,
608 1451 'parent' => $term->term_id
609 1452 );
610 - $subterms = get_terms( 'location', $args );
1453 + $subterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
611 1454 ?>
612 1455 <tr>
613 - <td class="cb"><?php if ( empty( $subterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"><?php }else{ echo '&nbsp;'; } ?></td>
614 - <td class="type"><?php echo $term->name; ?></td>
1456 + <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>
1457 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1458 + <td class="type"><?php echo esc_html($term->name); ?></td>
1459 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
615 1460 <td class="settings">
616 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1461 + <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>
617 1462 <?php if ( empty( $subterms ) ) { ?>
618 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1463 + <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>
619 1464 <?php } ?>
620 1465 </td>
621 1466 </tr>
622 1467 <?php
@@ -627,17 +1472,19 @@
627 1472 $args = array(
628 1473 'hide_empty' => false,
629 1474 'parent' => $term->term_id
630 1475 );
631 - $subsubterms = get_terms( 'location', $args );
1476 + $subsubterms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'location' ) ) );
632 1477 ?>
633 1478 <tr>
634 - <td class="cb"><?php if ( empty( $subsubterms ) ) { ?><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"><?php }else{ echo '&nbsp;'; } ?></td>
635 - <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo $term->name; ?></td>
1479 + <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>
1480 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1481 + <td class="type subtype">&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1482 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
636 1483 <td class="settings">
637 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1484 + <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>
638 1485 <?php if ( empty( $subsubterms ) ) { ?>
639 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1486 + <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>
640 1487 <?php } ?>
641 1488 </td>
642 1489 </tr>
643 1490 <?php
@@ -646,13 +1493,15 @@
646 1493 foreach ($subsubterms as $term)
647 1494 {
648 1495 ?>
649 1496 <tr>
650 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
651 - <td class="type subtype">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- <?php echo $term->name; ?></td>
1497 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1498 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1499 + <td class="type subtype">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- <?php echo esc_html($term->name); ?></td>
1500 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
652 1501 <td class="settings">
653 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
654 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1502 + <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>
1503 + <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>
655 1504 </td>
656 1505 </tr>
657 1506 <?php
658 1507 }
@@ -666,12 +1515,9 @@
666 1515 else
667 1516 {
668 1517 ?>
669 1518 <tr>
670 - <td><?php echo __( 'No locations found', 'propertyhive' ); ?></td>
671 - <td class="settings">
672 -
673 - </td>
1519 + <td colspan="5"><?php echo esc_html(__( 'No locations found', 'propertyhive' )); ?></td>
674 1520 </tr>
675 1521 <?php
676 1522 }
677 1523 ?>
@@ -683,10 +1529,10 @@
683 1529 <th scope="row" class="titledesc">
684 1530 &nbsp;
685 1531 </th>
686 1532 <td class="forminp forminp-button">
687 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
688 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=location&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Location', 'propertyhive' ); ?></a>
1533 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1534 + <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>
689 1535 </td>
690 1536 </tr>
691 1537 <?php
692 1538 }
@@ -704,20 +1550,22 @@
704 1550 <th scope="row" class="titledesc">
705 1551 &nbsp;
706 1552 </th>
707 1553 <td class="forminp forminp-button">
708 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
709 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Parking', 'propertyhive' ); ?></a>
1554 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1555 + <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>
710 1556 </td>
711 1557 </tr>
712 1558 <tr valign="top">
713 - <th scope="row" class="titledesc"><?php _e( 'Parking Options', 'propertyhive' ) ?></th>
1559 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Parking Options', 'propertyhive' )); ?></th>
714 1560 <td class="forminp">
715 - <table class="ph_customfields widefat" cellspacing="0">
1561 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="parking" cellspacing="0">
716 1562 <thead>
717 1563 <tr>
718 - <th class="cb" style="width:1px;">&nbsp;</th>
719 - <th class="type"><?php _e( 'Parking', 'propertyhive' ); ?></th>
1564 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1565 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1566 + <th class="type"><?php echo esc_html(__( 'Parking', 'propertyhive' )); ?></th>
1567 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
720 1568 <th class="settings">&nbsp;</th>
721 1569 </tr>
722 1570 </thead>
723 1571 <tbody>
@@ -725,21 +1573,23 @@
725 1573 $args = array(
726 1574 'hide_empty' => false,
727 1575 'parent' => 0
728 1576 );
729 - $terms = get_terms( 'parking', $args );
730 -
1577 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'parking' ) ) );
1578 +
731 1579 if ( !empty( $terms ) && !is_wp_error( $terms ) )
732 1580 {
733 1581 foreach ($terms as $term)
734 1582 {
735 1583 ?>
736 - <tr>
737 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
738 - <td class="type"><?php echo $term->name; ?></td>
1584 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1585 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1586 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1587 + <td class="type"><?php echo esc_html($term->name); ?></td>
1588 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
739 1589 <td class="settings">
740 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
741 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1590 + <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>
1591 + <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>
742 1592 </td>
743 1593 </tr>
744 1594 <?php
745 1595 }
@@ -747,12 +1597,9 @@
747 1597 else
748 1598 {
749 1599 ?>
750 1600 <tr>
751 - <td><?php echo __( 'No parking options found', 'propertyhive' ); ?></td>
752 - <td class="settings">
753 -
754 - </td>
1601 + <td colspan="5"><?php echo esc_html(__( 'No parking options found', 'propertyhive' )); ?></td>
755 1602 </tr>
756 1603 <?php
757 1604 }
758 1605 ?>
@@ -764,10 +1611,10 @@
764 1611 <th scope="row" class="titledesc">
765 1612 &nbsp;
766 1613 </th>
767 1614 <td class="forminp forminp-button">
768 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
769 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=parking&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Parking', 'propertyhive' ); ?></a>
1615 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1616 + <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>
770 1617 </td>
771 1618 </tr>
772 1619 <?php
773 1620 }
@@ -785,20 +1632,22 @@
785 1632 <th scope="row" class="titledesc">
786 1633 &nbsp;
787 1634 </th>
788 1635 <td class="forminp forminp-button">
789 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
790 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Outside Space', 'propertyhive' ); ?></a>
1636 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1637 + <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>
791 1638 </td>
792 1639 </tr>
793 1640 <tr valign="top">
794 - <th scope="row" class="titledesc"><?php _e( 'Outside Spaces', 'propertyhive' ) ?></th>
1641 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Outside Spaces', 'propertyhive' )); ?></th>
795 1642 <td class="forminp">
796 - <table class="ph_customfields widefat" cellspacing="0">
1643 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="outside_space" cellspacing="0">
797 1644 <thead>
798 1645 <tr>
799 - <th class="cb" style="width:1px;">&nbsp;</th>
800 - <th class="type"><?php _e( 'Outside Space', 'propertyhive' ); ?></th>
1646 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1647 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1648 + <th class="type"><?php echo esc_html(__( 'Outside Space', 'propertyhive' )); ?></th>
1649 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
801 1650 <th class="settings">&nbsp;</th>
802 1651 </tr>
803 1652 </thead>
804 1653 <tbody>
@@ -806,9 +1655,9 @@
806 1655 $args = array(
807 1656 'hide_empty' => false,
808 1657 'parent' => 0
809 1658 );
810 - $terms = get_terms( 'outside_space', $args );
1659 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'outside_space' ) ) );
811 1660
812 1661 if ( !empty( $terms ) && !is_wp_error( $terms ) )
813 1662 {
814 1663 foreach ($terms as $term)
@@ -813,14 +1662,16 @@
813 1662 {
814 1663 foreach ($terms as $term)
815 1664 {
816 1665 ?>
817 - <tr>
818 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
819 - <td class="type"><?php echo $term->name; ?></td>
1666 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1667 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1668 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1669 + <td class="type"><?php echo esc_html($term->name); ?></td>
1670 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
820 1671 <td class="settings">
821 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
822 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1672 + <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>
1673 + <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>
823 1674 </td>
824 1675 </tr>
825 1676 <?php
826 1677 }
@@ -828,12 +1679,9 @@
828 1679 else
829 1680 {
830 1681 ?>
831 1682 <tr>
832 - <td><?php echo __( 'No outside spaces found', 'propertyhive' ); ?></td>
833 - <td class="settings">
834 -
835 - </td>
1683 + <td colspan="5"><?php echo esc_html(__( 'No outside spaces found', 'propertyhive' )); ?></td>
836 1684 </tr>
837 1685 <?php
838 1686 }
839 1687 ?>
@@ -845,10 +1693,10 @@
845 1693 <th scope="row" class="titledesc">
846 1694 &nbsp;
847 1695 </th>
848 1696 <td class="forminp forminp-button">
849 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
850 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=outside-space&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Outside Space', 'propertyhive' ); ?></a>
1697 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1698 + <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>
851 1699 </td>
852 1700 </tr>
853 1701 <?php
854 1702 }
@@ -866,20 +1714,22 @@
866 1714 <th scope="row" class="titledesc">
867 1715 &nbsp;
868 1716 </th>
869 1717 <td class="forminp forminp-button">
870 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
871 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Price Qualifier', 'propertyhive' ); ?></a>
1718 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1719 + <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>
872 1720 </td>
873 1721 </tr>
874 1722 <tr valign="top">
875 - <th scope="row" class="titledesc"><?php _e( 'Price Qualifiers', 'propertyhive' ) ?></th>
1723 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Price Qualifiers', 'propertyhive' )); ?></th>
876 1724 <td class="forminp">
877 - <table class="ph_customfields widefat" cellspacing="0">
1725 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="price_qualifier" cellspacing="0">
878 1726 <thead>
879 1727 <tr>
880 - <th class="cb" style="width:1px;">&nbsp;</th>
881 - <th class="type"><?php _e( 'Price Qualifier', 'propertyhive' ); ?></th>
1728 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1729 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1730 + <th class="type"><?php echo esc_html(__( 'Price Qualifier', 'propertyhive' )); ?></th>
1731 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
882 1732 <th class="settings">&nbsp;</th>
883 1733 </tr>
884 1734 </thead>
885 1735 <tbody>
@@ -887,9 +1737,9 @@
887 1737 $args = array(
888 1738 'hide_empty' => false,
889 1739 'parent' => 0
890 1740 );
891 - $terms = get_terms( 'price_qualifier', $args );
1741 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'price_qualifier' ) ) );
892 1742
893 1743 if ( !empty( $terms ) && !is_wp_error( $terms ) )
894 1744 {
895 1745 foreach ($terms as $term)
@@ -894,14 +1744,16 @@
894 1744 {
895 1745 foreach ($terms as $term)
896 1746 {
897 1747 ?>
898 - <tr>
899 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
900 - <td class="type"><?php echo $term->name; ?></td>
1748 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1749 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1750 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1751 + <td class="type"><?php echo esc_html($term->name); ?></td>
1752 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
901 1753 <td class="settings">
902 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
903 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1754 + <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>
1755 + <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>
904 1756 </td>
905 1757 </tr>
906 1758 <?php
907 1759 }
@@ -909,12 +1761,9 @@
909 1761 else
910 1762 {
911 1763 ?>
912 1764 <tr>
913 - <td><?php echo __( 'No price qualifiers found', 'propertyhive' ); ?></td>
914 - <td class="settings">
915 -
916 - </td>
1765 + <td colspan="5"><?php echo esc_html(__( 'No price qualifiers found', 'propertyhive' )); ?></td>
917 1766 </tr>
918 1767 <?php
919 1768 }
920 1769 ?>
@@ -926,10 +1775,10 @@
926 1775 <th scope="row" class="titledesc">
927 1776 &nbsp;
928 1777 </th>
929 1778 <td class="forminp forminp-button">
930 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
931 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=price-qualifier&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Price Qualifier', 'propertyhive' ); ?></a>
1779 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1780 + <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>
932 1781 </td>
933 1782 </tr>
934 1783 <?php
935 1784 }
@@ -947,20 +1796,22 @@
947 1796 <th scope="row" class="titledesc">
948 1797 &nbsp;
949 1798 </th>
950 1799 <td class="forminp forminp-button">
951 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
952 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Sale By', 'propertyhive' ); ?></a>
1800 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1801 + <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>
953 1802 </td>
954 1803 </tr>
955 1804 <tr valign="top">
956 - <th scope="row" class="titledesc"><?php _e( 'Sale By Options', 'propertyhive' ) ?></th>
1805 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Sale By Options', 'propertyhive' )); ?></th>
957 1806 <td class="forminp">
958 - <table class="ph_customfields widefat" cellspacing="0">
1807 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="sale_by" cellspacing="0">
959 1808 <thead>
960 1809 <tr>
961 - <th class="cb" style="width:1px;">&nbsp;</th>
962 - <th class="type"><?php _e( 'Sale By', 'propertyhive' ); ?></th>
1810 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1811 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1812 + <th class="type"><?php echo esc_html(__( 'Sale By', 'propertyhive' )); ?></th>
1813 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
963 1814 <th class="settings">&nbsp;</th>
964 1815 </tr>
965 1816 </thead>
966 1817 <tbody>
@@ -968,9 +1819,9 @@
968 1819 $args = array(
969 1820 'hide_empty' => false,
970 1821 'parent' => 0
971 1822 );
972 - $terms = get_terms( 'sale_by', $args );
1823 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'sale_by' ) ) );
973 1824
974 1825 if ( !empty( $terms ) && !is_wp_error( $terms ) )
975 1826 {
976 1827 foreach ($terms as $term)
@@ -976,13 +1827,15 @@
976 1827 foreach ($terms as $term)
977 1828 {
978 1829 ?>
979 1830 <tr>
980 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
981 - <td class="type"><?php echo $term->name; ?></td>
1831 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1832 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1833 + <td class="type"><?php echo esc_html($term->name); ?></td>
1834 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
982 1835 <td class="settings">
983 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
984 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1836 + <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>
1837 + <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>
985 1838 </td>
986 1839 </tr>
987 1840 <?php
988 1841 }
@@ -990,12 +1843,9 @@
990 1843 else
991 1844 {
992 1845 ?>
993 1846 <tr>
994 - <td><?php echo __( 'No sale by options found', 'propertyhive' ); ?></td>
995 - <td class="settings">
996 -
997 - </td>
1847 + <td colspan="5"><?php echo esc_html(__( 'No sale by options found', 'propertyhive' )); ?></td>
998 1848 </tr>
999 1849 <?php
1000 1850 }
1001 1851 ?>
@@ -1007,10 +1857,10 @@
1007 1857 <th scope="row" class="titledesc">
1008 1858 &nbsp;
1009 1859 </th>
1010 1860 <td class="forminp forminp-button">
1011 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1012 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=sale-by&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Sale By', 'propertyhive' ); ?></a>
1861 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1862 + <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>
1013 1863 </td>
1014 1864 </tr>
1015 1865 <?php
1016 1866 }
@@ -1028,20 +1878,22 @@
1028 1878 <th scope="row" class="titledesc">
1029 1879 &nbsp;
1030 1880 </th>
1031 1881 <td class="forminp forminp-button">
1032 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1033 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Tenure', 'propertyhive' ); ?></a>
1882 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1883 + <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>
1034 1884 </td>
1035 1885 </tr>
1036 1886 <tr valign="top">
1037 - <th scope="row" class="titledesc"><?php _e( 'Tenures', 'propertyhive' ) ?></th>
1887 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Tenures', 'propertyhive' )); ?></th>
1038 1888 <td class="forminp">
1039 - <table class="ph_customfields widefat" cellspacing="0">
1889 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="tenure" cellspacing="0">
1040 1890 <thead>
1041 1891 <tr>
1042 - <th class="cb" style="width:1px;">&nbsp;</th>
1043 - <th class="type"><?php _e( 'Tenure', 'propertyhive' ); ?></th>
1892 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1893 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1894 + <th class="type"><?php echo esc_html(__( 'Tenure', 'propertyhive' )); ?></th>
1895 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1044 1896 <th class="settings">&nbsp;</th>
1045 1897 </tr>
1046 1898 </thead>
1047 1899 <tbody>
@@ -1049,9 +1901,9 @@
1049 1901 $args = array(
1050 1902 'hide_empty' => false,
1051 1903 'parent' => 0
1052 1904 );
1053 - $terms = get_terms( 'tenure', $args );
1905 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'tenure' ) ) );
1054 1906
1055 1907 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1056 1908 {
1057 1909 foreach ($terms as $term)
@@ -1056,14 +1908,16 @@
1056 1908 {
1057 1909 foreach ($terms as $term)
1058 1910 {
1059 1911 ?>
1060 - <tr>
1061 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1062 - <td class="type"><?php echo $term->name; ?></td>
1912 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1913 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1914 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1915 + <td class="type"><?php echo esc_html($term->name); ?></td>
1916 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1063 1917 <td class="settings">
1064 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1065 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
1918 + <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>
1919 + <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>
1066 1920 </td>
1067 1921 </tr>
1068 1922 <?php
1069 1923 }
@@ -1071,12 +1925,9 @@
1071 1925 else
1072 1926 {
1073 1927 ?>
1074 1928 <tr>
1075 - <td><?php echo __( 'No tenure found', 'propertyhive' ); ?></td>
1076 - <td class="settings">
1077 -
1078 - </td>
1929 + <td colspan="5"><?php echo esc_html(__( 'No tenure found', 'propertyhive' )); ?></td>
1079 1930 </tr>
1080 1931 <?php
1081 1932 }
1082 1933 ?>
@@ -1088,10 +1939,10 @@
1088 1939 <th scope="row" class="titledesc">
1089 1940 &nbsp;
1090 1941 </th>
1091 1942 <td class="forminp forminp-button">
1092 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1093 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=tenure&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Tenure', 'propertyhive' ); ?></a>
1943 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1944 + <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>
1094 1945 </td>
1095 1946 </tr>
1096 1947 <?php
1097 1948 }
@@ -1109,20 +1960,22 @@
1109 1960 <th scope="row" class="titledesc">
1110 1961 &nbsp;
1111 1962 </th>
1112 1963 <td class="forminp forminp-button">
1113 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1114 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Tenure', 'propertyhive' ); ?></a>
1964 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
1965 + <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>
1115 1966 </td>
1116 1967 </tr>
1117 1968 <tr valign="top">
1118 - <th scope="row" class="titledesc"><?php _e( 'Tenures', 'propertyhive' ) ?></th>
1969 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Tenures', 'propertyhive' )); ?></th>
1119 1970 <td class="forminp">
1120 - <table class="ph_customfields widefat" cellspacing="0">
1971 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="commercial_tenure" cellspacing="0">
1121 1972 <thead>
1122 1973 <tr>
1123 - <th class="cb" style="width:1px;">&nbsp;</th>
1124 - <th class="type"><?php _e( 'Tenure', 'propertyhive' ); ?></th>
1974 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
1975 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
1976 + <th class="type"><?php echo esc_html(__( 'Tenure', 'propertyhive' )); ?></th>
1977 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1125 1978 <th class="settings">&nbsp;</th>
1126 1979 </tr>
1127 1980 </thead>
1128 1981 <tbody>
@@ -1130,9 +1983,9 @@
1130 1983 $args = array(
1131 1984 'hide_empty' => false,
1132 1985 'parent' => 0
1133 1986 );
1134 - $terms = get_terms( 'commercial_tenure', $args );
1987 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_tenure' ) ) );
1135 1988
1136 1989 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1137 1990 {
1138 1991 foreach ($terms as $term)
@@ -1137,14 +1990,16 @@
1137 1990 {
1138 1991 foreach ($terms as $term)
1139 1992 {
1140 1993 ?>
1141 - <tr>
1142 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1143 - <td class="type"><?php echo $term->name; ?></td>
1994 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
1995 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
1996 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
1997 + <td class="type"><?php echo esc_html($term->name); ?></td>
1998 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1144 1999 <td class="settings">
1145 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1146 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
2000 + <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>
2001 + <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>
1147 2002 </td>
1148 2003 </tr>
1149 2004 <?php
1150 2005 }
@@ -1152,12 +2007,9 @@
1152 2007 else
1153 2008 {
1154 2009 ?>
1155 2010 <tr>
1156 - <td><?php echo __( 'No tenure found', 'propertyhive' ); ?></td>
1157 - <td class="settings">
1158 -
1159 - </td>
2011 + <td colspan="5"><?php echo esc_html(__( 'No tenure found', 'propertyhive' )); ?></td>
1160 2012 </tr>
1161 2013 <?php
1162 2014 }
1163 2015 ?>
@@ -1169,10 +2021,10 @@
1169 2021 <th scope="row" class="titledesc">
1170 2022 &nbsp;
1171 2023 </th>
1172 2024 <td class="forminp forminp-button">
1173 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1174 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=commercial-tenure&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Tenure', 'propertyhive' ); ?></a>
2025 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2026 + <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>
1175 2027 </td>
1176 2028 </tr>
1177 2029 <?php
1178 2030 }
@@ -1190,20 +2042,22 @@
1190 2042 <th scope="row" class="titledesc">
1191 2043 &nbsp;
1192 2044 </th>
1193 2045 <td class="forminp forminp-button">
1194 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1195 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Furnished Option', 'propertyhive' ); ?></a>
2046 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2047 + <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>
1196 2048 </td>
1197 2049 </tr>
1198 2050 <tr valign="top">
1199 - <th scope="row" class="titledesc"><?php _e( 'Furnished Options', 'propertyhive' ) ?></th>
2051 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Furnished Options', 'propertyhive' )); ?></th>
1200 2052 <td class="forminp">
1201 - <table class="ph_customfields widefat" cellspacing="0">
2053 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="furnished" cellspacing="0">
1202 2054 <thead>
1203 2055 <tr>
1204 - <th class="cb" style="width:1px;">&nbsp;</th>
1205 - <th class="type"><?php _e( 'Furnished', 'propertyhive' ); ?></th>
2056 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2057 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2058 + <th class="type"><?php echo esc_html(__( 'Furnished', 'propertyhive' )); ?></th>
2059 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1206 2060 <th class="settings">&nbsp;</th>
1207 2061 </tr>
1208 2062 </thead>
1209 2063 <tbody>
@@ -1211,9 +2065,9 @@
1211 2065 $args = array(
1212 2066 'hide_empty' => false,
1213 2067 'parent' => 0
1214 2068 );
1215 - $terms = get_terms( 'furnished', $args );
2069 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'furnished' ) ) );
1216 2070
1217 2071 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1218 2072 {
1219 2073 foreach ($terms as $term)
@@ -1218,14 +2072,16 @@
1218 2072 {
1219 2073 foreach ($terms as $term)
1220 2074 {
1221 2075 ?>
1222 - <tr>
1223 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1224 - <td class="type"><?php echo $term->name; ?></td>
2076 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
2077 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2078 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
2079 + <td class="type"><?php echo esc_html($term->name); ?></td>
2080 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1225 2081 <td class="settings">
1226 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1227 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
2082 + <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>
2083 + <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>
1228 2084 </td>
1229 2085 </tr>
1230 2086 <?php
1231 2087 }
@@ -1233,12 +2089,9 @@
1233 2089 else
1234 2090 {
1235 2091 ?>
1236 2092 <tr>
1237 - <td><?php echo __( 'No furnished options found', 'propertyhive' ); ?></td>
1238 - <td class="settings">
1239 -
1240 - </td>
2093 + <td colspan="5"><?php echo esc_html(__( 'No furnished options found', 'propertyhive' )); ?></td>
1241 2094 </tr>
1242 2095 <?php
1243 2096 }
1244 2097 ?>
@@ -1250,15 +2103,141 @@
1250 2103 <th scope="row" class="titledesc">
1251 2104 &nbsp;
1252 2105 </th>
1253 2106 <td class="forminp forminp-button">
1254 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1255 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=furnished&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Furnished Option', 'propertyhive' ); ?></a>
2107 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2108 + <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>
1256 2109 </td>
1257 2110 </tr>
1258 2111 <?php
1259 2112 }
1260 2113
2114 + public function custom_fields_management_key_date_type_setting() {
2115 + ?>
2116 + <tr valign="top">
2117 + <th scope="row" class="titledesc">
2118 + &nbsp;
2119 + </th>
2120 + <td class="forminp forminp-button">
2121 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2122 + <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>
2123 + </td>
2124 + </tr>
2125 + <?php foreach( array ('property_management' => __( 'Property Management', 'propertyhive' ), 'tenancy_management' => __( 'Tenancy Management', 'propertyhive' ) ) as $type => $title): ?>
2126 + <tr valign="top">
2127 + <th scope="row" class="titledesc no-auto"><?php echo esc_html( $title ); ?></th>
2128 + <td class="forminp no-auto">
2129 + <table class="ph_customfields widefat" cellspacing="0">
2130 + <thead>
2131 + <tr>
2132 + <th style="width:1px;">&nbsp;</th>
2133 + <th style="width:40%;"><?php echo esc_html(__( 'Description', 'propertyhive' )); ?></th>
2134 + <th><?php echo esc_html(__( 'Recurrence', 'propertyhive' )); ?></th>
2135 + <th>&nbsp;</th>
2136 + </tr>
2137 + </thead>
2138 + <tbody>
2139 + <?php
2140 + $args = array(
2141 + 'hide_empty' => false,
2142 + 'parent' => 0
2143 + );
2144 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'management_key_date_type' ) ) );
2145 +
2146 + if ( !empty( $terms ) && !is_wp_error( $terms ) )
2147 + {
2148 + $recurrence_rules = get_option( 'propertyhive_key_date_type', array() );
2149 + $recurrence_rules = is_array( $recurrence_rules ) ? $recurrence_rules : array();
2150 +
2151 + foreach ($terms as $term)
2152 + {
2153 + $recurrence_type = isset($recurrence_rules[$term->term_id]) ? $recurrence_rules[$term->term_id]['recurrence_type'] : '';
2154 +
2155 + if ( $recurrence_type !== $type)
2156 + {
2157 + continue;
2158 + }
2159 +
2160 +
2161 + $recurrence_rule = isset($recurrence_rules[$term->term_id]) ? $recurrence_rules[$term->term_id]['recurrence_rule'] : '';
2162 + $recurrence = array('FREQ' => '', 'INTERVAL' => '');
2163 + foreach (explode(';', $recurrence_rule) as $key_value_pair) {
2164 + list($key, $value) = explode('=', $key_value_pair);
2165 + $recurrence[$key] = $value;
2166 + }
2167 +
2168 + $frequency = '';
2169 + if ($recurrence['INTERVAL'] <= 1)
2170 + {
2171 + $frequencies = array(
2172 + 'ONCE' => __( 'Once', 'propertyhive' ),
2173 + 'DAILY' => __( 'Daily', 'propertyhive' ),
2174 + 'WEEKLY' => __( 'Weekly', 'propertyhive' ),
2175 + 'MONTHLY' => __( 'Monthly', 'propertyhive' ),
2176 + 'YEARLY' => __( 'Annually', 'propertyhive' ),
2177 + );
2178 +
2179 + $frequency = $frequencies[$recurrence['FREQ']];
2180 + }
2181 + else
2182 + {
2183 + $interval = $recurrence['INTERVAL'];
2184 + if (extension_loaded('intl'))
2185 + {
2186 + $formatter = new NumberFormatter(get_locale(), NumberFormatter::SPELLOUT);
2187 + $interval = $formatter->format($recurrence['INTERVAL']);
2188 + }
2189 +
2190 + $periods = array(
2191 + 'DAILY' => __( 'days', 'propertyhive' ),
2192 + 'WEEKLY' => __( 'weeks', 'propertyhive' ),
2193 + 'MONTHLY' => __( 'months', 'propertyhive' ),
2194 + 'YEARLY' => __( 'years', 'propertyhive' ),
2195 + );
2196 +
2197 +
2198 + $frequency = sprintf('Every %s %s', $interval, $periods[$recurrence['FREQ']]);
2199 + }
2200 +
2201 + ?>
2202 + <tr>
2203 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2204 + <td><?php echo esc_html($term->name); ?></td>
2205 + <td><?php echo esc_html($frequency); ?></td>
2206 + <td class="settings">
2207 + <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>
2208 + <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>
2209 + </td>
2210 + </tr>
2211 + <?php
2212 + }
2213 + }
2214 + else
2215 + {
2216 + ?>
2217 + <tr>
2218 + <td colspan="4"><?php echo esc_html(__( 'No management date types found', 'propertyhive' )); ?></td>
2219 + </tr>
2220 + <?php
2221 + }
2222 + ?>
2223 + </tbody>
2224 + </table>
2225 + </td>
2226 + </tr>
2227 + <?php endforeach; ?>
2228 + <tr valign="top">
2229 + <th scope="row" class="titledesc">
2230 + &nbsp;
2231 + </th>
2232 + <td class="forminp forminp-button">
2233 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2234 + <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>
2235 + </td>
2236 + </tr>
2237 + <?php
2238 + }
2239 +
1261 2240 /**
1262 2241 * Output list of marketing flag options
1263 2242 *
1264 2243 * @access public
@@ -1271,20 +2250,22 @@
1271 2250 <th scope="row" class="titledesc">
1272 2251 &nbsp;
1273 2252 </th>
1274 2253 <td class="forminp forminp-button">
1275 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1276 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Marketing Flag', 'propertyhive' ); ?></a>
2254 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2255 + <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>
1277 2256 </td>
1278 2257 </tr>
1279 2258 <tr valign="top">
1280 - <th scope="row" class="titledesc"><?php _e( 'Marketing Flags', 'propertyhive' ) ?></th>
2259 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Marketing Flags', 'propertyhive' )); ?></th>
1281 2260 <td class="forminp">
1282 - <table class="ph_customfields widefat" cellspacing="0">
2261 + <table class="ph_customfields sortable-custom-field widefat" data-taxonomy="marketing_flag" cellspacing="0">
1283 2262 <thead>
1284 2263 <tr>
1285 - <th class="cb" style="width:1px;">&nbsp;</th>
1286 - <th class="type"><?php _e( 'Marketing Flag', 'propertyhive' ); ?></th>
2264 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2265 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2266 + <th class="type"><?php echo esc_html(__( 'Marketing Flag', 'propertyhive' )); ?></th>
2267 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1287 2268 <th class="settings">&nbsp;</th>
1288 2269 </tr>
1289 2270 </thead>
1290 2271 <tbody>
@@ -1292,9 +2273,9 @@
1292 2273 $args = array(
1293 2274 'hide_empty' => false,
1294 2275 'parent' => 0
1295 2276 );
1296 - $terms = get_terms( 'marketing_flag', $args );
2277 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'marketing_flag' ) ) );
1297 2278
1298 2279 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1299 2280 {
1300 2281 foreach ($terms as $term)
@@ -1299,14 +2280,16 @@
1299 2280 {
1300 2281 foreach ($terms as $term)
1301 2282 {
1302 2283 ?>
1303 - <tr>
1304 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1305 - <td class="type"><?php echo $term->name; ?></td>
2284 + <tr id="term-<?php echo esc_attr($term->term_id); ?>">
2285 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2286 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
2287 + <td class="type"><?php echo esc_html($term->name); ?></td>
2288 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1306 2289 <td class="settings">
1307 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1308 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
2290 + <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>
2291 + <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>
1309 2292 </td>
1310 2293 </tr>
1311 2294 <?php
1312 2295 }
@@ -1314,12 +2297,9 @@
1314 2297 else
1315 2298 {
1316 2299 ?>
1317 2300 <tr>
1318 - <td><?php echo __( 'No marketing flags found', 'propertyhive' ); ?></td>
1319 - <td class="settings">
1320 -
1321 - </td>
2301 + <td colspan="5"><?php echo esc_html(__( 'No marketing flags found', 'propertyhive' )); ?></td>
1322 2302 </tr>
1323 2303 <?php
1324 2304 }
1325 2305 ?>
@@ -1331,10 +2311,10 @@
1331 2311 <th scope="row" class="titledesc">
1332 2312 &nbsp;
1333 2313 </th>
1334 2314 <td class="forminp forminp-button">
1335 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1336 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=marketing-flag&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Marketing Flag', 'propertyhive' ); ?></a>
2315 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2316 + <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>
1337 2317 </td>
1338 2318 </tr>
1339 2319 <?php
1340 2320 }
@@ -1352,20 +2332,22 @@
1352 2332 <th scope="row" class="titledesc">
1353 2333 &nbsp;
1354 2334 </th>
1355 2335 <td class="forminp forminp-button">
1356 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1357 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Feature', 'propertyhive' ); ?></a>
2336 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2337 + <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>
1358 2338 </td>
1359 2339 </tr>
1360 2340 <tr valign="top">
1361 - <th scope="row" class="titledesc"><?php _e( 'Property Features', 'propertyhive' ) ?></th>
2341 + <th scope="row" class="titledesc"><?php echo esc_html(__( 'Property Features', 'propertyhive' )); ?></th>
1362 2342 <td class="forminp">
1363 2343 <table class="ph_customfields widefat" cellspacing="0">
1364 2344 <thead>
1365 2345 <tr>
1366 - <th class="cb" style="width:1px;">&nbsp;</th>
1367 - <th class="type"><?php _e( 'Property Feature', 'propertyhive' ); ?></th>
2346 + <th class="cb" style="width:1px;"><input class="select_all" type="checkbox" style="margin: 2px 0 0 0;"></th>
2347 + <th class="id" style="width:45px;"><?php echo esc_html(__( 'ID', 'propertyhive' )); ?></th>
2348 + <th class="type"><?php echo esc_html(__( 'Property Feature', 'propertyhive' )); ?></th>
2349 + <th class="assigned_count"><?php echo esc_html(__( 'Assigned Properties', 'propertyhive' )); ?></th>
1368 2350 <th class="settings">&nbsp;</th>
1369 2351 </tr>
1370 2352 </thead>
1371 2353 <tbody>
@@ -1373,9 +2355,9 @@
1373 2355 $args = array(
1374 2356 'hide_empty' => false,
1375 2357 'parent' => 0
1376 2358 );
1377 - $terms = get_terms( 'property_feature', $args );
2359 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_feature' ) ) );
1378 2360
1379 2361 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1380 2362 {
1381 2363 foreach ($terms as $term)
@@ -1381,13 +2363,15 @@
1381 2363 foreach ($terms as $term)
1382 2364 {
1383 2365 ?>
1384 2366 <tr>
1385 - <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo $term->term_id; ?>"></td>
1386 - <td class="type"><?php echo $term->name; ?></td>
2367 + <td class="cb"><input type="checkbox" name="term_id[]" value="<?php echo esc_attr($term->term_id); ?>"></td>
2368 + <td class="id"><?php echo esc_html($term->term_id); ?></td>
2369 + <td class="type"><?php echo esc_html($term->name); ?></td>
2370 + <td class="assigned_count"><?php echo esc_html($term->count); ?></td>
1387 2371 <td class="settings">
1388 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' . $term->term_id ); ?>"><?php echo __( 'Edit', 'propertyhive' ); ?></a>
1389 - <a class="button" href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature-delete&id=' . $term->term_id ); ?>"><?php echo __( 'Delete', 'propertyhive' ); ?></a>
2372 + <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>
2373 + <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>
1390 2374 </td>
1391 2375 </tr>
1392 2376 <?php
1393 2377 }
@@ -1395,9 +2379,9 @@
1395 2379 else
1396 2380 {
1397 2381 ?>
1398 2382 <tr>
1399 - <td colspan="3"><?php echo __( 'No property features found', 'propertyhive' ); ?></td>
2383 + <td colspan="5"><?php echo esc_html(__( 'No property features found', 'propertyhive' )); ?></td>
1400 2384 </tr>
1401 2385 <?php
1402 2386 }
1403 2387 ?>
@@ -1409,10 +2393,10 @@
1409 2393 <th scope="row" class="titledesc">
1410 2394 &nbsp;
1411 2395 </th>
1412 2396 <td class="forminp forminp-button">
1413 - <a href="" class="button alignright batch-delete" disabled><?php echo __( 'Delete Selected', 'propertyhive' ); ?></a>
1414 - <a href="<?php echo admin_url( 'admin.php?page=ph-settings&tab=customfields&section=property-feature&id=' ); ?>" class="button alignright"><?php echo __( 'Add New Property Feature', 'propertyhive' ); ?></a>
2397 + <a href="" class="button alignright batch-delete" disabled><?php echo esc_html(__( 'Delete Selected', 'propertyhive' )); ?></a>
2398 + <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>
1415 2399 </td>
1416 2400 </tr>
1417 2401 <?php
1418 2402 }
@@ -1424,9 +2408,10 @@
1424 2408 * @return string
1425 2409 */
1426 2410 public function get_custom_fields_availability_setting()
1427 2411 {
1428 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2412 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2413 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1429 2414
1430 2415 $taxonomy = 'availability';
1431 2416 $term_name = '';
1432 2417 if ($current_id != '')
@@ -1434,11 +2419,13 @@
1434 2419 $term = get_term( $current_id, $taxonomy );
1435 2420 $term_name = $term->name;
1436 2421 }
1437 2422
2423 + $departments = ph_get_departments();
2424 +
1438 2425 $args = array(
1439 2426
1440 - array( 'title' => __( ( $current_id == '' ? 'Add New Availability Option' : 'Edit Availability' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_availability_settings' ),
2427 + array( 'title' => ( $current_id == '' ? __( 'Add New Availability Option', 'propertyhive' ) : __( 'Edit Availability', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_availability_settings' ),
1441 2428
1442 2429 array(
1443 2430 'title' => __( 'Availability', 'propertyhive' ),
1444 2431 'id' => 'availability_name',
@@ -1445,18 +2432,41 @@
1445 2432 'default' => $term_name,
1446 2433 'type' => 'text',
1447 2434 'desc_tip' => false,
1448 2435 ),
2436 +
2437 + );
2438 +
2439 + $availability_departments = get_option( 'propertyhive_availability_departments', array() );
2440 +
2441 + $i = 0;
2442 + foreach ( $departments as $key => $value )
2443 + {
2444 + if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
2445 + {
2446 + $args[] = array(
2447 + 'title' => __( 'Applies To', 'propertyhive' ),
2448 + 'name' => 'department[' . $key . ']',
2449 + 'id' => 'department_' . $key,
2450 + //'default' => $term_name,
2451 + 'value' => ( !isset($availability_departments[$current_id]) || in_array($key, $availability_departments[$current_id]) ? 'yes' : '' ),
2452 + 'type' => 'checkbox',
2453 + 'desc_tip' => false,
2454 + 'desc' => $value,
2455 + 'checkboxgroup' => ( $i == 0 ? 'start' : ( $i == count($departments)-1 ? 'end' : '' ) ),
2456 + );
2457 +
2458 + ++$i;
2459 + }
2460 + }
2461 +
2462 + $args[] = array(
2463 + 'type' => 'hidden',
2464 + 'id' => 'taxonomy',
2465 + 'default' => $taxonomy
2466 + );
1449 2467
1450 - array(
1451 - 'type' => 'hidden',
1452 - 'id' => 'taxonomy',
1453 - 'default' => $taxonomy
1454 - ),
1455 -
1456 - array( 'type' => 'sectionend', 'id' => 'custom_field_availability_settings' )
1457 -
1458 - );
2468 + $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_availability_settings' );
1459 2469
1460 2470 return apply_filters( 'propertyhive_custom_field_availability_settings', $args );
1461 2471 }
1462 2472
@@ -1467,9 +2477,10 @@
1467 2477 * @return string
1468 2478 */
1469 2479 public function get_custom_fields_property_type_setting()
1470 2480 {
1471 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2481 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2482 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1472 2483
1473 2484 $taxonomy = 'property_type';
1474 2485 $term_name = '';
1475 2486 $term_parent = '';
@@ -1484,11 +2495,12 @@
1484 2495
1485 2496 $args = array(
1486 2497 'hide_empty' => false,
1487 2498 'parent' => 0,
2499 + // 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.
1488 2500 'exclude' => array($current_id)
1489 2501 );
1490 - $terms = get_terms( 'property_type', $args );
2502 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'property_type' ) ) );
1491 2503 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1492 2504 {
1493 2505 foreach ($terms as $term)
1494 2506 {
@@ -1497,9 +2509,9 @@
1497 2509 }
1498 2510
1499 2511 $args = array(
1500 2512
1501 - array( 'title' => __( ( $current_id == '' ? 'Add New Property Type' : 'Edit Property Type' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_type_settings' ),
2513 + array( 'title' => ( $current_id == '' ? __( 'Add New Property Type', 'propertyhive' ) : __( 'Edit Property Type', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_type_settings' ),
1502 2514
1503 2515 array(
1504 2516 'title' => __( 'Property Type', 'propertyhive' ),
1505 2517 'id' => 'property_type_name',
@@ -1538,9 +2550,10 @@
1538 2550 * @return string
1539 2551 */
1540 2552 public function get_custom_fields_commercial_property_type_setting()
1541 2553 {
1542 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2554 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2555 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1543 2556
1544 2557 $taxonomy = 'commercial_property_type';
1545 2558 $term_name = '';
1546 2559 $term_parent = '';
@@ -1555,11 +2568,12 @@
1555 2568
1556 2569 $args = array(
1557 2570 'hide_empty' => false,
1558 2571 'parent' => 0,
2572 + // 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.
1559 2573 'exclude' => array($current_id)
1560 2574 );
1561 - $terms = get_terms( 'commercial_property_type', $args );
2575 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => 'commercial_property_type' ) ) );
1562 2576 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1563 2577 {
1564 2578 foreach ($terms as $term)
1565 2579 {
@@ -1568,9 +2582,9 @@
1568 2582 }
1569 2583
1570 2584 $args = array(
1571 2585
1572 - array( 'title' => __( ( $current_id == '' ? 'Add New Property Type' : 'Edit Property Type' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_property_type_settings' ),
2586 + array( 'title' => ( $current_id == '' ? __( 'Add New Property Type', 'propertyhive' ) : __( 'Edit Property Type', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_property_type_settings' ),
1573 2587
1574 2588 array(
1575 2589 'title' => __( 'Property Type', 'propertyhive' ),
1576 2590 'id' => 'commercial_property_type_name',
@@ -1609,9 +2623,10 @@
1609 2623 * @return string
1610 2624 */
1611 2625 public function get_custom_fields_location_setting()
1612 2626 {
1613 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2627 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2628 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1614 2629
1615 2630 $taxonomy = 'location';
1616 2631 $term_name = '';
1617 2632 $term_parent = '';
@@ -1626,11 +2641,12 @@
1626 2641
1627 2642 $args = array(
1628 2643 'hide_empty' => false,
1629 2644 'parent' => 0,
2645 + // 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.
1630 2646 'exclude' => array($current_id)
1631 2647 );
1632 - $terms = get_terms( $taxonomy, $args );
2648 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => $taxonomy ) ) );
1633 2649 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1634 2650 {
1635 2651 foreach ($terms as $term)
1636 2652 {
@@ -1638,11 +2654,12 @@
1638 2654
1639 2655 $args = array(
1640 2656 'hide_empty' => false,
1641 2657 'parent' => $term->term_id,
2658 + // 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.
1642 2659 'exclude' => array($current_id)
1643 2660 );
1644 - $terms = get_terms( $taxonomy, $args );
2661 + $terms = get_terms( array_merge( wp_parse_args( $args ), array( 'taxonomy' => $taxonomy ) ) );
1645 2662 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1646 2663 {
1647 2664 foreach ($terms as $term)
1648 2665 {
@@ -1653,9 +2670,9 @@
1653 2670 }
1654 2671
1655 2672 $args = array(
1656 2673
1657 - array( 'title' => __( ( $current_id == '' ? 'Add New Location' : 'Edit Location' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_location_settings' ),
2674 + array( 'title' => ( $current_id == '' ? __( 'Add New Location', 'propertyhive' ) : __( 'Edit Location', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_location_settings' ),
1658 2675
1659 2676 array(
1660 2677 'title' => __( 'Location', 'propertyhive' ),
1661 2678 'id' => 'location_name',
@@ -1694,9 +2711,10 @@
1694 2711 * @return string
1695 2712 */
1696 2713 public function get_custom_fields_parking_setting()
1697 2714 {
1698 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2715 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2716 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1699 2717
1700 2718 $taxonomy = 'parking';
1701 2719 $term_name = '';
1702 2720 if ($current_id != '')
@@ -1706,9 +2724,9 @@
1706 2724 }
1707 2725
1708 2726 $args = array(
1709 2727
1710 - array( 'title' => __( ( $current_id == '' ? 'Add New Parking Option' : 'Edit Parking' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_parking_settings' ),
2728 + array( 'title' => ( $current_id == '' ? __( 'Add New Parking Option', 'propertyhive' ) : __( 'Edit Parking', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_parking_settings' ),
1711 2729
1712 2730 array(
1713 2731 'title' => __( 'Parking', 'propertyhive' ),
1714 2732 'id' => 'parking_name',
@@ -1737,9 +2755,10 @@
1737 2755 * @return string
1738 2756 */
1739 2757 public function get_custom_fields_outside_space_setting()
1740 2758 {
1741 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2759 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This getter only renders stored taxonomy settings and does not mutate state.
2760 + $current_id = $this->normalize_custom_fields_render_term_id( ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '' );
1742 2761
1743 2762 $taxonomy = 'outside_space';
1744 2763 $term_name = '';
1745 2764 if ($current_id != '')
@@ -1749,9 +2768,9 @@
1749 2768 }
1750 2769
1751 2770 $args = array(
1752 2771
1753 - array( 'title' => __( ( $current_id == '' ? 'Add New Outside Space' : 'Edit Outside Space' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_outside_space_settings' ),
2772 + array( 'title' => ( $current_id == '' ? __( 'Add New Outside Space', 'propertyhive' ) : __( 'Edit Outside Space', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_outside_space_settings' ),
1754 2773
1755 2774 array(
1756 2775 'title' => __( 'Outside Space', 'propertyhive' ),
1757 2776 'id' => 'outside_space_name',
@@ -1782,20 +2801,26 @@
1782 2801 public function get_custom_fields_delete($current_id, $taxonomy, $taxonomy_name)
1783 2802 {
1784 2803 global $save_button_text;
1785 2804
2805 + // 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.
1786 2806 $save_button_text = __( 'Delete', 'propertyhive' );
1787 2807
1788 2808 //$taxonomy = 'outside_space';
1789 2809 //$taxonomy_name = __( 'Outside Space', 'propertyhive' );
1790 2810
1791 - if ( isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == 1 )
2811 + // 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.
2812 + $confirm_removal = ( isset( $_POST['confirm_removal'] ) && is_string( $_POST['confirm_removal'] ) ) ? sanitize_text_field( wp_unslash( $_POST['confirm_removal'] ) ) : '';
2813 + if ( '1' === $confirm_removal )
1792 2814 {
1793 2815 // A term has just been deleted
1794 2816 global $hide_save_button, $show_cancel_button, $cancel_button_href;
1795 2817
2818 + // 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.
1796 2819 $hide_save_button = TRUE;
2820 + // 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.
1797 2821 $show_cancel_button = TRUE;
2822 + // 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.
1798 2823 $cancel_button_href = admin_url( 'admin.php?page=ph-settings&tab=customfields&section=' . str_replace("_", "-", $taxonomy) );
1799 2824
1800 2825 $args = array();
1801 2826
@@ -1842,8 +2867,9 @@
1842 2867 $query_args = array(
1843 2868 'post_type' => 'property',
1844 2869 'nopaging' => true,
1845 2870 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2871 + // 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.
1846 2872 'tax_query' => array(
1847 2873 array(
1848 2874 'taxonomy' => $taxonomy,
1849 2875 'field' => 'id',
@@ -1864,8 +2890,9 @@
1864 2890 $query_args = array(
1865 2891 'post_type' => 'contact',
1866 2892 'nopaging' => true,
1867 2893 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2894 + // 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.
1868 2895 'meta_query' => array(
1869 2896 array(
1870 2897 'key' => '_contact_types',
1871 2898 'value' => 'applicant',
@@ -1914,9 +2941,33 @@
1914 2941
1915 2942 wp_reset_postdata();
1916 2943 }
1917 2944
1918 - if ($num_properties > 0 || $num_applicants > 0)
2945 + // Get number of key dates assigned to this term
2946 + $num_key_dates= 0;
2947 + if ( $taxonomy == 'management_key_date_type' )
2948 + {
2949 + $query_args = array(
2950 + 'post_type' => 'key_date',
2951 + 'nopaging' => true,
2952 + 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2953 + // 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.
2954 + 'tax_query' => array(
2955 + array(
2956 + 'taxonomy' => $taxonomy,
2957 + 'field' => 'id',
2958 + 'terms' => $current_id,
2959 + ),
2960 + ),
2961 + );
2962 + $key_date_query = new WP_Query( $query_args );
2963 +
2964 + $num_key_dates = $key_date_query->found_posts;
2965 +
2966 + wp_reset_postdata();
2967 + }
2968 +
2969 + if ($num_properties > 0 || $num_applicants > 0 || $num_key_dates > 0 )
1919 2970 {
1920 2971 $alternative_terms = array();
1921 2972
1922 2973 $alternative_terms['none'] = '-- ' . __( 'Don\'t Reassign', 'propertyhive' ) . ' --';
@@ -1922,12 +2973,13 @@
1922 2973 $alternative_terms['none'] = '-- ' . __( 'Don\'t Reassign', 'propertyhive' ) . ' --';
1923 2974
1924 2975 $term_args = array(
1925 2976 'hide_empty' => false,
2977 + // 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.
1926 2978 'exclude' => $term_ids,
1927 2979 'parent' => 0
1928 2980 );
1929 - $terms = get_terms( $taxonomy, $term_args );
2981 + $terms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
1930 2982
1931 2983 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1932 2984 {
1933 2985 foreach ($terms as $term)
@@ -1935,12 +2987,13 @@
1935 2987 $alternative_terms[$term->term_id] = $term->name;
1936 2988
1937 2989 $term_args = array(
1938 2990 'hide_empty' => false,
2991 + // 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.
1939 2992 'exclude' => $term_ids,
1940 2993 'parent' => $term->term_id
1941 2994 );
1942 - $subterms = get_terms( $taxonomy, $term_args );
2995 + $subterms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
1943 2996
1944 2997 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1945 2998 {
1946 2999 foreach ($subterms as $term)
@@ -1948,12 +3001,13 @@
1948 3001 $alternative_terms[$term->term_id] = '- ' . $term->name;
1949 3002
1950 3003 $term_args = array(
1951 3004 'hide_empty' => false,
3005 + // 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.
1952 3006 'exclude' => $term_ids,
1953 3007 'parent' => $term->term_id
1954 3008 );
1955 - $subsubterms = get_terms( $taxonomy, $term_args );
3009 + $subsubterms = get_terms( array_merge( wp_parse_args( $term_args ), array( 'taxonomy' => $taxonomy ) ) );
1956 3010
1957 3011 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1958 3012 {
1959 3013 foreach ($subsubterms as $term)
@@ -1973,21 +3027,11 @@
1973 3027 'default' => '',
1974 3028 'options' => $alternative_terms,
1975 3029 'type' => 'select',
1976 3030 'desc_tip' => false,
1977 - 'desc' => __( 'There are properties or applicants that have this term assigned to them. Which, if any, term should they be reassigned to?' , 'propertyhive' )
3031 + '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' )
1978 3032 );
1979 3033 }
1980 - else
1981 - {
1982 - // There are properties assigned to this term
1983 - $args[] = array(
1984 - 'title' => __( 'Re-assign to', 'propertyhive' ),
1985 - 'id' => 'reassign_to',
1986 - 'type' => 'html',
1987 - 'html' => __( 'No properties or applicants assigned to this term' , 'propertyhive' )
1988 - );
1989 - }
1990 3034
1991 3035 $args[] = array( 'type' => 'sectionend', 'id' => 'custom_field_' . $taxonomy . '_' . $current_id . '_delete' );
1992 3036 }
1993 3037 }
@@ -2021,9 +3065,10 @@
2021 3065 * @return string
2022 3066 */
2023 3067 public function get_custom_fields_price_qualifier_setting()
2024 3068 {
2025 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3069 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3070 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2026 3071
2027 3072 $taxonomy = 'price_qualifier';
2028 3073 $term_name = '';
2029 3074 if ($current_id != '')
@@ -2033,9 +3078,9 @@
2033 3078 }
2034 3079
2035 3080 $args = array(
2036 3081
2037 - array( 'title' => __( ( $current_id == '' ? 'Add New Price Qualifier' : 'Edit Price Qualifier' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_price_qualifier_settings' ),
3082 + array( 'title' => ( $current_id == '' ? __( 'Add New Price Qualifier', 'propertyhive' ) : __( 'Edit Price Qualifier', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_price_qualifier_settings' ),
2038 3083
2039 3084 array(
2040 3085 'title' => __( 'Price Qualifier', 'propertyhive' ),
2041 3086 'id' => 'price_qualifier_name',
@@ -2064,9 +3109,10 @@
2064 3109 * @return string
2065 3110 */
2066 3111 public function get_custom_fields_sale_by_setting()
2067 3112 {
2068 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3113 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3114 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2069 3115
2070 3116 $taxonomy = 'sale_by';
2071 3117 $term_name = '';
2072 3118 if ($current_id != '')
@@ -2076,9 +3122,9 @@
2076 3122 }
2077 3123
2078 3124 $args = array(
2079 3125
2080 - array( 'title' => __( ( $current_id == '' ? 'Add New Sale By' : 'Edit Sale By' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_sale_by_settings' ),
3126 + array( 'title' => ( $current_id == '' ? __( 'Add New Sale By', 'propertyhive' ) : __( 'Edit Sale By', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_sale_by_settings' ),
2081 3127
2082 3128 array(
2083 3129 'title' => __( 'Sale By', 'propertyhive' ),
2084 3130 'id' => 'sale_by_name',
@@ -2107,9 +3153,10 @@
2107 3153 * @return string
2108 3154 */
2109 3155 public function get_custom_fields_tenure_setting()
2110 3156 {
2111 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3157 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3158 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2112 3159
2113 3160 $taxonomy = 'tenure';
2114 3161 $term_name = '';
2115 3162 if ($current_id != '')
@@ -2119,9 +3166,9 @@
2119 3166 }
2120 3167
2121 3168 $args = array(
2122 3169
2123 - array( 'title' => __( ( $current_id == '' ? 'Add New Tenure' : 'Edit Tenure' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_tenure_settings' ),
3170 + array( 'title' => ( $current_id == '' ? __( 'Add New Tenure', 'propertyhive' ) : __( 'Edit Tenure', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_tenure_settings' ),
2124 3171
2125 3172 array(
2126 3173 'title' => __( 'Tenure', 'propertyhive' ),
2127 3174 'id' => 'tenure_name',
@@ -2150,9 +3197,10 @@
2150 3197 * @return string
2151 3198 */
2152 3199 public function get_custom_fields_commercial_tenure_setting()
2153 3200 {
2154 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3201 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3202 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2155 3203
2156 3204 $taxonomy = 'commercial_tenure';
2157 3205 $term_name = '';
2158 3206 if ($current_id != '')
@@ -2162,9 +3210,9 @@
2162 3210 }
2163 3211
2164 3212 $args = array(
2165 3213
2166 - array( 'title' => __( ( $current_id == '' ? 'Add New Tenure' : 'Edit Tenure' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_tenure_settings' ),
3214 + array( 'title' => ( $current_id == '' ? __( 'Add New Tenure', 'propertyhive' ) : __( 'Edit Tenure', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_commercial_tenure_settings' ),
2167 3215
2168 3216 array(
2169 3217 'title' => __( 'Tenure', 'propertyhive' ),
2170 3218 'id' => 'commercial_tenure_name',
@@ -2193,9 +3241,10 @@
2193 3241 * @return string
2194 3242 */
2195 3243 public function get_custom_fields_furnished_setting()
2196 3244 {
2197 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3245 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3246 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2198 3247
2199 3248 $taxonomy = 'furnished';
2200 3249 $term_name = '';
2201 3250 if ($current_id != '')
@@ -2205,9 +3254,9 @@
2205 3254 }
2206 3255
2207 3256 $args = array(
2208 3257
2209 - array( 'title' => __( ( $current_id == '' ? 'Add New Furnished' : 'Edit Furnished' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_furnished_settings' ),
3258 + array( 'title' => ( $current_id == '' ? __( 'Add New Furnished', 'propertyhive' ) : __( 'Edit Furnished', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_furnished_settings' ),
2210 3259
2211 3260 array(
2212 3261 'title' => __( 'Furnished', 'propertyhive' ),
2213 3262 'id' => 'furnished_name',
@@ -2228,8 +3277,113 @@
2228 3277
2229 3278 return apply_filters( 'propertyhive_custom_field_furnished_settings', $args );
2230 3279 }
2231 3280
3281 + /**
3282 + * Show key date add/edit options
3283 + *
3284 + * @return string
3285 + */
3286 + public function get_custom_fields_management_key_date_type_setting()
3287 + {
3288 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3289 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
3290 +
3291 + $taxonomy = 'management_key_date_type';
3292 + $term_name = '';
3293 + if ($current_id != '')
3294 + {
3295 + $term = get_term( $current_id, $taxonomy );
3296 + $term_name = $term->name;
3297 + }
3298 +
3299 + $recurrence = get_option( 'propertyhive_key_date_type', array() );
3300 + if ( ! is_array($recurrence) )
3301 + {
3302 + $recurrence = array();
3303 + }
3304 + $recurrence_rule = isset($recurrence[$current_id]) ? $recurrence[$current_id]['recurrence_rule'] : '';
3305 + $recurrence_type = isset($recurrence[$current_id]) ? $recurrence[$current_id]['recurrence_type'] : '';
3306 +
3307 + $recurrence = array(
3308 + 'FREQ' => 'ONCE',
3309 + 'INTERVAL' => '1',
3310 + );
3311 +
3312 + if ( !empty($recurrence_rule) )
3313 + {
3314 + foreach (explode(';', $recurrence_rule) as $key_value_pair){
3315 + list($key, $value) = explode('=', $key_value_pair);
3316 + $recurrence[$key] = $value;
3317 + }
3318 + }
3319 +
3320 + $interval_disabled = $recurrence['FREQ'] == 'ONCE' ? array('disabled' => 'disabled') : array();
3321 +
3322 + $args = array(
3323 +
3324 + 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' ),
3325 +
3326 + array(
3327 + 'title' => __( 'Description', 'propertyhive' ),
3328 + 'id' => 'management_key_date_type_name',
3329 + 'default' => $term_name,
3330 + 'type' => 'text',
3331 + 'desc_tip' => false,
3332 + ),
3333 +
3334 + array(
3335 + 'title' => __( 'Type', 'propertyhive' ),
3336 + 'id' => 'management_key_date_type_recurrence_type',
3337 + 'default' => $recurrence_type,
3338 + 'type' => 'select',
3339 + 'desc_tip' => false,
3340 + 'options' => array(
3341 + 'tenancy_management' => __( 'Tenancy Management', 'propertyhive' ),
3342 + 'property_management' => __( 'Property Management', 'propertyhive' ),
3343 + ),
3344 + ),
3345 +
3346 + array(
3347 + 'title' => __( 'Frequency', 'propertyhive' ),
3348 + 'id' => 'management_key_date_type_recurrence_freq',
3349 + 'default' => $recurrence['FREQ'],
3350 + 'type' => 'select',
3351 + 'desc_tip' => false,
3352 + 'options' => array(
3353 + 'ONCE' => __( 'Once', 'propertyhive' ),
3354 + 'DAILY' => __( 'Daily', 'propertyhive' ),
3355 + 'WEEKLY' => __( 'Weekly', 'propertyhive' ),
3356 + 'MONTHLY' => __( 'Monthly', 'propertyhive' ),
3357 + 'YEARLY' => __( 'Yearly', 'propertyhive' ),
3358 + ),
3359 + 'custom_attributes' => array('onchange' => "
3360 + jQuery('#management_key_date_type_recurrence_interval').prop( 'disabled', this.value == 'ONCE');
3361 + "),
3362 + ),
3363 +
3364 + array(
3365 + 'title' => __( 'Interval', 'propertyhive' ),
3366 + 'id' => 'management_key_date_type_recurrence_interval',
3367 + 'default' => $recurrence['INTERVAL'],
3368 + 'type' => 'number',
3369 + 'custom_attributes' => array_merge( array( 'min' => '1', 'required' => 'true'), $interval_disabled ),
3370 + '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>',
3371 + ),
3372 +
3373 + array(
3374 + 'type' => 'hidden',
3375 + 'id' => 'taxonomy',
3376 + 'default' => $taxonomy
3377 + ),
3378 +
3379 + array( 'type' => 'sectionend', 'id' => 'custom_field_management_key_date_type_settings' )
3380 +
3381 + );
3382 +
3383 + return apply_filters( 'propertyhive_custom_field_management_key_date_type_setting', $args );
3384 + }
3385 +
2232 3386 /**
2233 3387 * Show marketing flag add/edit options
2234 3388 *
2235 3389 * @access public
@@ -2236,9 +3390,10 @@
2236 3390 * @return string
2237 3391 */
2238 3392 public function get_custom_fields_marketing_flag_setting()
2239 3393 {
2240 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3394 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3395 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2241 3396
2242 3397 $taxonomy = 'marketing_flag';
2243 3398 $term_name = '';
2244 3399 if ($current_id != '')
@@ -2248,9 +3403,9 @@
2248 3403 }
2249 3404
2250 3405 $args = array(
2251 3406
2252 - array( 'title' => __( ( $current_id == '' ? 'Add New Marketing Flag' : 'Edit Marketing Flag' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_marketing_flag_settings' ),
3407 + array( 'title' => ( $current_id == '' ? __( 'Add New Marketing Flag', 'propertyhive' ) : __( 'Edit Marketing Flag', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_marketing_flag_settings' ),
2253 3408
2254 3409 array(
2255 3410 'title' => __( 'Marketing Flag', 'propertyhive' ),
2256 3411 'id' => 'marketing_flag_name',
@@ -2279,9 +3434,10 @@
2279 3434 * @return string
2280 3435 */
2281 3436 public function get_custom_fields_property_feature_setting()
2282 3437 {
2283 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
3438 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This settings getter only loads stored configuration for rendering; it does not mutate state.
3439 + $current_id = ( isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] ) ) ? sanitize_title( wp_unslash( $_REQUEST['id'] ) ) : '';
2284 3440
2285 3441 $taxonomy = 'property_feature';
2286 3442 $term_name = '';
2287 3443 if ($current_id != '')
@@ -2291,9 +3447,9 @@
2291 3447 }
2292 3448
2293 3449 $args = array(
2294 3450
2295 - array( 'title' => __( ( $current_id == '' ? 'Add New Property Feature' : 'Edit Property Feature' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_feature_settings' ),
3451 + array( 'title' => ( $current_id == '' ? __( 'Add New Property Feature', 'propertyhive' ) : __( 'Edit Property Feature', 'propertyhive' ) ), 'type' => 'title', 'desc' => '', 'id' => 'custom_field_property_feature_settings' ),
2296 3452
2297 3453 array(
2298 3454 'title' => __( 'Property Feature', 'propertyhive' ),
2299 3455 'id' => 'property_feature_name',
@@ -2314,232 +3470,496 @@
2314 3470
2315 3471 return apply_filters( 'propertyhive_custom_field_property_feature_settings', $args );
2316 3472 }
2317 3473
3474 + private function normalize_custom_fields_field_type( $value ) {
3475 + if ( ! is_string( $value ) ) {
3476 + return 'text';
3477 + }
3478 +
3479 + $field_type = sanitize_key( $value );
3480 + $allowed_types = array( 'text', 'textarea', 'select', 'multiselect', 'checkbox', 'date', 'image', 'file' );
3481 +
3482 + return in_array( $field_type, $allowed_types, true ) ? $field_type : 'text';
3483 + }
3484 +
3485 + private function normalize_custom_fields_dropdown_options( $value ) {
3486 + if ( ! is_array( $value ) ) {
3487 + return '';
3488 + }
3489 +
3490 + $options = array();
3491 + foreach ( $value as $option ) {
3492 + if ( ! is_string( $option ) ) {
3493 + return '';
3494 + }
3495 + $options[] = sanitize_text_field( $option );
3496 + }
3497 +
3498 + return $options;
3499 + }
3500 +
3501 + private function normalize_custom_fields_checkbox( $value ) {
3502 + return ( is_string( $value ) && '1' === $value ) ? '1' : '';
3503 + }
3504 +
3505 + private function normalize_custom_fields_meta_box( $value ) {
3506 + return is_string( $value ) ? sanitize_key( $value ) : '';
3507 + }
3508 +
3509 + private function normalize_custom_fields_term_id( $value, $allow_empty = true ) {
3510 + if ( ! is_string( $value ) ) {
3511 + return null;
3512 + }
3513 +
3514 + $value = trim( $value );
3515 + if ( '' === $value ) {
3516 + return $allow_empty ? '' : null;
3517 + }
3518 +
3519 + if ( ! preg_match( '/^[0-9]+$/D', $value ) ) {
3520 + return null;
3521 + }
3522 +
3523 + $term_id = absint( $value );
3524 + return $term_id > 0 ? (string) $term_id : null;
3525 + }
3526 +
3527 + private function normalize_custom_fields_render_term_id( $value ) {
3528 + $term_id = $this->normalize_custom_fields_term_id( $value );
3529 + return ( null === $term_id || '' === $term_id ) ? '' : absint( $term_id );
3530 + }
3531 +
3532 + private function normalize_custom_fields_parent_id( $value ) {
3533 + if ( ! is_string( $value ) ) {
3534 + return null;
3535 + }
3536 +
3537 + $value = trim( $value );
3538 + if ( '' === $value ) {
3539 + return 0;
3540 + }
3541 +
3542 + if ( ! preg_match( '/^[0-9]+$/D', $value ) ) {
3543 + return null;
3544 + }
3545 +
3546 + return absint( $value );
3547 + }
3548 +
3549 + private function normalize_custom_fields_term_id_list( $value ) {
3550 + if ( ! is_string( $value ) || '' === trim( $value ) ) {
3551 + return array();
3552 + }
3553 +
3554 + $term_ids = array();
3555 + foreach ( explode( '-', trim( $value ) ) as $term_id ) {
3556 + if ( ! preg_match( '/^[0-9]+$/D', $term_id ) ) {
3557 + return array();
3558 + }
3559 +
3560 + $term_id = absint( $term_id );
3561 + if ( $term_id < 1 || in_array( (string) $term_id, $term_ids, true ) ) {
3562 + return array();
3563 + }
3564 +
3565 + $term_ids[] = (string) $term_id;
3566 + }
3567 +
3568 + return $term_ids;
3569 + }
3570 +
3571 + private function normalize_custom_fields_reassignment( $value, $deleted_ids ) {
3572 + if ( ! is_string( $value ) ) {
3573 + return null;
3574 + }
3575 +
3576 + $value = trim( $value );
3577 + if ( '' === $value || 'none' === $value || ! preg_match( '/^[0-9]+$/D', $value ) ) {
3578 + return null;
3579 + }
3580 +
3581 + $term_id = (string) absint( $value );
3582 + if ( '0' === $term_id || in_array( $term_id, $deleted_ids, true ) ) {
3583 + return null;
3584 + }
3585 +
3586 + return $term_id;
3587 + }
3588 +
3589 + private function get_custom_fields_taxonomy_for_section( $section ) {
3590 + $taxonomies = array(
3591 + 'availability' => 'availability',
3592 + 'property-type' => 'property_type',
3593 + 'commercial-property-type' => 'commercial_property_type',
3594 + 'location' => 'location',
3595 + 'parking' => 'parking',
3596 + 'outside-space' => 'outside_space',
3597 + 'price-qualifier' => 'price_qualifier',
3598 + 'sale-by' => 'sale_by',
3599 + 'tenure' => 'tenure',
3600 + 'commercial-tenure' => 'commercial_tenure',
3601 + 'furnished' => 'furnished',
3602 + 'management-key-date-type' => 'management_key_date_type',
3603 + 'marketing-flag' => 'marketing_flag',
3604 + 'property-feature' => 'property_feature',
3605 + );
3606 +
3607 + if ( isset( $taxonomies[ $section ] ) ) {
3608 + return $taxonomies[ $section ];
3609 + }
3610 +
3611 + if ( is_string( $section ) && '-delete' === substr( $section, -7 ) ) {
3612 + $base_section = substr( $section, 0, -7 );
3613 + return isset( $taxonomies[ $base_section ] ) ? $taxonomies[ $base_section ] : '';
3614 + }
3615 +
3616 + return '';
3617 + }
3618 +
2318 3619 /**
2319 - * Save settings
3620 + * Save settings.
2320 3621 */
2321 3622 public function save() {
3623 + 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' ) ) {
3624 + return;
3625 + }
3626 +
2322 3627 global $current_section, $post;
2323 3628
2324 - if ( $current_section != '' )
2325 - {
2326 - if (isset($_REQUEST['id'])) // we're either adding or editing
2327 - {
2328 - $current_id = empty( $_REQUEST['id'] ) ? '' : sanitize_title( $_REQUEST['id'] );
2329 -
2330 - switch ($current_section)
2331 - {
2332 - // With heirarchy
2333 - case "property-type":
2334 - case "commercial-property-type":
2335 - case "location":
2336 - {
2337 - // TODO: Validate (check for blank fields)
2338 -
2339 - if ($current_id == '')
2340 - {
2341 - // Adding new term
2342 -
2343 - // TODO: Check term doesn't exist already
2344 -
3629 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing shared settings-router global; normalization preserves the public settings page contract.
3630 + $current_section = is_string( $current_section ) ? $current_section : '';
3631 + $request_id_present = isset( $_REQUEST['id'] ) && is_string( $_REQUEST['id'] );
3632 + $request_id = $request_id_present ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '';
3633 + $post_data = is_array( $_POST ) ? wp_unslash( $_POST ) : array();
3634 +
3635 + if ( '' === $current_section ) {
3636 + return;
3637 + }
3638 +
3639 + switch ( $current_section ) {
3640 + case 'addadditionalfield':
3641 + case 'editadditionalfield':
3642 + $current_settings = get_option( 'propertyhive_template_assistant', array() );
3643 + if ( ! is_array( $current_settings ) ) {
3644 + $current_settings = array();
3645 + }
3646 +
3647 + $current_id = $request_id_present ? sanitize_title( $request_id ) : '';
3648 + $existing_custom_fields = ( isset( $current_settings['custom_fields'] ) && is_array( $current_settings['custom_fields'] ) ) ? $current_settings['custom_fields'] : array();
3649 +
3650 + if ( 'editadditionalfield' === $current_section && 'default' !== $current_id && ! isset( $existing_custom_fields[ $current_id ] ) ) {
3651 + die( 'Trying to edit a non-existant custom field. Please go back and try again' );
3652 + }
3653 +
3654 + $field_label = ( isset( $post_data['field_label'] ) && is_string( $post_data['field_label'] ) ) ? sanitize_text_field( $post_data['field_label'] ) : '';
3655 + $field_name = ( isset( $post_data['field_name'] ) && is_string( $post_data['field_name'] ) ) ? sanitize_title( $post_data['field_name'] ) : '';
3656 + if ( '' === trim( $field_name ) ) {
3657 + $field_name = str_replace( '-', '_', sanitize_title( $field_label ) );
3658 + }
3659 + $field_name = '_' . ltrim( $field_name, '_' );
3660 +
3661 + $field_type = $this->normalize_custom_fields_field_type( isset( $post_data['field_type'] ) ? $post_data['field_type'] : '' );
3662 + $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'] ) : '';
3663 + $field_settings = array(
3664 + 'field_label' => $field_label,
3665 + 'field_name' => $field_name,
3666 + 'field_type' => $field_type,
3667 + 'dropdown_options' => $dropdown_options,
3668 + 'meta_box' => $this->normalize_custom_fields_meta_box( isset( $post_data['meta_box'] ) ? $post_data['meta_box'] : '' ),
3669 + 'display_on_website' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_website'] ) ? $post_data['display_on_website'] : '' ),
3670 + 'display_on_applicant_requirements' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_applicant_requirements'] ) ? $post_data['display_on_applicant_requirements'] : '' ),
3671 + 'exact_match' => $this->normalize_custom_fields_checkbox( isset( $post_data['exact_match'] ) ? $post_data['exact_match'] : '' ),
3672 + 'display_on_user_details' => $this->normalize_custom_fields_checkbox( isset( $post_data['display_on_user_details'] ) ? $post_data['display_on_user_details'] : '' ),
3673 + 'admin_list' => $this->normalize_custom_fields_checkbox( isset( $post_data['admin_list'] ) ? $post_data['admin_list'] : '' ),
3674 + 'admin_list_sortable' => $this->normalize_custom_fields_checkbox( isset( $post_data['admin_list_sortable'] ) ? $post_data['admin_list_sortable'] : '' ),
3675 + );
3676 +
3677 + if ( 'addadditionalfield' === $current_section ) {
3678 + $existing_custom_fields[] = $field_settings;
3679 + } else {
3680 + $existing_custom_fields[ $current_id ] = $field_settings;
3681 + }
3682 +
3683 + $current_settings['custom_fields'] = $existing_custom_fields;
3684 +
3685 + if ( 'addadditionalfield' !== $current_section && ! empty( $current_settings['search_forms'] ) && is_array( $current_settings['search_forms'] ) ) {
3686 + foreach ( $current_settings['search_forms'] as $search_form_id => $search_form ) {
3687 + if ( isset( $search_form['active_fields'] ) && is_array( $search_form['active_fields'] ) ) {
3688 + foreach ( $search_form['active_fields'] as $field_id => $field_data ) {
3689 + if ( $field_name === $field_id ) {
3690 + $current_settings['search_forms'][ $search_form_id ]['active_fields'][ $field_id ]['type'] = $field_type;
3691 + }
3692 + }
3693 + }
3694 +
3695 + if ( isset( $search_form['inactive_fields'] ) && is_array( $search_form['inactive_fields'] ) ) {
3696 + foreach ( $search_form['inactive_fields'] as $field_id => $field_data ) {
3697 + if ( $field_name === $field_id ) {
3698 + $current_settings['search_forms'][ $search_form_id ]['inactive_fields'][ $field_id ]['type'] = $field_type;
3699 + }
3700 + }
3701 + }
3702 + }
3703 + }
3704 +
3705 + update_option( 'propertyhive_template_assistant', $current_settings );
3706 + break;
3707 +
3708 + default:
3709 + if ( ! $request_id_present ) {
3710 + break;
3711 + }
3712 +
3713 + $taxonomy = $this->get_custom_fields_taxonomy_for_section( $current_section );
3714 + $is_delete_section = '-delete' === substr( $current_section, -7 );
3715 +
3716 + if ( '' !== $taxonomy ) {
3717 + if ( $is_delete_section ) {
3718 + $term_ids = $this->normalize_custom_fields_term_id_list( $request_id );
3719 + if ( empty( $term_ids ) ) {
3720 + return;
3721 + }
3722 + $current_id = implode( '-', $term_ids );
3723 + } else {
3724 + $current_id = $this->normalize_custom_fields_term_id( $request_id );
3725 + if ( null === $current_id ) {
3726 + return;
3727 + }
3728 + }
3729 + } else {
3730 + $current_id = sanitize_text_field( $request_id );
3731 + }
3732 +
3733 + switch ( $current_section ) {
3734 + case 'property-type':
3735 + case 'commercial-property-type':
3736 + case 'location':
3737 + $term_name_key = $taxonomy . '_name';
3738 + $parent_key = 'parent_' . $taxonomy . '_id';
3739 + $term_name = ( isset( $post_data[ $term_name_key ] ) && is_string( $post_data[ $term_name_key ] ) ) ? sanitize_text_field( $post_data[ $term_name_key ] ) : '';
3740 + $parent_id = $this->normalize_custom_fields_parent_id( isset( $post_data[ $parent_key ] ) ? $post_data[ $parent_key ] : '' );
3741 + if ( '' === $term_name || null === $parent_id ) {
3742 + return;
3743 + }
3744 +
3745 + if ( '' === $current_id ) {
2345 3746 wp_insert_term(
2346 - $_POST[$_POST['taxonomy'] . '_name'], // the term
2347 - $_POST['taxonomy'], // the taxonomy
3747 + $term_name,
3748 + $taxonomy,
3749 + array( 'parent' => $parent_id )
3750 + );
3751 + } else {
3752 + wp_update_term(
3753 + absint( $current_id ),
3754 + $taxonomy,
2348 3755 array(
2349 - 'parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id']
3756 + 'name' => $term_name,
3757 + 'parent' => $parent_id,
2350 3758 )
2351 3759 );
2352 -
2353 - // TODO: Check for errors returned from wp_insert_term()
2354 3760 }
2355 - else
2356 - {
2357 - // Editing term
2358 - wp_update_term($current_id, $_POST['taxonomy'], array(
2359 - 'name' => $_POST[$_POST['taxonomy'].'_name'],
2360 - 'parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id']
2361 - ));
2362 -
2363 - // TODO: Check for errors returned from wp_update_term()
3761 + break;
3762 +
3763 + case 'availability':
3764 + case 'outside-space':
3765 + case 'parking':
3766 + case 'price-qualifier':
3767 + case 'sale-by':
3768 + case 'tenure':
3769 + case 'commercial-tenure':
3770 + case 'furnished':
3771 + case 'management-key-date-type':
3772 + case 'marketing-flag':
3773 + case 'property-feature':
3774 + $term_name_key = $taxonomy . '_name';
3775 + $term_name = ( isset( $post_data[ $term_name_key ] ) && is_string( $post_data[ $term_name_key ] ) ) ? sanitize_text_field( $post_data[ $term_name_key ] ) : '';
3776 + if ( '' === $term_name ) {
3777 + return;
2364 3778 }
2365 - break;
2366 - }
2367 - // Without heirarchy
2368 - case "availability":
2369 - case "outside-space":
2370 - case "parking":
2371 - case "price-qualifier":
2372 - case "sale-by":
2373 - case "tenure":
2374 - case "commercial-tenure":
2375 - case "furnished":
2376 - case "marketing-flag":
2377 - case "property-feature":
2378 - {
2379 - // TODO: Validate (check for blank fields)
2380 -
2381 - if ($current_id == '')
2382 - {
2383 - // Adding new term
2384 -
2385 - // TODO: Check term doesn't exist already
2386 -
2387 - wp_insert_term(
2388 - $_POST[$_POST['taxonomy'] . '_name'], // the term
2389 - $_POST['taxonomy'] // the taxonomy
2390 - );
2391 -
2392 - // TODO: Check for errors returned from wp_insert_term()
3779 +
3780 + if ( '' === $current_id ) {
3781 + $term = wp_insert_term( $term_name, $taxonomy );
3782 + if ( ! is_wp_error( $term ) ) {
3783 + $current_id = isset( $term['term_id'] ) ? (string) absint( $term['term_id'] ) : '0';
3784 + }
3785 + } else {
3786 + wp_update_term( absint( $current_id ), $taxonomy, array( 'name' => $term_name ) );
2393 3787 }
2394 - else
2395 - {
2396 - // Editing term
2397 - wp_update_term($current_id, $_POST['taxonomy'], array(
2398 - 'name' => $_POST[$_POST['taxonomy'] . '_name']
2399 - ));
2400 -
2401 - // TODO: Check for errors returned from wp_update_term()
3788 +
3789 + if ( 'availability' === $current_section ) {
3790 + $availability_departments = get_option( 'propertyhive_availability_departments', array() );
3791 + if ( ! is_array( $availability_departments ) ) {
3792 + $availability_departments = array();
3793 + }
3794 +
3795 + $departments = ph_get_departments();
3796 + $posted_departments = ( isset( $post_data['department'] ) && is_array( $post_data['department'] ) ) ? $post_data['department'] : array();
3797 + $availability_departments[ $current_id ] = array();
3798 + foreach ( $departments as $key => $value ) {
3799 + if ( isset( $posted_departments[ $key ] ) && is_string( $posted_departments[ $key ] ) && '1' === $posted_departments[ $key ] ) {
3800 + $availability_departments[ $current_id ][] = $key;
3801 + }
3802 + }
3803 + update_option( 'propertyhive_availability_departments', $availability_departments );
2402 3804 }
3805 +
3806 + if ( 'management-key-date-type' === $current_section ) {
3807 + $options = get_option( 'propertyhive_key_date_type', array() );
3808 + if ( ! is_array( $options ) ) {
3809 + $options = array();
3810 + }
3811 +
3812 + $recurrence = array();
3813 + $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'] ) ) : '';
3814 + if ( in_array( $frequency, array( 'ONCE', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY' ), true ) ) {
3815 + $recurrence[] = 'FREQ=' . $frequency;
3816 + }
3817 +
3818 + $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'] ) : '';
3819 + if ( '' !== $interval && preg_match( '/^[1-9][0-9]*$/D', $interval ) ) {
3820 + $recurrence[] = 'INTERVAL=' . absint( $interval );
3821 + }
3822 +
3823 + $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'] ) : '';
3824 + if ( ! in_array( $recurrence_type, array( 'tenancy_management', 'property_management' ), true ) ) {
3825 + $recurrence_type = '';
3826 + }
3827 +
3828 + $options[ $current_id ]['recurrence_rule'] = join( ';', $recurrence );
3829 + $options[ $current_id ]['recurrence_type'] = $recurrence_type;
3830 + update_option( 'propertyhive_key_date_type', $options );
3831 + }
2403 3832 break;
2404 - }
2405 - case "availability-delete":
2406 - case "property-type-delete":
2407 - case "commercial-property-type-delete":
2408 - case "location-delete":
2409 - case "parking-delete":
2410 - case "outside-space-delete":
2411 - case "price-qualifier-delete":
2412 - case "sale-by-delete":
2413 - case "tenure-delete":
2414 - case "furnished-delete":
2415 - case "marketing-flag-delete":
2416 - case "property-feature-delete":
2417 - {
2418 - if ( isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == '1' )
2419 - {
2420 - $term_ids = explode("-", $current_id);
2421 3833
2422 - foreach ( $term_ids as $current_id )
2423 - {
2424 - // Update properties that have this taxonomy term set
3834 + case 'availability-delete':
3835 + case 'property-type-delete':
3836 + case 'commercial-property-type-delete':
3837 + case 'location-delete':
3838 + case 'parking-delete':
3839 + case 'outside-space-delete':
3840 + case 'price-qualifier-delete':
3841 + case 'sale-by-delete':
3842 + case 'tenure-delete':
3843 + case 'commercial-tenure-delete':
3844 + case 'furnished-delete':
3845 + case 'management-key-date-type-delete':
3846 + case 'marketing-flag-delete':
3847 + case 'property-feature-delete':
3848 + if ( ! isset( $post_data['confirm_removal'] ) || ! is_string( $post_data['confirm_removal'] ) || '1' !== $post_data['confirm_removal'] ) {
3849 + break;
3850 + }
3851 +
3852 + foreach ( $term_ids as $current_id ) {
3853 + $query_args = array(
3854 + 'post_type' => 'property',
3855 + 'nopaging' => true,
3856 + 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
3857 + // 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.
3858 + 'tax_query' => array(
3859 + array(
3860 + 'taxonomy' => $taxonomy,
3861 + 'field' => 'id',
3862 + 'terms' => $current_id,
3863 + ),
3864 + ),
3865 + );
3866 + $property_query = new WP_Query( $query_args );
3867 +
3868 + if ( $property_query->have_posts() ) {
3869 + while ( $property_query->have_posts() ) {
3870 + $property_query->the_post();
3871 + wp_remove_object_terms( $post->ID, $current_id, $taxonomy );
3872 +
3873 + $new_id = $this->normalize_custom_fields_reassignment( isset( $post_data[ 'reassign_to_' . $current_id ] ) ? $post_data[ 'reassign_to_' . $current_id ] : '', $term_ids );
3874 + if ( null !== $new_id ) {
3875 + wp_set_post_terms( $post->ID, $new_id, $taxonomy, true );
3876 + }
3877 + }
3878 + }
3879 + wp_reset_postdata();
3880 +
3881 + if ( 'availability-delete' === $current_section ) {
3882 + $availability_departments = get_option( 'propertyhive_availability_departments', array() );
3883 + if ( is_array( $availability_departments ) && isset( $availability_departments[ $current_id ] ) ) {
3884 + unset( $availability_departments[ $current_id ] );
3885 + update_option( 'propertyhive_availability_departments', $availability_departments );
3886 + }
3887 + }
3888 +
3889 + if ( in_array( $taxonomy, array( 'property_type', 'commercial_property_type', 'location' ), true ) ) {
2425 3890 $query_args = array(
2426 - 'post_type' => 'property',
2427 - 'nopaging' => true,
3891 + 'post_type' => 'contact',
3892 + 'nopaging' => true,
2428 3893 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2429 - 'tax_query' => array(
3894 + // 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.
3895 + 'meta_query' => array(
2430 3896 array(
2431 - 'taxonomy' => $_POST['taxonomy'],
2432 - 'field' => 'id',
2433 - 'terms' => $current_id,
3897 + 'key' => '_contact_types',
3898 + 'value' => 'applicant',
3899 + 'compare' => 'LIKE',
2434 3900 ),
2435 3901 ),
2436 3902 );
2437 - $property_query = new WP_Query( $query_args );
2438 -
2439 - if ( $property_query->have_posts() )
2440 - {
2441 - while ( $property_query->have_posts() )
2442 - {
2443 - $property_query->the_post();
2444 -
2445 - wp_remove_object_terms( $post->ID, $current_id, $_POST['taxonomy'] );
2446 -
2447 - // Re-assign to another term
2448 - if ( isset($_POST['reassign_to_' . $current_id]) && ! empty( $_POST['reassign_to_' . $current_id] ) && $_POST['reassign_to_' . $current_id] != 'none' )
2449 - {
2450 - $new_id = $_POST['reassign_to_' . $current_id];
2451 -
2452 - wp_set_post_terms( $post->ID, $new_id, $_POST['taxonomy'], TRUE );
2453 -
2454 - // TODO: Check for WP_ERROR
3903 + $applicant_query = new WP_Query( $query_args );
3904 +
3905 + if ( $applicant_query->have_posts() ) {
3906 + while ( $applicant_query->have_posts() ) {
3907 + $applicant_query->the_post();
3908 + $num_applicant_profiles = get_post_meta( get_the_ID(), '_applicant_profiles', true );
3909 + if ( '' === $num_applicant_profiles ) {
3910 + $num_applicant_profiles = 0;
2455 3911 }
2456 - }
2457 - }
2458 -
2459 - wp_reset_postdata();
2460 3912
2461 - if ( $_POST['taxonomy'] == 'property_type' || $_POST['taxonomy'] == 'commercial_property_type' || $_POST['taxonomy'] == 'location' )
2462 - {
2463 - $query_args = array(
2464 - 'post_type' => 'contact',
2465 - 'nopaging' => true,
2466 - 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ),
2467 - 'meta_query' => array(
2468 - array(
2469 - 'key' => '_contact_types',
2470 - 'value' => 'applicant',
2471 - 'compare' => 'LIKE'
2472 - ),
2473 - ),
2474 - );
2475 - $applicant_query = new WP_Query( $query_args );
3913 + if ( $num_applicant_profiles > 0 ) {
3914 + for ( $i = 0; $i < $num_applicant_profiles; ++$i ) {
3915 + $applicant_profile = get_post_meta( get_the_ID(), '_applicant_profile_' . $i, true );
3916 + $profile_key = $taxonomy . 's';
3917 + if ( ! is_array( $applicant_profile ) || ! isset( $applicant_profile[ $profile_key ] ) || ! is_array( $applicant_profile[ $profile_key ] ) ) {
3918 + continue;
3919 + }
2476 3920
2477 - if ( $applicant_query->have_posts() )
2478 - {
2479 - while ( $applicant_query->have_posts() )
2480 - {
2481 - $applicant_query->the_post();
2482 -
2483 - $num_applicant_profiles = get_post_meta( get_the_ID(), '_applicant_profiles', TRUE );
2484 - if ( $num_applicant_profiles == '' )
2485 - {
2486 - $num_applicant_profiles = 0;
2487 - }
3921 + $profile_terms = array();
3922 + foreach ( $applicant_profile[ $profile_key ] as $profile_term_id ) {
3923 + if ( is_scalar( $profile_term_id ) ) {
3924 + $profile_terms[] = (string) absint( $profile_term_id );
3925 + }
3926 + }
3927 + if ( ! in_array( (string) $current_id, $profile_terms, true ) ) {
3928 + continue;
3929 + }
2488 3930
2489 - if ( $num_applicant_profiles > 0 )
2490 - {
2491 - for ( $i = 0; $i < $num_applicant_profiles; ++$i )
2492 - {
2493 - $applicant_profile = get_post_meta( get_the_ID(), '_applicant_profile_' . $i, TRUE );
2494 -
2495 - if ( isset($applicant_profile[$_POST['taxonomy'].'s']) && is_array($applicant_profile[$_POST['taxonomy'].'s']) && !empty($applicant_profile[$_POST['taxonomy'].'s']) )
2496 - {
2497 - if (in_array($current_id, $applicant_profile[$_POST['taxonomy'].'s']))
2498 - {
2499 - // This profile has this term set
2500 - unset($applicant_profile[$_POST['taxonomy'].'s'][$current_id]);
2501 -
2502 - if ( isset($_POST['reassign_to_' . $current_id]) && ! empty( $_POST['reassign_to_' . $current_id] ) && $_POST['reassign_to_' . $current_id] != 'none' )
2503 - {
2504 - $applicant_profile[$_POST['taxonomy'].'s'][] = $_POST['reassign_to_' . $current_id];
2505 - $applicant_profile[$_POST['taxonomy'].'s'] = array_unique($applicant_profile[$_POST['taxonomy'].'s']);
2506 - }
2507 -
2508 - $applicant_profile[$_POST['taxonomy'].'s'] = array_values($applicant_profile[$_POST['taxonomy'].'s']);
2509 -
2510 - update_post_meta( get_the_ID(), '_applicant_profile_' . $i, $applicant_profile );
2511 - }
2512 - }
3931 + $profile_terms = array_values( array_filter( $profile_terms, static function ( $profile_term_id ) use ( $current_id ) {
3932 + return (string) $profile_term_id !== (string) $current_id;
3933 + } ) );
3934 + $new_id = $this->normalize_custom_fields_reassignment( isset( $post_data[ 'reassign_to_' . $current_id ] ) ? $post_data[ 'reassign_to_' . $current_id ] : '', $term_ids );
3935 + if ( null !== $new_id ) {
3936 + $profile_terms[] = $new_id;
2513 3937 }
3938 + $applicant_profile[ $profile_key ] = array_values( array_unique( $profile_terms ) );
3939 + update_post_meta( get_the_ID(), '_applicant_profile_' . $i, wp_slash( $applicant_profile ) );
2514 3940 }
2515 3941 }
2516 3942 }
2517 3943 }
2518 -
2519 3944 wp_reset_postdata();
3945 + }
2520 3946
2521 - wp_delete_term( $current_id, $_POST['taxonomy'] );
2522 - }
3947 + wp_delete_term( absint( $current_id ), $taxonomy );
2523 3948 }
3949 + break;
2524 3950
3951 + default:
3952 + $section_found = apply_filters( 'propertyhive_custom_fields_save_section', false, $current_section, $current_id );
3953 + if ( ! $section_found ) {
3954 + echo 'UNKNOWN CUSTOM FIELD';
3955 + }
2525 3956 break;
2526 - }
2527 - default: { echo 'UNKNOWN CUSTOM FIELD'; }
2528 3957 }
2529 - }
2530 - else
2531 - {
2532 - // Nothing to save. Should always be an id set when editing custom fields.
2533 - // Even blank ids dictate something is being added
2534 - }
3958 + break;
2535 3959 }
2536 - else
2537 - {
2538 - // Nothing to save. Should always be a section when editing custom fields
2539 - }
2540 3960 }
2541 3961 }
2542 3962
2543 3963 endif;
2544 3964
2545 -return new PH_Settings_Custom_Fields();
3965 +return new PH_Settings_Custom_Fields();