PluginProbe
Property Hive / 1.4.59
Property Hive v1.4.59
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
propertyhive / includes / admin / post-types / class-ph-admin-meta-boxes.php

class-ph-admin-meta-boxes.php in Property Hive 1.4.59, at includes/admin/post-types/class-ph-admin-meta-boxes.php

1,776 lines 73.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Meta Boxes
4 *
5 * Sets up the write panels used by products and orders (custom post types)
6 *
7 * @author BIOSTA::
8 * @category Admin
9 * @package PropertyHive/Admin/Meta Boxes
10 * @version 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 if ( ! class_exists( 'PH_Admin_Meta_Boxes' ) )
16 {
17
18 /**
19 * PH_Admin_Meta_Boxes
20 */
21 class PH_Admin_Meta_Boxes {
22
23 private static $meta_box_errors = array();
24
25 /**
26 * Constructor
27 */
28 public function __construct() {
29
30 add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
31 add_action( 'add_meta_boxes', array( $this, 'rename_meta_boxes' ), 20 );
32 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 );
33 add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
34
35 // Save Property Meta Boxes
36 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Address::save', 10, 2 );
37 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Owner::save', 12, 2 );
38 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Record_Details::save', 13, 2 );
39 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Coordinates::save', 70, 2 );
40
41 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Department::save', 15, 2 );
42 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Details::save', 20, 2 );
43 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Lettings_Details::save', 25, 2 );
44 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Sales_Details::save', 30, 2 );
45 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Commercial_Details::save', 30, 2 );
46
47 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Marketing::save', 35, 2 );
48
49 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Rooms::save', 40, 2 );
50 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Features::save', 45, 2 );
51 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Description::save', 45, 2 );
52
53 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Photos::save', 50, 2 );
54 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Floorplans::save', 55, 2 );
55 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Brochures::save', 65, 2 );
56 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Epcs::save', 70, 2 );
57 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Virtual_Tours::save', 75, 2 );
58
59 // Save Contact Meta Boxes
60 if ( isset($_POST['_contact_type_new']) )
61 {
62 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_New_Relationship::save', 1, 2 );
63 }
64 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Correspondence_Address::save', 10, 2 );
65 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Contact_Details::save', 15, 2 );
66 if ( !isset($_POST['_contact_type_new']) )
67 {
68 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Relationships::save', 20, 2 );
69 }
70
71 // Save Enquiry Meta Boxes
72 if ( get_option('propertyhive_module_disabled_enquiries', '') != 'yes' )
73 {
74 add_action( 'propertyhive_process_enquiry_meta', 'PH_Meta_Box_Enquiry_Record_Details::save', 10, 2 );
75 add_action( 'propertyhive_process_enquiry_meta', 'PH_Meta_Box_Enquiry_Details::save', 15, 2 );
76 }
77
78 // Save Appraisal Meta Boxes
79 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Details::save', 10, 2 );
80 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Event::save', 15, 2 );
81 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Property_Owner::save', 20, 2 );
82 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Property::save', 25, 2 );
83
84 // Save Viewing Meta Boxes
85 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Details::save', 10, 2 );
86 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Event::save', 15, 2 );
87 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Applicant::save', 20, 2 );
88 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Property::save', 25, 2 );
89
90 // Save Offer Meta Boxes
91 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Details::save', 10, 2 );
92 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Applicant::save', 15, 2 );
93 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Applicant_Solicitor::save', 20, 2 );
94 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Property::save', 25, 2 );
95 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Property_Owner_Solicitor::save', 30, 2 );
96
97 // Save Sale Meta Boxes
98 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Details::save', 10, 2 );
99 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Applicant_Solicitor::save', 15, 2 );
100 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Property_Owner_Solicitor::save', 20, 2 );
101
102 // Error handling (for showing errors from meta boxes on next page load)
103 add_action( 'admin_notices', array( $this, 'output_errors' ) );
104 add_action( 'shutdown', array( $this, 'save_errors' ) );
105
106 add_filter( 'redirect_post_location', array( $this, 'redirect_to_tab' ), 10, 2 );
107
108 $this->check_contact_create_relationship();
109 $this->check_contact_delete_relationship();
110 $this->check_remove_solicitor();
111 $this->check_create_offer();
112 $this->check_create_sale();
113 }
114
115 public function redirect_to_tab( $url, $post_id )
116 {
117 if ( isset($_POST['propertyhive_selected_metabox_tab']) )
118 {
119 $url .= '#' . $_POST['propertyhive_selected_metabox_tab'];
120 }
121
122 return $url;
123 }
124
125 public function check_contact_create_relationship()
126 {
127 if ( isset($_GET['add_applicant_relationship']) && wp_verify_nonce($_GET['add_applicant_relationship'], '1') && isset($_GET['post']) )
128 {
129 // Need to add blank applicant
130 if ( get_post_type((int)$_GET['post']) != 'contact' )
131 return;
132
133 $num_applicant_profiles = get_post_meta( (int)$_GET['post'], '_applicant_profiles', TRUE );
134 if ( $num_applicant_profiles == '' )
135 {
136 $num_applicant_profiles = 0;
137 }
138
139 update_post_meta( (int)$_GET['post'], '_applicant_profile_' . $num_applicant_profiles, '' );
140 update_post_meta( (int)$_GET['post'], '_applicant_profiles', $num_applicant_profiles + 1 );
141
142 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
143 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
144 {
145 $existing_contact_types = array();
146 }
147 if ( !in_array( 'applicant', $existing_contact_types ) )
148 {
149 $existing_contact_types[] = 'applicant';
150 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
151 }
152
153 // Do redirect
154 wp_redirect( admin_url( 'post.php?post=' . (int)$_GET['post'] . '&action=edit#propertyhive-contact-relationships' ) );
155 exit();
156 }
157
158 if ( isset($_GET['add_third_party_relationship']) && wp_verify_nonce($_GET['add_third_party_relationship'], '1') && isset($_GET['post']) )
159 {
160 // Need to add blank third party relationship
161 if ( get_post_type((int)$_GET['post']) != 'contact' )
162 return;
163
164 $existing_third_party_categories = get_post_meta( (int)$_GET['post'], '_third_party_categories', TRUE );
165 if ( !is_array($existing_third_party_categories) )
166 {
167 $existing_third_party_categories = array();
168 }
169 $existing_third_party_categories[] = 0;
170 update_post_meta( $_GET['post'], '_third_party_categories', $existing_third_party_categories );
171
172 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
173 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
174 {
175 $existing_contact_types = array();
176 }
177 if ( !in_array( 'thirdparty', $existing_contact_types ) )
178 {
179 $existing_contact_types[] = 'thirdparty';
180 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
181 }
182 }
183 }
184
185 public function check_contact_delete_relationship()
186 {
187 if ( isset($_GET['delete_applicant_relationship']) && isset($_GET['post']) )
188 {
189 // Need to add blank applicant
190 if ( get_post_type((int)$_GET['post']) != 'contact' )
191 return;
192
193 $num_applicant_profiles = get_post_meta( (int)$_GET['post'], '_applicant_profiles', TRUE );
194 if ( $num_applicant_profiles == '' )
195 {
196 $num_applicant_profiles = 0;
197 }
198
199 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
200 {
201 if ( wp_verify_nonce($_GET['delete_applicant_relationship'], $i) )
202 {
203 $deleting_applicant_profile = $i;
204
205 // We're deleting this one
206 delete_post_meta( (int)$_GET['post'], '_applicant_profile_' . $i );
207
208 // Now need to rename any that are higher than $deleting_applicant_profile
209 for ( $j = 0; $j < $num_applicant_profiles; ++$j )
210 {
211 if ( $j > $deleting_applicant_profile )
212 {
213 $this_applicant_profile = get_post_meta( (int)$_GET['post'], '_applicant_profile_' . $j );
214 update_post_meta( (int)$_GET['post'], '_applicant_profile_' . ($j - 1), $this_applicant_profile );
215 delete_post_meta( (int)$_GET['post'], '_applicant_profile_' . $j );
216 }
217 }
218
219 // remove from _contact_types if no more profiles left
220 if ( $num_applicant_profiles == 1 )
221 {
222 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
223 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
224 {
225 $existing_contact_types = array();
226 }
227 if( ( $key = array_search('applicant', $existing_contact_types) ) !== false )
228 {
229 unset($existing_contact_types[$key]);
230 }
231 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
232 }
233
234 update_post_meta( (int)$_GET['post'], '_applicant_profiles', $num_applicant_profiles - 1 );
235
236 // Do redirect
237 wp_redirect( admin_url( 'post.php?post=' . (int)$_GET['post'] . '&action=edit#propertyhive-contact-relationships' ) );
238 exit();
239 }
240 }
241 }
242 }
243
244 public function check_remove_solicitor()
245 {
246 if ( isset($_GET['remove_property_owner_solicitor']) && isset($_GET['post']) )
247 {
248 if ( get_post_type((int)$_GET['post']) != 'offer' && get_post_type((int)$_GET['post']) != 'sale' )
249 return;
250
251 update_post_meta( (int)$_GET['post'], '_property_owner_solicitor_contact_id', '' );
252 }
253
254 if ( isset($_GET['remove_applicant_solicitor']) && isset($_GET['post']) )
255 {
256 if ( get_post_type((int)$_GET['post']) != 'offer' && get_post_type((int)$_GET['post']) != 'sale' )
257 return;
258
259 update_post_meta( (int)$_GET['post'], '_applicant_solicitor_contact_id', '' );
260 }
261 }
262
263 public function check_create_offer()
264 {
265 if ( isset($_GET['create_offer']) && isset($_GET['post']) )
266 {
267 if ( get_post_type((int)$_GET['post']) != 'viewing')
268 return;
269
270 $viewing = new PH_Viewing((int)$_GET['post']);
271
272 $offer_post = array(
273 'post_title' => '',
274 'post_content' => '',
275 'post_type' => 'offer',
276 'post_status' => 'publish',
277 'comment_status' => 'closed',
278 'ping_status' => 'closed',
279 );
280
281 // Insert the post into the database
282 $offer_post_id = wp_insert_post( $offer_post );
283
284 add_post_meta( $offer_post_id, '_status', 'pending' );
285 add_post_meta( $offer_post_id, '_amount', '' );
286 add_post_meta( $offer_post_id, '_applicant_contact_id', $viewing->applicant_contact_id );
287 add_post_meta( $offer_post_id, '_applicant_solicitor_contact_id', '' );
288 add_post_meta( $offer_post_id, '_property_id', $viewing->property_id );
289 add_post_meta( $offer_post_id, '_property_owner_solicitor_contact_id', '' );
290 add_post_meta( $offer_post_id, '_offer_date_time', date("Y-m-d H:i:s") );
291
292 update_post_meta( (int)$_GET['post'], '_offer_id', $offer_post_id );
293 update_post_meta( (int)$_GET['post'], '_status', 'offer_made' );
294
295 $current_user = wp_get_current_user();
296
297 // Add note/comment to viewing
298 $comment = array(
299 'note_type' => 'action',
300 'action' => 'viewing_offer_made',
301 );
302
303 $data = array(
304 'comment_post_ID' => (int)$_GET['post'],
305 'comment_author' => $current_user->display_name,
306 'comment_author_email' => 'propertyhive@noreply.com',
307 'comment_author_url' => '',
308 'comment_date' => date("Y-m-d H:i:s"),
309 'comment_content' => serialize($comment),
310 'comment_approved' => 1,
311 'comment_type' => 'propertyhive_note',
312 );
313 $comment_id = wp_insert_comment( $data );
314
315 // Do redirect
316 wp_redirect( admin_url( 'post.php?post=' . $offer_post_id . '&action=edit' ) );
317 exit();
318 }
319
320 }
321
322 public function check_create_sale()
323 {
324 if ( isset($_GET['create_sale']) && isset($_GET['post']) )
325 {
326 if ( get_post_type((int)$_GET['post']) != 'offer')
327 return;
328
329 $offer = new PH_Offer((int)$_GET['post']);
330
331 $sale_post = array(
332 'post_title' => '',
333 'post_content' => '',
334 'post_type' => 'sale',
335 'post_status' => 'publish',
336 'comment_status' => 'closed',
337 'ping_status' => 'closed',
338 );
339
340 // Insert the post into the database
341 $sale_post_id = wp_insert_post( $sale_post );
342
343 add_post_meta( $sale_post_id, '_status', 'current' );
344 add_post_meta( $sale_post_id, '_amount', $offer->amount );
345 add_post_meta( $sale_post_id, '_applicant_contact_id', $offer->applicant_contact_id );
346 add_post_meta( $sale_post_id, '_applicant_solicitor_contact_id', $offer->applicant_solicitor_contact_id );
347 add_post_meta( $sale_post_id, '_property_id', $offer->property_id );
348 add_post_meta( $sale_post_id, '_property_owner_solicitor_contact_id', $offer->property_owner_solicitor_contact_id );
349 add_post_meta( $sale_post_id, '_sale_date_time', date("Y-m-d H:i:s") );
350
351 update_post_meta( (int)$_GET['post'], '_sale_id', $sale_post_id );
352
353 $current_user = wp_get_current_user();
354
355 // Add note/comment to offer
356 $comment = array(
357 'note_type' => 'action',
358 'action' => 'offer_sale_created',
359 );
360
361 $data = array(
362 'comment_post_ID' => (int)$_GET['post'],
363 'comment_author' => $current_user->display_name,
364 'comment_author_email' => 'propertyhive@noreply.com',
365 'comment_author_url' => '',
366 'comment_date' => date("Y-m-d H:i:s"),
367 'comment_content' => serialize($comment),
368 'comment_approved' => 1,
369 'comment_type' => 'propertyhive_note',
370 );
371 $comment_id = wp_insert_comment( $data );
372
373 // Do redirect
374 wp_redirect( admin_url( 'post.php?post=' . $sale_post_id . '&action=edit' ) );
375 exit();
376 }
377
378 }
379
380 /**
381 * Add an error message
382 * @param string $text
383 */
384 public static function add_error( $text ) {
385 self::$meta_box_errors[] = $text;
386 }
387
388 /**
389 * Save errors to an option
390 */
391 public function save_errors() {
392 update_option( 'propertyhivemeta_box_errors', self::$meta_box_errors );
393 }
394
395 /**
396 * Show any stored error messages.
397 */
398 public function output_errors() {
399
400 $errors = maybe_unserialize( get_option( 'propertyhive_meta_box_errors' ) );
401
402 if ( ! empty( $errors ) ) {
403
404 echo '<div id="propertyhive_errors" class="error fade">';
405 foreach ( $errors as $error ) {
406 echo '<p>' . esc_html( $error ) . '</p>';
407 }
408 echo '</div>';
409
410 // Clear
411 delete_option( 'propertyhive_meta_box_errors' );
412 }
413 }
414
415 /**
416 * Add PH Meta boxes
417 */
418 public function add_meta_boxes() {
419
420 global $tabs, $post, $pagenow;
421
422 // PROPERTY
423 if (!isset($tabs)) $tabs = array();
424
425 /* PROPERTY SUMMARY META BOXES */
426 $meta_boxes = array();
427 $meta_boxes[5] = array(
428 'id' => 'propertyhive-property-address',
429 'title' => __( 'Property Address', 'propertyhive' ),
430 'callback' => 'PH_Meta_Box_Property_Address::output',
431 'screen' => 'property',
432 'context' => 'normal',
433 'priority' => 'high'
434 );
435 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
436 {
437 $meta_boxes[10] = array(
438 'id' => 'propertyhive-property-owner',
439 'title' => __( 'Property Owner / Landlord', 'propertyhive' ),
440 'callback' => 'PH_Meta_Box_Property_Owner::output',
441 'screen' => 'property',
442 'context' => 'normal',
443 'priority' => 'high'
444 );
445 }
446 $meta_boxes[15] = array(
447 'id' => 'propertyhive-property-record-details',
448 'title' => __( 'Record Details', 'propertyhive' ),
449 'callback' => 'PH_Meta_Box_Property_Record_Details::output',
450 'screen' => 'property',
451 'context' => 'normal',
452 'priority' => 'high'
453 );
454 $meta_boxes[20] = array(
455 'id' => 'propertyhive-property-coordinates',
456 'title' => __( 'Property Location', 'propertyhive' ),
457 'callback' => 'PH_Meta_Box_Property_Coordinates::output',
458 'screen' => 'property',
459 'context' => 'normal',
460 'priority' => 'high'
461 );
462
463 $meta_boxes = apply_filters( 'propertyhive_property_summary_meta_boxes', $meta_boxes );
464 ksort($meta_boxes);
465
466 $ids = array();
467 foreach ($meta_boxes as $meta_box)
468 {
469 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
470 $ids[] = $meta_box['id'];
471 }
472
473 $tabs['tab_summary'] = array(
474 'name' => __( 'Summary', 'propertyhive' ),
475 'metabox_ids' => $ids,
476 'post_type' => 'property'
477 );
478
479
480 /* PROPERTY DETAILS META BOXES */
481 $meta_boxes = array();
482 $meta_boxes[5] = array(
483 'id' => 'propertyhive-property-department',
484 'title' => __( 'Property Department', 'propertyhive' ),
485 'callback' => 'PH_Meta_Box_Property_Department::output',
486 'screen' => 'property',
487 'context' => 'normal',
488 'priority' => 'high'
489 );
490 $meta_boxes[10] = array(
491 'id' => 'propertyhive-property-residential-sales-details',
492 'title' => __( 'Residential Sales Details', 'propertyhive' ),
493 'callback' => 'PH_Meta_Box_Property_Residential_Sales_Details::output',
494 'screen' => 'property',
495 'context' => 'normal',
496 'priority' => 'high'
497 );
498 $meta_boxes[15] = array(
499 'id' => 'propertyhive-property-residential-lettings-details',
500 'title' => __( 'Residential Lettings Details', 'propertyhive' ),
501 'callback' => 'PH_Meta_Box_Property_Residential_Lettings_Details::output',
502 'screen' => 'property',
503 'context' => 'normal',
504 'priority' => 'high'
505 );
506 $meta_boxes[20] = array(
507 'id' => 'propertyhive-property-residential-details',
508 'title' => __( 'Residential Details', 'propertyhive' ),
509 'callback' => 'PH_Meta_Box_Property_Residential_Details::output',
510 'screen' => 'property',
511 'context' => 'normal',
512 'priority' => 'high'
513 );
514 $meta_boxes[25] = array(
515 'id' => 'propertyhive-property-commercial-details',
516 'title' => __( 'Commercial Details', 'propertyhive' ),
517 'callback' => 'PH_Meta_Box_Property_Commercial_Details::output',
518 'screen' => 'property',
519 'context' => 'normal',
520 'priority' => 'high'
521 );
522
523 $meta_boxes = apply_filters( 'propertyhive_property_details_meta_boxes', $meta_boxes );
524 ksort($meta_boxes);
525
526 $ids = array();
527 foreach ($meta_boxes as $meta_box)
528 {
529 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
530 $ids[] = $meta_box['id'];
531 }
532
533 $tabs['tab_details'] = array(
534 'name' => __( 'Details', 'propertyhive' ),
535 'metabox_ids' => $ids,
536 'post_type' => 'property'
537 );
538
539 if ( get_post_meta( $post->ID, '_department', TRUE ) == 'commercial' && isset($post->post_parent) && $post->post_parent == 0 )
540 {
541 $meta_boxes = array();
542 $meta_boxes[5] = array(
543 'id' => 'propertyhive-property-commercial-units',
544 'title' => __( 'Commercial Units', 'propertyhive' ),
545 'callback' => 'PH_Meta_Box_Property_Commercial_Units::output',
546 'screen' => 'property',
547 'context' => 'normal',
548 'priority' => 'high'
549 );
550
551 $meta_boxes = apply_filters( 'propertyhive_property_commercial_units_meta_boxes', $meta_boxes );
552 ksort($meta_boxes);
553
554 $ids = array();
555 foreach ($meta_boxes as $meta_box)
556 {
557 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
558 $ids[] = $meta_box['id'];
559 }
560
561 $tabs['tab_units'] = array(
562 'name' => __( 'Units', 'propertyhive' ),
563 'metabox_ids' => $ids,
564 'post_type' => 'property'
565 );
566 }
567
568 /* PROPERTY MARKETING META BOXES */
569 $meta_boxes = array();
570 $meta_boxes[5] = array(
571 'id' => 'propertyhive-property-marketing',
572 'title' => __( 'Property Marketing', 'propertyhive' ),
573 'callback' => 'PH_Meta_Box_Property_Marketing::output',
574 'screen' => 'property',
575 'context' => 'normal',
576 'priority' => 'high'
577 );
578 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
579 {
580 $meta_boxes[10] = array(
581 'id' => 'propertyhive-property-marketing-statistics',
582 'title' => __( 'Property Marketing Statistics', 'propertyhive' ),
583 'callback' => 'PH_Meta_Box_Property_Marketing_Statistics::output',
584 'screen' => 'property',
585 'context' => 'normal',
586 'priority' => 'high'
587 );
588 }
589
590 $meta_boxes = apply_filters( 'propertyhive_property_marketing_meta_boxes', $meta_boxes );
591 ksort($meta_boxes);
592
593 $ids = array();
594 foreach ($meta_boxes as $meta_box)
595 {
596 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
597 $ids[] = $meta_box['id'];
598 }
599
600 $tabs['tab_marketing'] = array(
601 'name' => __( 'Marketing', 'propertyhive' ),
602 'metabox_ids' => $ids,
603 'post_type' => 'property',
604 );
605 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
606 {
607 $tabs['tab_marketing']['ajax_actions'] = array( 'get_property_marketing_statistics_meta_box^' . wp_create_nonce( 'get_property_marketing_statistics_meta_box' ) . '^reload_marketing_statistics' );
608 }
609
610 /* PROPERTY DESCRIPTIONS META BOXES */
611 $meta_boxes = array();
612 $meta_boxes[5] = array(
613 'id' => 'propertyhive-property-features',
614 'title' => __( 'Property Features', 'propertyhive' ),
615 'callback' => 'PH_Meta_Box_Property_Features::output',
616 'screen' => 'property',
617 'context' => 'normal',
618 'priority' => 'high'
619 );
620 $meta_boxes[10] = array(
621 'id' => 'postexcerpt',
622 'title' => __( 'Property Summary Description', 'propertyhive' ),
623 'callback' => 'PH_Meta_Box_Property_Summary_Description::output',
624 'screen' => 'property',
625 'context' => 'normal',
626 'priority' => 'high'
627 );
628 $meta_boxes[15] = array(
629 'id' => 'propertyhive-property-rooms',
630 'title' => __( 'Property Rooms', 'propertyhive' ),
631 'callback' => 'PH_Meta_Box_Property_Rooms::output',
632 'screen' => 'property',
633 'context' => 'normal',
634 'priority' => 'high'
635 );
636 $meta_boxes[20] = array(
637 'id' => 'propertyhive-property-description',
638 'title' => __( 'Property Description', 'propertyhive' ),
639 'callback' => 'PH_Meta_Box_Property_Description::output',
640 'screen' => 'property',
641 'context' => 'normal',
642 'priority' => 'high'
643 );
644
645 $meta_boxes = apply_filters( 'propertyhive_property_descriptions_meta_boxes', $meta_boxes );
646 ksort($meta_boxes);
647
648 $ids = array();
649 foreach ($meta_boxes as $meta_box)
650 {
651 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
652 $ids[] = $meta_box['id'];
653 }
654
655 $tabs['tab_descriptions'] = array(
656 'name' => __( 'Descriptions', 'propertyhive' ),
657 'metabox_ids' => $ids,
658 'post_type' => 'property'
659 );
660
661 /* PROPERTY MEDIA META BOXES */
662 $meta_boxes = array();
663 $meta_boxes[5] = array(
664 'id' => 'propertyhive-property-photos',
665 'title' => __( 'Property Photos', 'propertyhive' ),
666 'callback' => 'PH_Meta_Box_Property_Photos::output',
667 'screen' => 'property',
668 'context' => 'normal',
669 'priority' => 'high'
670 );
671 $meta_boxes[10] = array(
672 'id' => 'propertyhive-property-floorplans',
673 'title' => __( 'Property Floorplans', 'propertyhive' ),
674 'callback' => 'PH_Meta_Box_Property_Floorplans::output',
675 'screen' => 'property',
676 'context' => 'normal',
677 'priority' => 'high'
678 );
679 $meta_boxes[15] = array(
680 'id' => 'propertyhive-property-brochures',
681 'title' => __( 'Property Brochures', 'propertyhive' ),
682 'callback' => 'PH_Meta_Box_Property_Brochures::output',
683 'screen' => 'property',
684 'context' => 'normal',
685 'priority' => 'high'
686 );
687 $meta_boxes[20] = array(
688 'id' => 'propertyhive-property-epcs',
689 'title' => __( 'Property EPCs', 'propertyhive' ),
690 'callback' => 'PH_Meta_Box_Property_Epcs::output',
691 'screen' => 'property',
692 'context' => 'normal',
693 'priority' => 'high'
694 );
695 $meta_boxes[25] = array(
696 'id' => 'propertyhive-property-virtual-tours',
697 'title' => __( 'Property Virtual Tours', 'propertyhive' ),
698 'callback' => 'PH_Meta_Box_Property_Virtual_Tours::output',
699 'screen' => 'property',
700 'context' => 'normal',
701 'priority' => 'high'
702 );
703
704 $meta_boxes = apply_filters( 'propertyhive_property_media_meta_boxes', $meta_boxes );
705 ksort($meta_boxes);
706
707 $ids = array();
708 foreach ($meta_boxes as $meta_box)
709 {
710 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
711 $ids[] = $meta_box['id'];
712 }
713
714 $tabs['tab_media'] = array(
715 'name' => __( 'Media', 'propertyhive' ),
716 'metabox_ids' => $ids,
717 'post_type' => 'property'
718 );
719
720 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
721 {
722 /* PROPERTY VIEWINGS META BOXES */
723 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
724 {
725 $meta_boxes = array();
726 $meta_boxes[5] = array(
727 'id' => 'propertyhive-property-viewings',
728 'title' => __( 'Viewings', 'propertyhive' ),
729 'callback' => 'PH_Meta_Box_Property_Viewings::output',
730 'screen' => 'property',
731 'context' => 'normal',
732 'priority' => 'high'
733 );
734
735 $meta_boxes = apply_filters( 'propertyhive_property_viewings_meta_boxes', $meta_boxes );
736 ksort($meta_boxes);
737
738 $ids = array();
739 foreach ($meta_boxes as $meta_box)
740 {
741 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
742 $ids[] = $meta_box['id'];
743 }
744
745 $tabs['tab_viewings'] = array(
746 'name' => __( 'Viewings', 'propertyhive' ),
747 'metabox_ids' => $ids,
748 'post_type' => 'property',
749 'ajax_actions' => array( 'get_property_viewings_meta_box^' . wp_create_nonce( 'get_property_viewings_meta_box' ) ),
750 );
751 }
752
753 if ( get_option('propertyhive_module_disabled_offers_sales', '') != 'yes' )
754 {
755 if ( get_post_meta( $post->ID, '_department', TRUE ) == 'residential-sales' )
756 {
757 /* PROPERTY OFFERS META BOXES */
758 $meta_boxes = array();
759 $meta_boxes[5] = array(
760 'id' => 'propertyhive-property-offers',
761 'title' => __( 'Offers', 'propertyhive' ),
762 'callback' => 'PH_Meta_Box_Property_Offers::output',
763 'screen' => 'property',
764 'context' => 'normal',
765 'priority' => 'high'
766 );
767
768 $meta_boxes = apply_filters( 'propertyhive_property_offers_meta_boxes', $meta_boxes );
769 ksort($meta_boxes);
770
771 $ids = array();
772 foreach ($meta_boxes as $meta_box)
773 {
774 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
775 $ids[] = $meta_box['id'];
776 }
777
778 $tabs['tab_offers'] = array(
779 'name' => __( 'Offers', 'propertyhive' ),
780 'metabox_ids' => $ids,
781 'post_type' => 'property',
782 'ajax_actions' => array( 'get_property_offers_meta_box^' . wp_create_nonce( 'get_property_offers_meta_box' ) ),
783 );
784
785 /* PROPERTY SALES META BOXES */
786 $meta_boxes = array();
787 $meta_boxes[5] = array(
788 'id' => 'propertyhive-property-sales',
789 'title' => __( 'Sales', 'propertyhive' ),
790 'callback' => 'PH_Meta_Box_Property_Sales::output',
791 'screen' => 'property',
792 'context' => 'normal',
793 'priority' => 'high'
794 );
795
796 $meta_boxes = apply_filters( 'propertyhive_property_sales_meta_boxes', $meta_boxes );
797 ksort($meta_boxes);
798
799 $ids = array();
800 foreach ($meta_boxes as $meta_box)
801 {
802 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
803 $ids[] = $meta_box['id'];
804 }
805
806 $tabs['tab_sales'] = array(
807 'name' => __( 'Sales', 'propertyhive' ),
808 'metabox_ids' => $ids,
809 'post_type' => 'property',
810 'ajax_actions' => array( 'get_property_sales_meta_box^' . wp_create_nonce( 'get_property_sales_meta_box' ) ),
811 );
812 }
813 }
814 }
815
816 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
817 {
818 if ( get_option('propertyhive_module_disabled_enquiries', '') != 'yes' )
819 {
820 /* PROPERTY ENQUIRIES META BOXES */
821 $meta_boxes = array();
822 $meta_boxes[5] = array(
823 'id' => 'propertyhive-property-enquiries',
824 'title' => __( 'Enquiries', 'propertyhive' ),
825 'callback' => 'PH_Meta_Box_Property_Enquiries::output',
826 'screen' => 'property',
827 'context' => 'normal',
828 'priority' => 'high'
829 );
830
831 $meta_boxes = apply_filters( 'propertyhive_property_enquiries_meta_boxes', $meta_boxes );
832 ksort($meta_boxes);
833
834 $ids = array();
835 foreach ($meta_boxes as $meta_box)
836 {
837 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
838 $ids[] = $meta_box['id'];
839 }
840
841 $tabs['tab_enquiries'] = array(
842 'name' => __( 'Enquiries', 'propertyhive' ),
843 'metabox_ids' => $ids,
844 'post_type' => 'property'
845 );
846 }
847 }
848
849 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
850 {
851 /* PROPERTY NOTES META BOXES */
852 $meta_boxes = array();
853 $meta_boxes[5] = array(
854 'id' => 'propertyhive-property-history-notes',
855 'title' => __( 'Property History &amp; Notes', 'propertyhive' ),
856 'callback' => 'PH_Meta_Box_Property_Notes::output',
857 'screen' => 'property',
858 'context' => 'normal',
859 'priority' => 'high'
860 );
861
862 $meta_boxes = apply_filters( 'propertyhive_property_notes_meta_boxes', $meta_boxes );
863 ksort($meta_boxes);
864
865 $ids = array();
866 foreach ($meta_boxes as $meta_box)
867 {
868 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
869 $ids[] = $meta_box['id'];
870 }
871
872 $tabs['tab_notes'] = array(
873 'name' => __( 'History &amp; Notes', 'propertyhive' ),
874 'metabox_ids' => $ids,
875 'post_type' => 'property'
876 );
877
878 add_meta_box( 'propertyhive-property-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Property_Actions::output', 'property', 'side' );
879 }
880
881 // CONTACT
882 $meta_boxes = array();
883
884 if ( $pagenow == 'post-new.php' && get_post_type($post->ID) == 'contact' )
885 {
886 $meta_boxes[1] = array(
887 'id' => 'propertyhive-contact-new-relationship',
888 'title' => __( 'Contact Type', 'propertyhive' ),
889 'callback' => 'PH_Meta_Box_Contact_New_Relationship::output',
890 'screen' => 'contact',
891 'context' => 'normal',
892 'priority' => 'high'
893 );
894 }
895
896 $meta_boxes[5] = array(
897 'id' => 'propertyhive-contact-correspondence-address',
898 'title' => __( 'Correspondence Address', 'propertyhive' ),
899 'callback' => 'PH_Meta_Box_Contact_Correspondence_Address::output',
900 'screen' => 'contact',
901 'context' => 'normal',
902 'priority' => 'high'
903 );
904 $meta_boxes[10] = array(
905 'id' => 'propertyhive-contact-contact-details',
906 'title' => __( 'Contact Details', 'propertyhive' ),
907 'callback' => 'PH_Meta_Box_Contact_Contact_Details::output',
908 'screen' => 'contact',
909 'context' => 'normal',
910 'priority' => 'high'
911 );
912
913 $meta_boxes = apply_filters( 'propertyhive_contact_details_meta_boxes', $meta_boxes );
914 ksort($meta_boxes);
915
916 $ids = array();
917 foreach ($meta_boxes as $meta_box)
918 {
919 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
920 $ids[] = $meta_box['id'];
921 }
922
923 $tabs['tab_contact_details'] = array(
924 'name' => __( 'Contact Details', 'propertyhive' ),
925 'metabox_ids' => $ids,
926 'post_type' => 'contact'
927 );
928
929 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'contact' )
930 {
931 add_meta_box( 'propertyhive-contact-relationships', __( 'Relationships', 'propertyhive' ), 'PH_Meta_Box_Contact_Relationships::output', 'contact', 'normal', 'high' );
932 $tabs['tab_contact_relationships'] = array(
933 'name' => __( 'Relationships', 'propertyhive' ),
934 'metabox_ids' => array('propertyhive-contact-relationships'),
935 'post_type' => 'contact'
936 );
937 }
938
939 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'contact' )
940 {
941 $show_viewings = false;
942 $show_offers = false;
943 $show_sales = false;
944
945 $contact_types = get_post_meta( $post->ID, '_contact_types', TRUE );
946 if ( is_array($contact_types) && in_array('applicant', $contact_types) )
947 {
948 $show_viewings = true;
949
950 $num_applicant_profiles = get_post_meta( $post->ID, '_applicant_profiles', TRUE );
951 if ( $num_applicant_profiles == '' )
952 {
953 $num_applicant_profiles = 0;
954 }
955
956 if ( $num_applicant_profiles > 0 )
957 {
958 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
959 {
960 $applicant_profile = get_post_meta( $post->ID, '_applicant_profile_' . $i, TRUE );
961
962 if ( isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-sales' )
963 {
964 $show_offers = true;
965 $show_sales = true;
966 }
967 }
968 }
969 }
970 else
971 {
972 $args = array(
973 'post_type' => 'viewing',
974 'posts_per_page' => 1,
975 'fields' => 'ids',
976 'meta_query' => array(
977 array(
978 'key' => '_applicant_contact_id',
979 'value' => $post->ID
980 )
981 )
982 );
983 $viewing_query = new WP_Query( $args );
984 if ($viewing_query->have_posts())
985 {
986 $show_viewings = true;
987 }
988 wp_reset_postdata();
989
990 $args = array(
991 'post_type' => 'offer',
992 'posts_per_page' => 1,
993 'fields' => 'ids',
994 'meta_query' => array(
995 array(
996 'key' => '_applicant_contact_id',
997 'value' => $post->ID
998 )
999 )
1000 );
1001 $offer_query = new WP_Query( $args );
1002 if ($offer_query->have_posts())
1003 {
1004 $show_offers = true;
1005 }
1006 wp_reset_postdata();
1007
1008 $args = array(
1009 'post_type' => 'sale',
1010 'posts_per_page' => 1,
1011 'fields' => 'ids',
1012 'meta_query' => array(
1013 array(
1014 'key' => '_applicant_contact_id',
1015 'value' => $post->ID
1016 )
1017 )
1018 );
1019 $sale_query = new WP_Query( $args );
1020 if ($sale_query->have_posts())
1021 {
1022 $show_sales = true;
1023 }
1024 wp_reset_postdata();
1025 }
1026
1027 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
1028 {
1029 if ( $show_viewings )
1030 {
1031 /* CONTACT VIEWINGS META BOXES */
1032 add_meta_box( 'propertyhive-contact-viewings', __( 'Viewings', 'propertyhive' ), 'PH_Meta_Box_Contact_Viewings::output', 'contact', 'normal', 'high' );
1033
1034 $tabs['tab_viewings'] = array(
1035 'name' => __( 'Viewings', 'propertyhive' ),
1036 'metabox_ids' => array('propertyhive-contact-viewings'),
1037 'post_type' => 'contact',
1038 'ajax_actions' => array( 'get_contact_viewings_meta_box^' . wp_create_nonce( 'get_contact_viewings_meta_box' ) ),
1039 );
1040 }
1041 }
1042
1043 if ( get_option('propertyhive_module_disabled_offers_sales', '') != 'yes' )
1044 {
1045 if ( $show_offers )
1046 {
1047 /* CONTACT OFFERS META BOXES */
1048 add_meta_box( 'propertyhive-contact-offers', __( 'Offers', 'propertyhive' ), 'PH_Meta_Box_Contact_Offers::output', 'contact', 'normal', 'high' );
1049
1050 $tabs['tab_offers'] = array(
1051 'name' => __( 'Offers', 'propertyhive' ),
1052 'metabox_ids' => array('propertyhive-contact-offers'),
1053 'post_type' => 'contact',
1054 'ajax_actions' => array( 'get_contact_offers_meta_box^' . wp_create_nonce( 'get_contact_offers_meta_box' ) ),
1055 );
1056 }
1057
1058 if ( $show_sales )
1059 {
1060 /* CONTACT SALES META BOXES */
1061 add_meta_box( 'propertyhive-contact-sales', __( 'Sales', 'propertyhive' ), 'PH_Meta_Box_Contact_Sales::output', 'contact', 'normal', 'high' );
1062
1063 $tabs['tab_sales'] = array(
1064 'name' => __( 'Sales', 'propertyhive' ),
1065 'metabox_ids' => array('propertyhive-contact-sales'),
1066 'post_type' => 'contact',
1067 'ajax_actions' => array( 'get_contact_sales_meta_box^' . wp_create_nonce( 'get_contact_sales_meta_box' ) ),
1068 );
1069 }
1070 }
1071 $meta_boxes = array();
1072 $meta_boxes[5] = array(
1073 'id' => 'propertyhive-contact-history-notes',
1074 'title' => __( 'Contact History &amp; Notes', 'propertyhive' ),
1075 'callback' => 'PH_Meta_Box_Contact_Notes::output',
1076 'screen' => 'contact',
1077 'context' => 'normal',
1078 'priority' => 'high'
1079 );
1080
1081 $meta_boxes = apply_filters( 'propertyhive_contact_notes_meta_boxes', $meta_boxes );
1082 ksort($meta_boxes);
1083
1084 $ids = array();
1085 foreach ($meta_boxes as $meta_box)
1086 {
1087 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1088 $ids[] = $meta_box['id'];
1089 }
1090
1091 $tabs['tab_notes'] = array(
1092 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1093 'metabox_ids' => $ids,
1094 'post_type' => 'contact'
1095 );
1096
1097 add_meta_box( 'propertyhive-contact-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Contact_Actions::output', 'contact', 'side' );
1098 }
1099
1100 // ENQUIRY
1101 add_meta_box( 'propertyhive-enquiry-record-details', __( 'Record Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_Record_details::output', 'enquiry', 'normal', 'high' );
1102 add_meta_box( 'propertyhive-enquiry-details', __( 'Enquiry Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_details::output', 'enquiry', 'normal', 'high' );
1103 $tabs['tab_enquiry_details'] = array(
1104 'name' => __( 'Details', 'propertyhive' ),
1105 'metabox_ids' => array('propertyhive-enquiry-record-details', 'propertyhive-enquiry-details'),
1106 'post_type' => 'enquiry'
1107 );
1108
1109 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'enquiry' )
1110 {
1111 $meta_boxes = array();
1112 $meta_boxes[5] = array(
1113 'id' => 'propertyhive-enquiry-history-notes',
1114 'title' => __( 'Enquiry History &amp; Notes', 'propertyhive' ),
1115 'callback' => 'PH_Meta_Box_Enquiry_Notes::output',
1116 'screen' => 'enquiry',
1117 'context' => 'normal',
1118 'priority' => 'high'
1119 );
1120
1121 $meta_boxes = apply_filters( 'propertyhive_enquiry_notes_meta_boxes', $meta_boxes );
1122 ksort($meta_boxes);
1123
1124 $ids = array();
1125 foreach ($meta_boxes as $meta_box)
1126 {
1127 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1128 $ids[] = $meta_box['id'];
1129 }
1130
1131 $tabs['tab_notes'] = array(
1132 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1133 'metabox_ids' => $ids,
1134 'post_type' => 'enquiry'
1135 );
1136 }
1137
1138 // APPRAISAL
1139 if (!isset($tabs)) $tabs = array();
1140
1141 /* APPRAISAL SUMMARY META BOXES */
1142 $meta_boxes = array();
1143 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'appraisal' )
1144 {
1145 $meta_boxes[5] = array(
1146 'id' => 'propertyhive-appraisal-details',
1147 'title' => __( 'Appraisal Details', 'propertyhive' ),
1148 'callback' => 'PH_Meta_Box_Appraisal_Details::output',
1149 'screen' => 'appraisal',
1150 'context' => 'normal',
1151 'priority' => 'high'
1152 );
1153 }
1154 $meta_boxes[10] = array(
1155 'id' => 'propertyhive-appraisal-event',
1156 'title' => __( 'Event Details', 'propertyhive' ),
1157 'callback' => 'PH_Meta_Box_Appraisal_Event::output',
1158 'screen' => 'appraisal',
1159 'context' => 'normal',
1160 'priority' => 'high'
1161 );
1162 $meta_boxes[15] = array(
1163 'id' => 'propertyhive-appraisal-property-owner',
1164 'title' => __( 'Property Owner Details', 'propertyhive' ),
1165 'callback' => 'PH_Meta_Box_Appraisal_Property_Owner::output',
1166 'screen' => 'appraisal',
1167 'context' => 'normal',
1168 'priority' => 'high'
1169 );
1170 $meta_boxes[20] = array(
1171 'id' => 'propertyhive-appraisal-property',
1172 'title' => __( 'Property Details', 'propertyhive' ),
1173 'callback' => 'PH_Meta_Box_Appraisal_Property::output',
1174 'screen' => 'appraisal',
1175 'context' => 'normal',
1176 'priority' => 'high'
1177 );
1178
1179 $meta_boxes = apply_filters( 'propertyhive_appraisal_summary_meta_boxes', $meta_boxes );
1180 ksort($meta_boxes);
1181
1182 $ids = array();
1183 foreach ($meta_boxes as $meta_box)
1184 {
1185 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1186 $ids[] = $meta_box['id'];
1187 }
1188
1189 $tabs['tab_appraisal_summary'] = array(
1190 'name' => __( 'Summary', 'propertyhive' ),
1191 'metabox_ids' => $ids,
1192 'post_type' => 'appraisal'
1193 );
1194
1195 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'appraisal' )
1196 {
1197 $meta_boxes = array();
1198 $meta_boxes[5] = array(
1199 'id' => 'propertyhive-appraisal-history-notes',
1200 'title' => __( 'Appraisal History &amp; Notes', 'propertyhive' ),
1201 'callback' => 'PH_Meta_Box_Appraisal_Notes::output',
1202 'screen' => 'appraisal',
1203 'context' => 'normal',
1204 'priority' => 'high'
1205 );
1206
1207 $meta_boxes = apply_filters( 'propertyhive_appraisal_notes_meta_boxes', $meta_boxes );
1208 ksort($meta_boxes);
1209
1210 $ids = array();
1211 foreach ($meta_boxes as $meta_box)
1212 {
1213 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1214 $ids[] = $meta_box['id'];
1215 }
1216
1217 $tabs['tab_notes'] = array(
1218 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1219 'metabox_ids' => $ids,
1220 'post_type' => 'appraisal'
1221 );
1222
1223 add_meta_box( 'propertyhive-appraisal-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Appraisal_Actions::output', 'appraisal', 'side' );
1224 }
1225
1226 // VIEWING
1227 if (!isset($tabs)) $tabs = array();
1228
1229 /* VIEWING SUMMARY META BOXES */
1230 $meta_boxes = array();
1231 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1232 {
1233 $meta_boxes[5] = array(
1234 'id' => 'propertyhive-viewing-details',
1235 'title' => __( 'Viewing Details', 'propertyhive' ),
1236 'callback' => 'PH_Meta_Box_Viewing_Details::output',
1237 'screen' => 'viewing',
1238 'context' => 'normal',
1239 'priority' => 'high'
1240 );
1241 }
1242 $meta_boxes[10] = array(
1243 'id' => 'propertyhive-viewing-event',
1244 'title' => __( 'Event Details', 'propertyhive' ),
1245 'callback' => 'PH_Meta_Box_Viewing_Event::output',
1246 'screen' => 'viewing',
1247 'context' => 'normal',
1248 'priority' => 'high'
1249 );
1250 $meta_boxes[15] = array(
1251 'id' => 'propertyhive-viewing-applicant',
1252 'title' => __( 'Applicant Details', 'propertyhive' ),
1253 'callback' => 'PH_Meta_Box_Viewing_Applicant::output',
1254 'screen' => 'viewing',
1255 'context' => 'normal',
1256 'priority' => 'high'
1257 );
1258 $meta_boxes[20] = array(
1259 'id' => 'propertyhive-viewing-property',
1260 'title' => __( 'Property Details', 'propertyhive' ),
1261 'callback' => 'PH_Meta_Box_Viewing_Property::output',
1262 'screen' => 'viewing',
1263 'context' => 'normal',
1264 'priority' => 'high'
1265 );
1266
1267 $meta_boxes = apply_filters( 'propertyhive_viewing_summary_meta_boxes', $meta_boxes );
1268 ksort($meta_boxes);
1269
1270 $ids = array();
1271 foreach ($meta_boxes as $meta_box)
1272 {
1273 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1274 $ids[] = $meta_box['id'];
1275 }
1276
1277 $tabs['tab_viewing_summary'] = array(
1278 'name' => __( 'Summary', 'propertyhive' ),
1279 'metabox_ids' => $ids,
1280 'post_type' => 'viewing'
1281 );
1282
1283 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1284 {
1285 $meta_boxes = array();
1286 $meta_boxes[5] = array(
1287 'id' => 'propertyhive-viewing-history-notes',
1288 'title' => __( 'Viewing History &amp; Notes', 'propertyhive' ),
1289 'callback' => 'PH_Meta_Box_Viewing_Notes::output',
1290 'screen' => 'viewing',
1291 'context' => 'normal',
1292 'priority' => 'high'
1293 );
1294
1295 $meta_boxes = apply_filters( 'propertyhive_viewing_notes_meta_boxes', $meta_boxes );
1296 ksort($meta_boxes);
1297
1298 $ids = array();
1299 foreach ($meta_boxes as $meta_box)
1300 {
1301 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1302 $ids[] = $meta_box['id'];
1303 }
1304
1305 $tabs['tab_notes'] = array(
1306 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1307 'metabox_ids' => $ids,
1308 'post_type' => 'viewing'
1309 );
1310
1311 add_meta_box( 'propertyhive-viewing-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Viewing_Actions::output', 'viewing', 'side' );
1312 }
1313
1314 // OFFER
1315 if (!isset($tabs)) $tabs = array();
1316
1317 /* OFFER SUMMARY META BOXES */
1318 $meta_boxes = array();
1319 $meta_boxes[5] = array(
1320 'id' => 'propertyhive-offer-details',
1321 'title' => __( 'Offer Details', 'propertyhive' ),
1322 'callback' => 'PH_Meta_Box_Offer_Details::output',
1323 'screen' => 'offer',
1324 'context' => 'normal',
1325 'priority' => 'high'
1326 );
1327 $meta_boxes[10] = array(
1328 'id' => 'propertyhive-offer-property',
1329 'title' => __( 'Property Details', 'propertyhive' ),
1330 'callback' => 'PH_Meta_Box_Offer_Property::output',
1331 'screen' => 'offer',
1332 'context' => 'normal',
1333 'priority' => 'high'
1334 );
1335 $meta_boxes[15] = array(
1336 'id' => 'propertyhive-offer-property-owner-solicitor',
1337 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1338 'callback' => 'PH_Meta_Box_Offer_Property_Owner_Solicitor::output',
1339 'screen' => 'offer',
1340 'context' => 'normal',
1341 'priority' => 'high'
1342 );
1343 $meta_boxes[20] = array(
1344 'id' => 'propertyhive-offer-applicant',
1345 'title' => __( 'Applicant Details', 'propertyhive' ),
1346 'callback' => 'PH_Meta_Box_Offer_Applicant::output',
1347 'screen' => 'offer',
1348 'context' => 'normal',
1349 'priority' => 'high'
1350 );
1351 $meta_boxes[25] = array(
1352 'id' => 'propertyhive-offer-applicant-solicitor',
1353 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1354 'callback' => 'PH_Meta_Box_Offer_Applicant_Solicitor::output',
1355 'screen' => 'offer',
1356 'context' => 'normal',
1357 'priority' => 'high'
1358 );
1359
1360
1361 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1362 ksort($meta_boxes);
1363
1364 $ids = array();
1365 foreach ($meta_boxes as $meta_box)
1366 {
1367 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1368 $ids[] = $meta_box['id'];
1369 }
1370
1371 $tabs['tab_offer_summary'] = array(
1372 'name' => __( 'Summary', 'propertyhive' ),
1373 'metabox_ids' => $ids,
1374 'post_type' => 'offer'
1375 );
1376
1377 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'offer' )
1378 {
1379 $meta_boxes = array();
1380 $meta_boxes[5] = array(
1381 'id' => 'propertyhive-offer-history-notes',
1382 'title' => __( 'Offer History &amp; Notes', 'propertyhive' ),
1383 'callback' => 'PH_Meta_Box_Offer_Notes::output',
1384 'screen' => 'offer',
1385 'context' => 'normal',
1386 'priority' => 'high'
1387 );
1388
1389 $meta_boxes = apply_filters( 'propertyhive_offer_notes_meta_boxes', $meta_boxes );
1390 ksort($meta_boxes);
1391
1392 $ids = array();
1393 foreach ($meta_boxes as $meta_box)
1394 {
1395 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1396 $ids[] = $meta_box['id'];
1397 }
1398
1399 $tabs['tab_notes'] = array(
1400 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1401 'metabox_ids' => $ids,
1402 'post_type' => 'offer'
1403 );
1404
1405 add_meta_box( 'propertyhive-offer-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Offer_Actions::output', 'offer', 'side' );
1406 }
1407
1408 // SALE
1409 if (!isset($tabs)) $tabs = array();
1410
1411 /* SALE SUMMARY META BOXES */
1412 $meta_boxes = array();
1413 $meta_boxes[5] = array(
1414 'id' => 'propertyhive-sale-details',
1415 'title' => __( 'Sale Details', 'propertyhive' ),
1416 'callback' => 'PH_Meta_Box_Sale_Details::output',
1417 'screen' => 'sale',
1418 'context' => 'normal',
1419 'priority' => 'high'
1420 );
1421 $meta_boxes[10] = array(
1422 'id' => 'propertyhive-sale-property',
1423 'title' => __( 'Property Details', 'propertyhive' ),
1424 'callback' => 'PH_Meta_Box_Sale_Property::output',
1425 'screen' => 'sale',
1426 'context' => 'normal',
1427 'priority' => 'high'
1428 );
1429 $meta_boxes[15] = array(
1430 'id' => 'propertyhive-sale-property-owner-solicitor',
1431 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1432 'callback' => 'PH_Meta_Box_Sale_Property_Owner_Solicitor::output',
1433 'screen' => 'sale',
1434 'context' => 'normal',
1435 'priority' => 'high'
1436 );
1437 $meta_boxes[20] = array(
1438 'id' => 'propertyhive-sale-applicant',
1439 'title' => __( 'Applicant Details', 'propertyhive' ),
1440 'callback' => 'PH_Meta_Box_Sale_Applicant::output',
1441 'screen' => 'sale',
1442 'context' => 'normal',
1443 'priority' => 'high'
1444 );
1445 $meta_boxes[25] = array(
1446 'id' => 'propertyhive-sale-applicant-solicitor',
1447 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1448 'callback' => 'PH_Meta_Box_Sale_Applicant_Solicitor::output',
1449 'screen' => 'sale',
1450 'context' => 'normal',
1451 'priority' => 'high'
1452 );
1453
1454
1455 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1456 ksort($meta_boxes);
1457
1458 $ids = array();
1459 foreach ($meta_boxes as $meta_box)
1460 {
1461 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1462 $ids[] = $meta_box['id'];
1463 }
1464
1465 $tabs['tab_sale_summary'] = array(
1466 'name' => __( 'Summary', 'propertyhive' ),
1467 'metabox_ids' => $ids,
1468 'post_type' => 'sale'
1469 );
1470
1471 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'sale' )
1472 {
1473 $meta_boxes = array();
1474 $meta_boxes[5] = array(
1475 'id' => 'propertyhive-sale-history-notes',
1476 'title' => __( 'Sale History &amp; Notes', 'propertyhive' ),
1477 'callback' => 'PH_Meta_Box_Sale_Notes::output',
1478 'screen' => 'sale',
1479 'context' => 'normal',
1480 'priority' => 'high'
1481 );
1482
1483 $meta_boxes = apply_filters( 'propertyhive_sale_notes_meta_boxes', $meta_boxes );
1484 ksort($meta_boxes);
1485
1486 $ids = array();
1487 foreach ($meta_boxes as $meta_box)
1488 {
1489 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1490 $ids[] = $meta_box['id'];
1491 }
1492
1493 $tabs['tab_notes'] = array(
1494 'name' => __( 'History &amp; Notes', 'propertyhive' ),
1495 'metabox_ids' => $ids,
1496 'post_type' => 'sale'
1497 );
1498
1499 add_meta_box( 'propertyhive-sale-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Sale_Actions::output', 'sale', 'side' );
1500 }
1501
1502 $tabs = apply_filters( 'propertyhive_tabs', $tabs );
1503
1504 // Force order of meta boxes
1505 $meta_box_ids = array();
1506 if (
1507 in_array(
1508 get_post_type($post->ID),
1509 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'viewing', 'offer', 'sale') )
1510 )
1511 )
1512 {
1513 foreach ( $tabs as $tab_id => $tab_options)
1514 {
1515 if ( isset($tab_options['post_type']) && $tab_options['post_type'] == get_post_type($post->ID) )
1516 {
1517 $meta_box_ids = array_merge( $meta_box_ids, $tab_options['metabox_ids'] );
1518 }
1519 }
1520 }
1521
1522 if (!empty($meta_box_ids) )
1523 {
1524 $existing_meta_box_order = get_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), TRUE );
1525 if ( $existing_meta_box_order == '' )
1526 {
1527 $existing_meta_box_order = array();
1528 $existing_meta_box_order['side'] = '';
1529 $existing_meta_box_order['advanced'] = '';
1530 }
1531 $existing_meta_box_order['normal'] = implode(",", $meta_box_ids);
1532
1533 update_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), $existing_meta_box_order );
1534 }
1535
1536 // TO DO: move this so it works when in one column
1537 add_action( 'edit_form_after_title', array( $this, 'draw_meta_box_tabs' ), 31, 1);
1538 }
1539
1540 /**
1541 * Draw meta box tabs
1542 */
1543 public function draw_meta_box_tabs() {
1544
1545 global $post, $tabs;
1546
1547 if (
1548 !empty($tabs) &&
1549 in_array(
1550 $post->post_type,
1551 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'appraisal', 'viewing', 'offer', 'sale') )
1552 )
1553 )
1554 {
1555 $meta_boxes_under_tabs = array();
1556
1557 $i = 0;
1558 echo '<div id="propertyhive_metabox_tabs" style="margin-top:15px">';
1559 foreach ($tabs as $tab_id => $tab)
1560 {
1561 if (isset($tab['post_type']) && $post->post_type == $tab['post_type'])
1562 {
1563 echo '<a href="#' . implode("|#", $tab['metabox_ids']) . '" id="' . $tab_id . '" class="button' . ( ($i == 0) ? ' button-primary' : '') . '"';
1564 if ( isset($tab['ajax_actions']) )
1565 {
1566 echo ' data-ajax-actions="' . esc_attr(implode("|", $tab['ajax_actions'])) . '"';
1567 }
1568 echo '>' . $tab['name'] . '</a> ';
1569
1570 $meta_boxes_under_tabs[] = $tab['metabox_ids'];
1571
1572 ++$i;
1573 }
1574 }
1575 echo '</div><br>';
1576
1577 // hidden field to keep track of selected hash
1578 echo '<input type="hidden" name="propertyhive_selected_metabox_tab" id="propertyhive_selected_metabox_tab" value="">';
1579
1580 if (!empty($meta_boxes_under_tabs))
1581 {
1582 echo '
1583 <script>
1584 var meta_boxes_under_tabs = ' . json_encode($meta_boxes_under_tabs) . ';
1585
1586 var ajax_actions_executed = new Array();
1587
1588 jQuery(document).ready(function()
1589 {
1590 // Hide all on page load
1591 hide_meta_box_tabs();
1592
1593 // Show first meta box
1594 //jQuery(\'#\' + meta_boxes_under_tabs[0][0] + \'\').show();
1595 for (var i in meta_boxes_under_tabs[0])
1596 {
1597 jQuery(\'#\' + meta_boxes_under_tabs[0][i] + \'\').show();
1598 }
1599 //jQuery(\'#propertyhive_metabox_tabs a:first-child\').trigger(\'click\');
1600
1601 // Set first button as primary
1602 jQuery(\'#propertyhive_metabox_tabs a:first-child\').addClass(\'button-primary\');
1603
1604 // Hide meta boxes and show correct one when tab clicked
1605 jQuery(\'#propertyhive_metabox_tabs a\').click(function(e)
1606 {
1607 e.preventDefault();
1608
1609 hide_meta_box_tabs();
1610
1611 var this_href = jQuery(this).attr(\'href\').split(\'|\');
1612
1613 for (var i in this_href)
1614 {
1615 jQuery(this_href[i]).show();
1616 }
1617
1618 jQuery(this).addClass(\'button-primary\');
1619
1620 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_details\') { showHideDepartmentMetaBox(); }' : '' ) . '
1621 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideRoomsMetaBox(); }' : '' ) . '
1622 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideDescriptionsMetaBox(); }' : '' ) . '
1623
1624 if ( jQuery(this).attr(\'data-ajax-actions\') && jQuery(this).attr(\'data-ajax-actions\') != \'\' )
1625 {
1626 var ajax_actions = jQuery(this).attr(\'data-ajax-actions\').split(\'|\');
1627
1628 for ( var i in ajax_actions )
1629 {
1630 var ajax_action = ajax_actions[i].split(\'^\');
1631
1632 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(\'Loading...\');
1633
1634 if ( ajax_action[2] ) // callback
1635 {
1636 eval(ajax_action[2] + \'()\');
1637 }
1638 else
1639 {
1640 var data = {
1641 action: \'propertyhive_\' + ajax_action[0],
1642 post_id: ' . $post->ID . ',
1643 security: ajax_action[1]
1644 }
1645
1646 jQuery.post( \'' . admin_url('admin-ajax.php') . '\', data, function(response)
1647 {
1648 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(response);
1649 activateTipTip();
1650 }, \'html\');
1651 }
1652 }
1653 }
1654
1655 //window.location.hash = jQuery(this).attr(\'href\');
1656 history.pushState({}, \'\', \'#\' + jQuery(this).attr(\'href\').replace(/#/g, \'\').replace(/\|/g, \'%7C\'));
1657
1658 jQuery(\'#propertyhive_selected_metabox_tab\').val(jQuery(this).attr(\'href\').replace(/#/g, \'\').replace(/\|/g, \'%7C\'));
1659
1660 return false;
1661 });
1662
1663 // Set default tab if hash set
1664 if (window.location.hash != \'\')
1665 {
1666 var hash = window.location.hash;
1667 if ( window.location.hash.indexOf(\'%7C\') )
1668 {
1669 hash = window.location.hash.replace(/%7C/g, \'|#\');
1670 }
1671 jQuery("#propertyhive_metabox_tabs a[href=\'" + hash + "\']").trigger(\'click\');
1672 }
1673 });
1674
1675 function hide_meta_box_tabs()
1676 {
1677 for (var i in meta_boxes_under_tabs)
1678 {
1679 for (var j in meta_boxes_under_tabs[i])
1680 {
1681 jQuery(\'#\' + meta_boxes_under_tabs[i][j] + \'\').hide();
1682 }
1683 }
1684
1685 jQuery(\'#propertyhive_metabox_tabs a\').removeClass(\'button-primary\');
1686 }
1687 </script>
1688 ';
1689 }
1690 }
1691
1692 }
1693
1694 /**
1695 * Remove bloat
1696 */
1697 public function remove_meta_boxes() {
1698 //remove_meta_box( 'submitdiv', 'property', 'side' );
1699 remove_meta_box( 'postexcerpt', 'property', 'normal' );
1700 remove_meta_box( 'pageparentdiv', 'property', 'side' );
1701 remove_meta_box( 'commentstatusdiv', 'property', 'normal' );
1702 remove_meta_box( 'commentstatusdiv', 'property', 'side' );
1703 remove_meta_box( 'commentsdiv', 'product', 'normal' );
1704 }
1705
1706 /**
1707 * Rename core meta boxes
1708 */
1709 public function rename_meta_boxes() {
1710 global $post;
1711
1712 // Comments/Reviews
1713 if ( isset( $post ) && ( 'publish' == $post->post_status || 'private' == $post->post_status ) ) {
1714 //remove_meta_box( 'commentsdiv', 'product', 'normal' );
1715
1716 //add_meta_box( 'commentsdiv', __( 'Reviews', 'propertyhive' ), 'post_comment_meta_box', 'product', 'normal' );
1717 }
1718 }
1719
1720 /**
1721 * Check if we're saving, then trigger an action based on the post type
1722 *
1723 * @param int $post_id
1724 * @param object $post
1725 */
1726 public function save_meta_boxes( $post_id, $post ) {
1727 // $post_id and $post are required
1728 if ( empty( $post_id ) || empty( $post ) ) {
1729 return;
1730 }
1731
1732 // Dont' save meta boxes for revisions or autosaves
1733 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
1734 return;
1735 }
1736
1737 // Check the nonce
1738 if ( empty( $_POST['propertyhive_meta_nonce'] ) || ! wp_verify_nonce( $_POST['propertyhive_meta_nonce'], 'propertyhive_save_data' ) ) {
1739 return;
1740 }
1741
1742 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events
1743 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
1744 return;
1745 }
1746
1747 // Check user has permission to edit
1748 if ( ! current_user_can( 'edit_post', $post_id ) ) {
1749 return;
1750 }
1751
1752 // Check the post type
1753 if (
1754 ! in_array(
1755 $post->post_type,
1756 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'appraisal', 'viewing', 'offer', 'sale') )
1757 )
1758 ) {
1759 return;
1760 }
1761
1762 if ( isset($_POST['post_parent']) && $_POST['post_parent'] != '' && $_POST['post_parent'] != '0' )
1763 {
1764 global $wpdb;
1765
1766 $wpdb->update( $wpdb->posts, array( 'post_parent' => (int)$_POST['post_parent'] ), array( 'ID' => $post_id ) );
1767 }
1768
1769 do_action( 'propertyhive_process_' . $post->post_type . '_meta', $post_id, $post );
1770 }
1771
1772 }
1773
1774 new PH_Admin_Meta_Boxes();
1775
1776 }