PluginProbe
Property Hive / 1.4.51
Property Hive v1.4.51
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 / class-ph-admin-post-types.php

class-ph-admin-post-types.php in Property Hive 1.4.51, at includes/admin/class-ph-admin-post-types.php

1,256 lines 44.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Types Admin
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! class_exists( 'PH_Admin_Post_Types' ) ) :
14
15 /**
16 * PH_Admin_Post_Types Class
17 */
18 class PH_Admin_Post_Types {
19
20 /**
21 * Constructor
22 */
23 public function __construct() {
24 add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
25 add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
26 add_action( 'admin_print_scripts', array( $this, 'remove_month_filter' ) );
27 add_action( 'admin_print_scripts', array( $this, 'disable_autosave' ) );
28
29 // Filters
30 add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
31 add_filter( 'request', array( $this, 'request_query' ) );
32
33 // Status transitions
34 add_action( 'delete_post', array( $this, 'delete_post' ) );
35 add_action( 'wp_trash_post', array( $this, 'trash_post' ) );
36 add_action( 'untrash_post', array( $this, 'untrash_post' ) );
37
38
39 }
40
41 /**
42 * Conditonally load classes and functions only needed when viewing a post type.
43 */
44 public function include_post_type_handlers() {
45 include( 'post-types/class-ph-admin-header-stripes.php' );
46 include( 'post-types/class-ph-admin-meta-boxes.php' );
47
48 include( 'post-types/class-ph-admin-cpt-property.php' );
49 include( 'post-types/class-ph-admin-cpt-contact.php' );
50 include( 'post-types/class-ph-admin-cpt-enquiry.php' );
51 include( 'post-types/class-ph-admin-cpt-office.php' );
52 include( 'post-types/class-ph-admin-cpt-appraisal.php' );
53 include( 'post-types/class-ph-admin-cpt-viewing.php' );
54 include( 'post-types/class-ph-admin-cpt-offer.php' );
55 include( 'post-types/class-ph-admin-cpt-sale.php' );
56 }
57
58 /**
59 * Change messages when a post type is updated.
60 *
61 * @param array $messages
62 * @return array
63 */
64 public function post_updated_messages( $messages ) {
65 global $post, $post_ID;
66
67 $messages['property'] = array(
68 0 => '', // Unused. Messages start at index 1.
69 1 => sprintf( __( 'Property updated. <a href="%s">View Property</a>', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ),
70 2 => __( 'Custom field updated.', 'propertyhive' ),
71 3 => __( 'Custom field deleted.', 'propertyhive' ),
72 4 => __( 'Property updated.', 'propertyhive' ),
73 5 => isset($_GET['revision']) ? sprintf( __( 'Property restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
74 6 => sprintf( __( 'Property published. <a href="%s">View Property</a>', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ),
75 7 => __( 'Property saved.', 'propertyhive' ),
76 8 => sprintf( __( 'Property submitted. <a target="_blank" href="%s">Preview Property</a>', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
77 9 => sprintf( __( 'Property scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Property</a>', 'propertyhive' ),
78 date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
79 10 => sprintf( __( 'Property draft updated. <a target="_blank" href="%s">Preview Property</a>', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
80 );
81
82 $messages['contact'] = array(
83 0 => '', // Unused. Messages start at index 1.
84 1 => __( 'Contact updated.', 'propertyhive' ),
85 2 => __( 'Custom field updated.', 'propertyhive' ),
86 3 => __( 'Custom field deleted.', 'propertyhive' ),
87 4 => __( 'Contact updated.', 'propertyhive' ),
88 5 => isset($_GET['revision']) ? sprintf( __( 'Contact restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
89 6 => __( 'Contact published.', 'propertyhive' ),
90 7 => __( 'Contact saved.', 'propertyhive' ),
91 8 => __( 'Contact submitted.', 'propertyhive' ),
92 9 => sprintf( __( 'Contact scheduled for: <strong>%1$s</strong>.', 'propertyhive' ), date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) )),
93 10 => __( 'Contact draft updated.', 'propertyhive' ),
94 );
95
96 $messages['office'] = array(
97 0 => '', // Unused. Messages start at index 1.
98 1 => __( 'Office updated.', 'propertyhive' ),
99 2 => __( 'Custom field updated.', 'propertyhive' ),
100 3 => __( 'Custom field deleted.', 'propertyhive' ),
101 4 => __( 'Office updated.', 'propertyhive' ),
102 5 => isset($_GET['revision']) ? sprintf( __( 'Office restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
103 6 => sprintf( __( 'Office published.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ),
104 7 => __( 'Office saved.', 'propertyhive' ),
105 8 => sprintf( __( 'Office submitted.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
106 9 => sprintf( __( 'Office scheduled for: <strong>%1$s</strong>.', 'propertyhive' ),
107 date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
108 10 => sprintf( __( 'Office draft updated. ', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
109 );
110
111 $messages['enquiry'] = array(
112 0 => '', // Unused. Messages start at index 1.
113 1 => sprintf( __( 'Enquiry updated.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ),
114 2 => __( 'Custom field updated.', 'propertyhive' ),
115 3 => __( 'Custom field deleted.', 'propertyhive' ),
116 4 => __( 'Enquiry updated.', 'propertyhive' ),
117 5 => isset($_GET['revision']) ? sprintf( __( 'Enquiry restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
118 6 => sprintf( __( 'Enquiry published.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ),
119 7 => __( 'Enquiry saved.', 'propertyhive' ),
120 8 => sprintf( __( 'Enquiry submitted.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
121 9 => sprintf( __( 'Enquiry scheduled for: <strong>%1$s</strong>.', 'propertyhive' ),
122 date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
123 10 => sprintf( __( 'Enquiry draft updated.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
124 );
125
126 return $messages;
127 }
128
129 /**
130 * Remove month filter from some property hive pages
131 */
132 public function remove_month_filter() {
133 global $typenow;
134
135 if ($typenow == 'property' || $typenow == 'contact' || $typenow == 'appraisal' || $typenow == 'viewing' || $typenow == 'offer' || $typenow == 'sale')
136 {
137 add_filter('months_dropdown_results', '__return_empty_array');
138 }
139 }
140
141 /**
142 * Disable the auto-save functionality for certain CPT's.
143 *
144 * @access public
145 * @return void
146 */
147 public function disable_autosave(){
148 /*global $post;
149
150 if ( $post && get_post_type( $post->ID ) === 'enquiry' ) {
151 wp_dequeue_script( 'autosave' );
152 }*/
153 }
154
155 /**
156 * Filters for post types
157 */
158 public function restrict_manage_posts() {
159 global $typenow, $wp_query;
160
161 switch ( $typenow ) {
162 case 'property' :
163 $this->property_filters();
164 break;
165 case 'contact' :
166 $this->contact_filters();
167 break;
168 case 'enquiry' :
169 $this->enquiry_filters();
170 break;
171 case 'appraisal' :
172 $this->appraisal_filters();
173 break;
174 case 'viewing' :
175 $this->viewing_filters();
176 break;
177 case 'offer' :
178 $this->offer_filters();
179 break;
180 case 'sale' :
181 $this->sale_filters();
182 break;
183 default :
184 break;
185 }
186 }
187
188 /**
189 * Show a property filter box
190 */
191 public function property_filters() {
192 global $wp_query;
193
194 // Department filtering
195 $output = '';
196
197 $output .= $this->property_department_filter();
198 $output .= $this->property_marketing_filter();
199 $output .= $this->property_availability_filter();
200 $output .= $this->property_location_filter();
201 $output .= $this->property_office_filter();
202 $output .= $this->property_negotiator_filter();
203
204 echo apply_filters( 'propertyhive_property_filters', $output );
205 }
206
207 /**
208 * Show a property department filter box
209 */
210 public function property_department_filter() {
211 global $wp_query;
212
213 $departments = ph_get_departments();
214
215 $selected_department = isset( $_GET['_department'] ) && in_array( $_GET['_department'], array_keys($departments) ) ? $_GET['_department'] : '';
216
217 // Department filtering
218 $output = '<select name="_department" id="dropdown_property_department">';
219
220 $output .= '<option value="">' . __( 'All Departments', 'propertyhive' ) . '</option>';
221
222 foreach ( $departments as $key => $value )
223 {
224 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
225 {
226 $output .= '<option value="' . $key . '"';
227 $output .= selected( $key, $selected_department, false );
228 $output .= '>' . $value . '</option>';
229 }
230 }
231
232 $output .= '</select>';
233
234 return $output;
235 }
236
237 /**
238 * Show a property office filter box
239 */
240 public function property_office_filter() {
241 global $wp_query, $post;
242
243 // Department filtering
244 $output = '<select name="_office_id" id="dropdown_property_office_id">';
245
246 $output .= '<option value="">' . __( 'All Offices', 'propertyhive' ) . '</option>';
247
248 $args = array(
249 'post_type' => 'office',
250 'nopaging' => true,
251 'orderby' => 'title',
252 'order' => 'ASC'
253 );
254 $office_query = new WP_Query($args);
255
256 if ($office_query->have_posts())
257 {
258 while ($office_query->have_posts())
259 {
260 $office_query->the_post();
261
262 $output .= '<option value="' . $post->ID . '"';
263 if ( isset( $_GET['_office_id'] ) && ! empty( $_GET['_office_id'] ) )
264 {
265 $output .= selected( $post->ID, (int)$_GET['_office_id'], false );
266 }
267 $output .= '>' . get_the_title() . '</option>';
268 }
269 }
270
271 wp_reset_postdata();
272
273 $output .= '</select>';
274
275 return $output;
276 }
277
278 /**
279 * Show a property negotiator filter box
280 */
281 public function property_negotiator_filter() {
282 global $wp_query, $post;
283
284 $selected = '';
285 if ( isset( $_GET['_negotiator_id'] ) && ! empty( $_GET['_negotiator_id'] ) )
286 {
287 $selected = (int)$_GET['_negotiator_id'];
288 }
289
290 $args = array(
291 'name' => '_negotiator_id',
292 'id' => 'dropdown_property_negotiator_id',
293 'show_option_all' => __( 'All Negotiators', 'propertyhive' ),
294 'selected' => $selected,
295 'echo' => false,
296 'role__not_in' => array('property_hive_contact')
297 );
298 $output = wp_dropdown_users($args);
299
300 return $output;
301 }
302
303 /**
304 * Show a property location filter box
305 */
306 public function property_location_filter() {
307 global $wp_query, $post;
308
309 // Department filtering
310 $output = '<select name="_location_id" id="dropdown_property_location_id">';
311
312 $options = array( );
313 $args = array(
314 'hide_empty' => false,
315 'parent' => 0
316 );
317 $terms = get_terms( 'location', $args );
318
319 if ( !empty( $terms ) && !is_wp_error( $terms ) )
320 {
321 foreach ($terms as $term)
322 {
323 $options[$term->term_id] = $term->name;
324
325 $args = array(
326 'hide_empty' => false,
327 'parent' => $term->term_id
328 );
329 $subterms = get_terms( 'location', $args );
330
331 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
332 {
333 foreach ($subterms as $term)
334 {
335 $options[$term->term_id] = '- ' . $term->name;
336
337 $args = array(
338 'hide_empty' => false,
339 'parent' => $term->term_id
340 );
341 $subsubterms = get_terms( 'location', $args );
342
343 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
344 {
345 foreach ($subsubterms as $term)
346 {
347 $options[$term->term_id] = '- ' . $term->name;
348 }
349 }
350 }
351 }
352 }
353 }
354
355 $output .= '<option value="">' . __( 'All Locations', 'propertyhive' ) . '</option>';
356
357 if ( !empty($options) )
358 {
359 foreach ( $options as $value => $label )
360 {
361 $output .= '<option value="' . $value . '"';
362 if ( isset( $_GET['_location_id'] ) && ! empty( $_GET['_location_id'] ) )
363 {
364 $output .= selected( $value, (int)$_GET['_location_id'], false );
365 }
366 $output .= '>' . $label . '</option>';
367 }
368 }
369
370 $output .= '</select>';
371
372 return $output;
373 }
374
375 /**
376 * Show a property availability filter box
377 */
378 public function property_availability_filter() {
379 global $wp_query, $post;
380
381 // Availability filtering
382 $output = '<select name="_availability_id" id="dropdown_property_availability_id">';
383
384 $options = array( );
385 $args = array(
386 'hide_empty' => false,
387 'parent' => 0
388 );
389 $terms = get_terms( 'availability', $args );
390
391 if ( !empty( $terms ) && !is_wp_error( $terms ) )
392 {
393 foreach ($terms as $term)
394 {
395 $options[$term->term_id] = $term->name;
396 }
397 }
398
399 $output .= '<option value="">' . __( 'All Availabilities', 'propertyhive' ) . '</option>';
400
401 if ( !empty($options) )
402 {
403 foreach ( $options as $value => $label )
404 {
405 $output .= '<option value="' . $value . '"';
406 if ( isset( $_GET['_availability_id'] ) && ! empty( $_GET['_availability_id'] ) )
407 {
408 $output .= selected( $value, (int)$_GET['_availability_id'], false );
409 }
410 $output .= '>' . $label . '</option>';
411 }
412 }
413
414 $output .= '</select>';
415
416 return $output;
417 }
418
419 /**
420 * Show a property marketing filter box
421 */
422 public function property_marketing_filter() {
423 global $wp_query, $post;
424
425 // Availability filtering
426 $output = '<select name="_marketing" id="dropdown_property_marketing">';
427
428 $output .= '<option value="">' . __( 'All Marketing Statuses', 'propertyhive' ) . '</option>';
429
430 $options = array(
431 'on_market' => __( 'On Market Only', 'propertyhive' ),
432 'off_market' => __( 'Not On Market Only', 'propertyhive' ),
433 'featured' => __( 'Featured Only', 'propertyhive' ),
434 );
435
436 $args = array(
437 'hide_empty' => false,
438 'parent' => 0
439 );
440 $terms = get_terms( 'marketing_flag', $args );
441
442 if ( !empty( $terms ) && !is_wp_error( $terms ) )
443 {
444 foreach ($terms as $term)
445 {
446 $options['marketing_flag_' . $term->term_id] = __( 'Has Marketing Flag', 'propertyhive') . ' - ' . $term->name;
447 }
448 }
449
450 $options = apply_filters( 'propertyhive_property_filter_marketing_options', $options );
451
452 foreach ( $options as $key => $value )
453 {
454 $output .= '<option value="' . $key . '"';
455 if ( isset( $_GET['_marketing'] ) && ! empty( $_GET['_marketing'] ) )
456 {
457 $output .= selected( $key, sanitize_text_field($_GET['_marketing']), false );
458 }
459 $output .= '>' . $value . '</option>';
460 }
461
462 $output .= '</select>';
463
464 return $output;
465 }
466
467 /**
468 * Show a contact filter box
469 */
470 public function contact_filters() {
471 global $wp_query;
472
473 $selected_contact_type = isset( $_GET['_contact_type'] ) && in_array( $_GET['_contact_type'], array( 'owner', 'potentialowner', 'applicant', 'hotapplicant', 'thirdparty' ) ) ? $_GET['_contact_type'] : '';
474
475 // Type filtering
476 $options = array();
477
478 // Owners
479 $option = '<option value="owner"';
480 $option .= selected( 'owner', $selected_contact_type, false );
481 $option .= '>' . __( 'Owners and Landlords', 'propertyhive' ) . '</option>';
482
483 $options[] = $option;
484
485 // Potential Owners
486 $option = '<option value="potentialowner"';
487 $option .= selected( 'potentialowner', $selected_contact_type, false );
488 $option .= '>' . __( 'Potential Owners and Landlords', 'propertyhive' ) . '</option>';
489
490 $options[] = $option;
491
492 // Applicants
493 $option = '<option value="applicant"';
494 $option .= selected( 'applicant', $selected_contact_type, false );
495 $option .= '>' . __( 'Applicants', 'propertyhive' ) . '</option>';
496
497 $options[] = $option;
498
499 // Hot Applicants
500 $option = '<option value="hotapplicant"';
501 $option .= selected( 'hotapplicant', $selected_contact_type, false );
502 $option .= '>- ' . __( 'Hot Applicants', 'propertyhive' ) . '</option>';
503
504 $options[] = $option;
505
506 // Third Parties
507 $option = '<option value="thirdparty"';
508 $option .= selected( 'thirdparty', $selected_contact_type, false );
509 $option .= '>' . __( 'Third Party Contacts', 'propertyhive' ) . '</option>';
510
511 $options[] = $option;
512
513 $options = apply_filters( 'propertyhive_contact_filter_options', $options );
514
515 $output = '';
516 if (count($options) > 1)
517 {
518 $output = '<select name="_contact_type" id="dropdown_contact_type">';
519
520 $output .= '<option value="">' . __( 'Show all contact types', 'propertyhive' ) . '</option>';
521
522 $output .= implode("", $options);
523
524 $output .= '</select>';
525 }
526
527 echo $output;
528 }
529
530 /**
531 * Show an enquiry filter box
532 */
533 public function enquiry_filters() {
534 global $wp_query;
535
536 // Department filtering
537 $output = '';
538
539 $output .= $this->enquiry_status_filter();
540 $output .= $this->enquiry_source_filter();
541 $output .= $this->enquiry_office_filter();
542
543 echo apply_filters( 'propertyhive_enquiry_filters', $output );
544 }
545
546 /**
547 * Show an enquiry status filter box
548 */
549 public function enquiry_status_filter() {
550 global $wp_query;
551
552 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'open', 'closed' ) ) ? $_GET['_status'] : '';
553
554 // Status filtering
555 $output = '<select name="_status" id="dropdown_enquiry_status">';
556
557 $output .= '<option value="open"';
558 $output .= selected( 'open', $selected_status, false );
559 $output .= '>' . __( 'Open', 'propertyhive' ) . '</option>';
560
561 $output .= '<option value="closed"';
562 $output .= selected( 'closed', $selected_status, false );
563 $output .= '>' . __( 'Closed', 'propertyhive' ) . '</option>';
564
565 $output .= '</select>';
566
567 return $output;
568 }
569
570 /**
571 * Show an enquiry source filter box
572 */
573 public function enquiry_source_filter() {
574 global $wp_query;
575
576 $sources = array(
577 'office' => __( 'Office', 'propertyhive' ),
578 'website' => __( 'Website', 'propertyhive' )
579 );
580
581 $sources = apply_filters( 'propertyhive_enquiry_sources', $sources );
582
583 // Status filtering
584 $output = '<select name="_source" id="dropdown_enquiry_source">';
585
586 $output .= '<option value="">' . __( 'Show all sources', 'propertyhive' ) . '</option>';
587
588 foreach ( $sources as $key => $value )
589 {
590 $output .= '<option value="' . $key . '"';
591 if ( isset( $_GET['_source'] ) && ! empty( $_GET['_source'] ) )
592 {
593 $output .= selected( $key, sanitize_text_field($_GET['_source']), false );
594 }
595 $output .= '>' . __( $value, 'propertyhive' ) . '</option>';
596 }
597
598 $output .= '</select>';
599
600 return $output;
601 }
602
603 /**
604 * Show an enquiry office filter box
605 */
606 public function enquiry_office_filter() {
607 global $wp_query, $post;
608
609 // Department filtering
610 $output = '<select name="_office_id" id="dropdown_enquiry_office_id">';
611
612 $output .= '<option value="">' . __( 'All Offices', 'propertyhive' ) . '</option>';
613
614 $args = array(
615 'post_type' => 'office',
616 'nopaging' => true,
617 'orderby' => 'title',
618 'order' => 'ASC'
619 );
620 $office_query = new WP_Query($args);
621
622 if ($office_query->have_posts())
623 {
624 while ($office_query->have_posts())
625 {
626 $office_query->the_post();
627
628 $output .= '<option value="' . $post->ID . '"';
629 if ( isset( $_GET['_office_id'] ) && ! empty( $_GET['_office_id'] ) )
630 {
631 $output .= selected( $post->ID, (int)$_GET['_office_id'], false );
632 }
633 $output .= '>' . get_the_title() . '</option>';
634 }
635 }
636
637 wp_reset_postdata();
638
639 $output .= '</select>';
640
641 return $output;
642 }
643
644 /**
645 * Show am appraisal filter box
646 */
647 public function appraisal_filters() {
648 global $wp_query;
649
650 $output = '';
651
652 $output .= $this->appraisal_status_filter();
653 $output .= $this->appraisal_attending_negotiator_filter();
654
655 echo apply_filters( 'propertyhive_appraisal_filters', $output );
656 }
657
658 /**
659 * Show an appraisal status filter box
660 */
661 public function appraisal_status_filter() {
662 global $wp_query;
663
664 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'pending', 'carried_out', 'won', 'lost', 'instructed', 'cancelled' ) ) ? $_GET['_status'] : '';
665
666 // Status filtering
667 $output = '<select name="_status" id="dropdown_appraisal_status">';
668
669 $output .= '<option value="">All Statuses</option>';
670
671 $output .= '<option value="pending"';
672 $output .= selected( 'pending', $selected_status, false );
673 $output .= '>' . __( 'Pending', 'propertyhive' ) . '</option>';
674
675 $output .= '<option value="carried_out"';
676 $output .= selected( 'carried_out', $selected_status, false );
677 $output .= '>' . __( 'Carried Out', 'propertyhive' ) . '</option>';
678
679 $output .= '<option value="won"';
680 $output .= selected( 'won', $selected_status, false );
681 $output .= '>- ' . __( 'Won', 'propertyhive' ) . '</option>';
682
683 $output .= '<option value="lost"';
684 $output .= selected( 'lost', $selected_status, false );
685 $output .= '>- ' . __( 'Lost', 'propertyhive' ) . '</option>';
686
687 $output .= '<option value="instructed"';
688 $output .= selected( 'instructed', $selected_status, false );
689 $output .= '>- ' . __( 'Instructed', 'propertyhive' ) . '</option>';
690
691 $output .= '<option value="cancelled"';
692 $output .= selected( 'cancelled', $selected_status, false );
693 $output .= '>' . __( 'Cancelled', 'propertyhive' ) . '</option>';
694
695 $output .= '</select>';
696
697 return $output;
698 }
699
700 /**
701 * Show an appraisal attending negotiator filter box
702 */
703 public function appraisal_attending_negotiator_filter() {
704 global $wp_query;
705
706 $selected_negotiator_id = isset( $_GET['_negotiator_id']) ? (int)$_GET['_negotiator_id'] : '';
707
708 // Status filtering
709 $output = '<select name="_negotiator_id" id="dropdown_appraisal_negotiator_id">';
710
711 $output .= '<option value="">Attending Negotiator</option>';
712 $output .= '<option value="">All Negotiators</option>';
713
714 $args = array(
715 'number' => 9999,
716 'orderby' => 'display_name',
717 'role__not_in' => array('property_hive_contact')
718 );
719 $user_query = new WP_User_Query( $args );
720
721 if ( ! empty( $user_query->results ) )
722 {
723 foreach ( $user_query->results as $user )
724 {
725 $output .= '<option value="' . $user->ID . '"';
726 if ( $user->ID == $selected_negotiator_id )
727 {
728 $output .= ' selected';
729 }
730 $output .= '>' . $user->display_name . '</option>';
731 }
732 }
733
734 $output .= '</select>';
735
736 return $output;
737 }
738
739 /**
740 * Show a viewing filter box
741 */
742 public function viewing_filters() {
743 global $wp_query;
744
745 // Department filtering
746 $output = '';
747
748 $output .= $this->viewing_status_filter();
749 $output .= $this->viewing_attending_negotiator_filter();
750
751 echo apply_filters( 'propertyhive_viewing_filters', $output );
752 }
753
754 /**
755 * Show a viewing status filter box
756 */
757 public function viewing_status_filter() {
758 global $wp_query;
759
760 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'pending', 'confirmed', 'unconfirmed', 'carried_out', 'feedback_passed_on', 'feedback_not_passed_on', 'cancelled' ) ) ? $_GET['_status'] : '';
761
762 // Status filtering
763 $output = '<select name="_status" id="dropdown_viewing_status">';
764
765 $output .= '<option value="">All Statuses</option>';
766
767 $output .= '<option value="pending"';
768 $output .= selected( 'pending', $selected_status, false );
769 $output .= '>' . __( 'Pending', 'propertyhive' ) . '</option>';
770
771 $output .= '<option value="confirmed"';
772 $output .= selected( 'confirmed', $selected_status, false );
773 $output .= '>- ' . __( 'Confirmed', 'propertyhive' ) . '</option>';
774
775 $output .= '<option value="unconfirmed"';
776 $output .= selected( 'unconfirmed', $selected_status, false );
777 $output .= '>- ' . __( 'Awaiting Confirmation', 'propertyhive' ) . '</option>';
778
779 $output .= '<option value="carried_out"';
780 $output .= selected( 'carried_out', $selected_status, false );
781 $output .= '>' . __( 'Carried Out', 'propertyhive' ) . '</option>';
782
783 $output .= '<option value="feedback_passed_on"';
784 $output .= selected( 'feedback_passed_on', $selected_status, false );
785 $output .= '>- ' . __( 'Feedback Passed On', 'propertyhive' ) . '</option>';
786
787 $output .= '<option value="feedback_not_passed_on"';
788 $output .= selected( 'feedback_not_passed_on', $selected_status, false );
789 $output .= '>- ' . __( 'Feedback Not Passed On', 'propertyhive' ) . '</option>';
790
791 $output .= '<option value="cancelled"';
792 $output .= selected( 'cancelled', $selected_status, false );
793 $output .= '>' . __( 'Cancelled', 'propertyhive' ) . '</option>';
794
795 $output .= '</select>';
796
797 return $output;
798 }
799
800 /**
801 * Show a viewing attending negotiator filter box
802 */
803 public function viewing_attending_negotiator_filter() {
804 global $wp_query;
805
806 $selected_negotiator_id = isset( $_GET['_negotiator_id']) ? (int)$_GET['_negotiator_id'] : '';
807
808 // Status filtering
809 $output = '<select name="_negotiator_id" id="dropdown_viewing_negotiator_id">';
810
811 $output .= '<option value="">Attending Negotiator</option>';
812 $output .= '<option value="">All Negotiators</option>';
813
814 $args = array(
815 'number' => 9999,
816 'orderby' => 'display_name',
817 'role__not_in' => array('property_hive_contact')
818 );
819 $user_query = new WP_User_Query( $args );
820
821 if ( ! empty( $user_query->results ) )
822 {
823 foreach ( $user_query->results as $user )
824 {
825 $output .= '<option value="' . $user->ID . '"';
826 if ( $user->ID == $selected_negotiator_id )
827 {
828 $output .= ' selected';
829 }
830 $output .= '>' . $user->display_name . '</option>';
831 }
832 }
833
834 $output .= '</select>';
835
836 return $output;
837 }
838
839 /**
840 * Show an offer filter box
841 */
842 public function offer_filters() {
843 global $wp_query;
844
845 $output = '';
846
847 $output .= $this->offer_status_filter();
848
849 echo apply_filters( 'propertyhive_offer_filters', $output );
850 }
851
852 /**
853 * Show an offer status filter box
854 */
855 public function offer_status_filter() {
856 global $wp_query;
857
858 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'pending', 'accepted', 'declined' ) ) ? $_GET['_status'] : '';
859
860 // Status filtering
861 $output = '<select name="_status" id="dropdown_offer_status">';
862
863 $output .= '<option value="">All Statuses</option>';
864
865 $output .= '<option value="pending"';
866 $output .= selected( 'pending', $selected_status, false );
867 $output .= '>' . __( 'Pending', 'propertyhive' ) . '</option>';
868
869 $output .= '<option value="accepted"';
870 $output .= selected( 'accepted', $selected_status, false );
871 $output .= '>' . __( 'Accepted', 'propertyhive' ) . '</option>';
872
873 $output .= '<option value="declined"';
874 $output .= selected( 'declined', $selected_status, false );
875 $output .= '>' . __( 'Declined', 'propertyhive' ) . '</option>';
876
877 $output .= '</select>';
878
879 return $output;
880 }
881
882 /**
883 * Show an sale filter box
884 */
885 public function sale_filters() {
886 global $wp_query;
887
888 $output = '';
889
890 $output .= $this->sale_status_filter();
891
892 echo apply_filters( 'propertyhive_sale_filters', $output );
893 }
894
895 /**
896 * Show an sale status filter box
897 */
898 public function sale_status_filter() {
899 global $wp_query;
900
901 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'current', 'exchanged', 'completed', 'fallen_through' ) ) ? $_GET['_status'] : '';
902
903 // Status filtering
904 $output = '<select name="_status" id="dropdown_sale_status">';
905
906 $output .= '<option value="">All Statuses</option>';
907
908 $output .= '<option value="current"';
909 $output .= selected( 'current', $selected_status, false );
910 $output .= '>' . __( 'Current', 'propertyhive' ) . '</option>';
911
912 $output .= '<option value="exchanged"';
913 $output .= selected( 'exchanged', $selected_status, false );
914 $output .= '>' . __( 'Exchanged', 'propertyhive' ) . '</option>';
915
916 $output .= '<option value="completed"';
917 $output .= selected( 'completed', $selected_status, false );
918 $output .= '>' . __( 'Completed', 'propertyhive' ) . '</option>';
919
920 $output .= '<option value="fallen_through"';
921 $output .= selected( 'fallen_through', $selected_status, false );
922 $output .= '>' . __( 'Fallen Through', 'propertyhive' ) . '</option>';
923
924 $output .= '</select>';
925
926 return $output;
927 }
928
929 /**
930 * Filters and sorting handler
931 * @param array $vars
932 * @return array
933 */
934 public function request_query( $vars ) {
935 global $typenow, $wp_query;
936
937 if ( !isset($vars['meta_query']) ) { $vars['meta_query'] = array(); }
938 if ( !isset($vars['tax_query']) ) { $vars['tax_query'] = array(); }
939
940 if ( 'property' === $typenow )
941 {
942 if ( ! empty( $_GET['_department'] ) ) {
943 $vars['meta_query'][] = array(
944 'key' => '_department',
945 'value' => sanitize_text_field( $_GET['_department'] ),
946 );
947 }
948 if ( ! empty( $_GET['_office_id'] ) ) {
949 $vars['meta_query'][] = array(
950 'key' => '_office_id',
951 'value' => (int)$_GET['_office_id'],
952 );
953 }
954 if ( ! empty( $_GET['_negotiator_id'] ) ) {
955 $vars['meta_query'][] = array(
956 'key' => '_negotiator_id',
957 'value' => (int)$_GET['_negotiator_id'],
958 );
959 }
960 if ( ! empty( $_GET['_location_id'] ) ) {
961 $vars['tax_query'][] = array(
962 'taxonomy' => 'location',
963 'terms' => ( (is_array($_GET['_location_id'])) ? (int)$_GET['_location_id'] : array( (int)$_GET['_location_id'] ) )
964 );
965 }
966 if ( ! empty( $_GET['_availability_id'] ) ) {
967 $vars['tax_query'][] = array(
968 'taxonomy' => 'availability',
969 'terms' => ( (is_array($_GET['_availability_id'])) ? (int)$_GET['_availability_id'] : array( (int)$_GET['_availability_id'] ) )
970 );
971 }
972 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'on_market' ) {
973 $vars['meta_query'][] = array(
974 'key' => '_on_market',
975 'value' => 'yes',
976 );
977 }
978 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'off_market' ) {
979 $vars['meta_query'][] = array(
980 'key' => '_on_market',
981 'value' => 'yes',
982 'compare' => '!=',
983 );
984 }
985 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'featured' ) {
986 $vars['meta_query'][] = array(
987 'key' => '_featured',
988 'value' => 'yes',
989 );
990 }
991 if ( ! empty( $_GET['_marketing'] ) && substr($_GET['_marketing'], 0, 15) == 'marketing_flag_' ) {
992 $marketing_flag_id = sanitize_text_field( str_replace("marketing_flag_", "", $_GET['_marketing']) );
993 $vars['tax_query'][] = array(
994 'taxonomy' => 'marketing_flag',
995 'terms' => ( (is_array($marketing_flag_id)) ? $marketing_flag_id : array( $marketing_flag_id ) )
996 );
997 }
998 }
999 elseif ( 'contact' === $typenow )
1000 {
1001 if ( ! empty( $_GET['_contact_type'] ) )
1002 {
1003 $contact_type = ph_clean($_GET['_contact_type']);
1004 if ( $contact_type == 'hotapplicant' )
1005 {
1006 $contact_type = 'applicant';
1007
1008 $vars['meta_query'][] = array(
1009 'key' => '_hot_applicant',
1010 'value' => 'yes',
1011 );
1012 }
1013 $vars['meta_query'][] = array(
1014 'key' => '_contact_types',
1015 'value' => $contact_type,
1016 'compare' => 'LIKE'
1017 );
1018 }
1019 }
1020 elseif ( 'enquiry' === $typenow )
1021 {
1022 if ( ! empty( $_GET['_status'] ) ) {
1023 $vars['meta_query'][] = array(
1024 'key' => '_status',
1025 'value' => sanitize_text_field( $_GET['_status'] ),
1026 );
1027 }
1028 if ( ! empty( $_GET['_source'] ) ) {
1029 $vars['meta_query'][] = array(
1030 'key' => '_source',
1031 'value' => sanitize_text_field( $_GET['_source'] ),
1032 );
1033 }
1034 if ( ! empty( $_GET['_office_id'] ) ) {
1035 $vars['meta_query'][] = array(
1036 'key' => '_office_id',
1037 'value' => sanitize_text_field( $_GET['_office_id'] ),
1038 );
1039 }
1040 }
1041 elseif ( 'appraisal' === $typenow )
1042 {
1043 if ( ! empty( $_GET['_status'] ) ) {
1044 switch ( sanitize_text_field( $_GET['_status'] ) )
1045 {
1046 case "confirmed":
1047 {
1048 $vars['meta_query'][] = array(
1049 'key' => '_status',
1050 'value' => 'pending',
1051 );
1052 $vars['meta_query'][] = array(
1053 'key' => '_all_confirmed',
1054 'value' => 'yes',
1055 );
1056 break;
1057 }
1058 case "unconfirmed":
1059 {
1060 $vars['meta_query'][] = array(
1061 'key' => '_status',
1062 'value' => 'pending',
1063 );
1064 $vars['meta_query'][] = array(
1065 'key' => '_all_confirmed',
1066 'value' => '',
1067 );
1068 break;
1069 }
1070 default:
1071 {
1072 $vars['meta_query'][] = array(
1073 'key' => '_status',
1074 'value' => sanitize_text_field( $_GET['_status'] ),
1075 );
1076 }
1077 }
1078 }
1079 if ( ! empty( $_GET['_negotiator_id'] ) )
1080 {
1081 $vars['meta_query'][] = array(
1082 'key' => '_negotiator_id',
1083 'value' => (int)$_GET['_negotiator_id'],
1084 );
1085 }
1086 }
1087 elseif ( 'viewing' === $typenow )
1088 {
1089 if ( ! empty( $_GET['_status'] ) ) {
1090 switch ( sanitize_text_field( $_GET['_status'] ) )
1091 {
1092 case "confirmed":
1093 {
1094 $vars['meta_query'][] = array(
1095 'key' => '_status',
1096 'value' => 'pending',
1097 );
1098 $vars['meta_query'][] = array(
1099 'key' => '_all_confirmed',
1100 'value' => 'yes',
1101 );
1102 break;
1103 }
1104 case "unconfirmed":
1105 {
1106 $vars['meta_query'][] = array(
1107 'key' => '_status',
1108 'value' => 'pending',
1109 );
1110 $vars['meta_query'][] = array(
1111 'key' => '_all_confirmed',
1112 'value' => '',
1113 );
1114 break;
1115 }
1116 case "feedback_passed_on":
1117 {
1118 $vars['meta_query'][] = array(
1119 'key' => '_status',
1120 'value' => 'carried_out',
1121 );
1122 $vars['meta_query'][] = array(
1123 'key' => '_feedback_status',
1124 'value' => array('interested', 'not_interested'),
1125 'compare' => 'IN'
1126 );
1127 $vars['meta_query'][] = array(
1128 'key' => '_feedback_passed_on',
1129 'value' => 'yes',
1130 );
1131 break;
1132 }
1133 case "feedback_not_passed_on":
1134 {
1135 $vars['meta_query'][] = array(
1136 'key' => '_status',
1137 'value' => 'carried_out',
1138 );
1139 $vars['meta_query'][] = array(
1140 'key' => '_feedback_status',
1141 'value' => array('interested', 'not_interested'),
1142 'compare' => 'IN'
1143 );
1144 $vars['meta_query'][] = array(
1145 'key' => '_feedback_passed_on',
1146 'value' => '',
1147 );
1148 break;
1149 }
1150 default:
1151 {
1152 $vars['meta_query'][] = array(
1153 'key' => '_status',
1154 'value' => sanitize_text_field( $_GET['_status'] ),
1155 );
1156 }
1157 }
1158 }
1159 if ( ! empty( $_GET['_negotiator_id'] ) )
1160 {
1161 $vars['meta_query'][] = array(
1162 'key' => '_negotiator_id',
1163 'value' => (int)$_GET['_negotiator_id'],
1164 );
1165 }
1166 }
1167 elseif ( 'offer' === $typenow )
1168 {
1169 if ( ! empty( $_GET['_status'] ) ) {
1170 $vars['meta_query'][] = array(
1171 'key' => '_status',
1172 'value' => sanitize_text_field( $_GET['_status'] ),
1173 );
1174 }
1175 }
1176 elseif ( 'sale' === $typenow )
1177 {
1178 if ( ! empty( $_GET['_status'] ) ) {
1179 $vars['meta_query'][] = array(
1180 'key' => '_status',
1181 'value' => sanitize_text_field( $_GET['_status'] ),
1182 );
1183 }
1184 }
1185
1186 $vars = apply_filters( 'propertyhive_property_filter_query', $vars, $typenow );
1187
1188 return $vars;
1189 }
1190
1191 /**
1192 * Removes variations etc belonging to a deleted post, and clears transients
1193 *
1194 * @access public
1195 * @param mixed $id ID of post being deleted
1196 * @return void
1197 */
1198 public function delete_post( $id ) {
1199 /*global $propertyhive, $wpdb;
1200
1201 if ( ! current_user_can( 'delete_posts' ) )
1202 return;
1203
1204 if ( $id > 0 ) {
1205
1206 $post_type = get_post_type( $id );
1207
1208 switch( $post_type ) {
1209 case 'property' :
1210 ph_delete_property_transients();
1211 break;
1212 case 'contact' :
1213 ph_delete_contact_transients();
1214 break;
1215 case 'enquiry' :
1216 ph_delete_enquiry_transients();
1217 break;
1218 }
1219 }*/
1220 }
1221
1222 /**
1223 * propertyhive_trash_post function.
1224 *
1225 * @access public
1226 * @param mixed $id
1227 * @return void
1228 */
1229 public function trash_post( $id ) {
1230 /*if ( $id > 0 ) {
1231
1232 $post_type = get_post_type( $id );
1233
1234
1235 }*/
1236 }
1237
1238 /**
1239 * propertyhive_untrash_post function.
1240 *
1241 * @access public
1242 * @param mixed $id
1243 * @return void
1244 */
1245 public function untrash_post( $id ) {
1246 /*if ( $id > 0 ) {
1247
1248 $post_type = get_post_type( $id );
1249
1250 }*/
1251 }
1252 }
1253
1254 endif;
1255
1256 return new PH_Admin_Post_Types();