PluginProbe
Property Hive / 1.4.49
Property Hive v1.4.49
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.49, at includes/admin/class-ph-admin-post-types.php

1,076 lines 38.3 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 default :
178 break;
179 }
180 }
181
182 /**
183 * Show a property filter box
184 */
185 public function property_filters() {
186 global $wp_query;
187
188 // Department filtering
189 $output = '';
190
191 $output .= $this->property_department_filter();
192 $output .= $this->property_marketing_filter();
193 $output .= $this->property_availability_filter();
194 $output .= $this->property_location_filter();
195 $output .= $this->property_office_filter();
196 $output .= $this->property_negotiator_filter();
197
198 echo apply_filters( 'propertyhive_property_filters', $output );
199 }
200
201 /**
202 * Show a property department filter box
203 */
204 public function property_department_filter() {
205 global $wp_query;
206
207 $departments = ph_get_departments();
208
209 $selected_department = isset( $_GET['_department'] ) && in_array( $_GET['_department'], array_keys($departments) ) ? $_GET['_department'] : '';
210
211 // Department filtering
212 $output = '<select name="_department" id="dropdown_property_department">';
213
214 $output .= '<option value="">' . __( 'All Departments', 'propertyhive' ) . '</option>';
215
216 foreach ( $departments as $key => $value )
217 {
218 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
219 {
220 $output .= '<option value="' . $key . '"';
221 $output .= selected( $key, $selected_department, false );
222 $output .= '>' . $value . '</option>';
223 }
224 }
225
226 $output .= '</select>';
227
228 return $output;
229 }
230
231 /**
232 * Show a property office filter box
233 */
234 public function property_office_filter() {
235 global $wp_query, $post;
236
237 // Department filtering
238 $output = '<select name="_office_id" id="dropdown_property_office_id">';
239
240 $output .= '<option value="">' . __( 'All Offices', 'propertyhive' ) . '</option>';
241
242 $args = array(
243 'post_type' => 'office',
244 'nopaging' => true,
245 'orderby' => 'title',
246 'order' => 'ASC'
247 );
248 $office_query = new WP_Query($args);
249
250 if ($office_query->have_posts())
251 {
252 while ($office_query->have_posts())
253 {
254 $office_query->the_post();
255
256 $output .= '<option value="' . $post->ID . '"';
257 if ( isset( $_GET['_office_id'] ) && ! empty( $_GET['_office_id'] ) )
258 {
259 $output .= selected( $post->ID, (int)$_GET['_office_id'], false );
260 }
261 $output .= '>' . get_the_title() . '</option>';
262 }
263 }
264
265 wp_reset_postdata();
266
267 $output .= '</select>';
268
269 return $output;
270 }
271
272 /**
273 * Show a property negotiator filter box
274 */
275 public function property_negotiator_filter() {
276 global $wp_query, $post;
277
278 $selected = '';
279 if ( isset( $_GET['_negotiator_id'] ) && ! empty( $_GET['_negotiator_id'] ) )
280 {
281 $selected = (int)$_GET['_negotiator_id'];
282 }
283
284 $args = array(
285 'name' => '_negotiator_id',
286 'id' => 'dropdown_property_negotiator_id',
287 'show_option_all' => __( 'All Negotiators', 'propertyhive' ),
288 'selected' => $selected,
289 'echo' => false,
290 'role__not_in' => array('property_hive_contact')
291 );
292 $output = wp_dropdown_users($args);
293
294 return $output;
295 }
296
297 /**
298 * Show a property location filter box
299 */
300 public function property_location_filter() {
301 global $wp_query, $post;
302
303 // Department filtering
304 $output = '<select name="_location_id" id="dropdown_property_location_id">';
305
306 $options = array( );
307 $args = array(
308 'hide_empty' => false,
309 'parent' => 0
310 );
311 $terms = get_terms( 'location', $args );
312
313 if ( !empty( $terms ) && !is_wp_error( $terms ) )
314 {
315 foreach ($terms as $term)
316 {
317 $options[$term->term_id] = $term->name;
318
319 $args = array(
320 'hide_empty' => false,
321 'parent' => $term->term_id
322 );
323 $subterms = get_terms( 'location', $args );
324
325 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
326 {
327 foreach ($subterms as $term)
328 {
329 $options[$term->term_id] = '- ' . $term->name;
330
331 $args = array(
332 'hide_empty' => false,
333 'parent' => $term->term_id
334 );
335 $subsubterms = get_terms( 'location', $args );
336
337 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
338 {
339 foreach ($subsubterms as $term)
340 {
341 $options[$term->term_id] = '- ' . $term->name;
342 }
343 }
344 }
345 }
346 }
347 }
348
349 $output .= '<option value="">' . __( 'All Locations', 'propertyhive' ) . '</option>';
350
351 if ( !empty($options) )
352 {
353 foreach ( $options as $value => $label )
354 {
355 $output .= '<option value="' . $value . '"';
356 if ( isset( $_GET['_location_id'] ) && ! empty( $_GET['_location_id'] ) )
357 {
358 $output .= selected( $value, (int)$_GET['_location_id'], false );
359 }
360 $output .= '>' . $label . '</option>';
361 }
362 }
363
364 $output .= '</select>';
365
366 return $output;
367 }
368
369 /**
370 * Show a property availability filter box
371 */
372 public function property_availability_filter() {
373 global $wp_query, $post;
374
375 // Availability filtering
376 $output = '<select name="_availability_id" id="dropdown_property_availability_id">';
377
378 $options = array( );
379 $args = array(
380 'hide_empty' => false,
381 'parent' => 0
382 );
383 $terms = get_terms( 'availability', $args );
384
385 if ( !empty( $terms ) && !is_wp_error( $terms ) )
386 {
387 foreach ($terms as $term)
388 {
389 $options[$term->term_id] = $term->name;
390 }
391 }
392
393 $output .= '<option value="">' . __( 'All Availabilities', 'propertyhive' ) . '</option>';
394
395 if ( !empty($options) )
396 {
397 foreach ( $options as $value => $label )
398 {
399 $output .= '<option value="' . $value . '"';
400 if ( isset( $_GET['_availability_id'] ) && ! empty( $_GET['_availability_id'] ) )
401 {
402 $output .= selected( $value, (int)$_GET['_availability_id'], false );
403 }
404 $output .= '>' . $label . '</option>';
405 }
406 }
407
408 $output .= '</select>';
409
410 return $output;
411 }
412
413 /**
414 * Show a property marketing filter box
415 */
416 public function property_marketing_filter() {
417 global $wp_query, $post;
418
419 // Availability filtering
420 $output = '<select name="_marketing" id="dropdown_property_marketing">';
421
422 $output .= '<option value="">' . __( 'All Marketing Statuses', 'propertyhive' ) . '</option>';
423
424 $options = array(
425 'on_market' => __( 'On Market Only', 'propertyhive' ),
426 'off_market' => __( 'Not On Market Only', 'propertyhive' ),
427 'featured' => __( 'Featured Only', 'propertyhive' ),
428 );
429
430 $args = array(
431 'hide_empty' => false,
432 'parent' => 0
433 );
434 $terms = get_terms( 'marketing_flag', $args );
435
436 if ( !empty( $terms ) && !is_wp_error( $terms ) )
437 {
438 foreach ($terms as $term)
439 {
440 $options['marketing_flag_' . $term->term_id] = __( 'Has Marketing Flag', 'propertyhive') . ' - ' . $term->name;
441 }
442 }
443
444 $options = apply_filters( 'propertyhive_property_filter_marketing_options', $options );
445
446 foreach ( $options as $key => $value )
447 {
448 $output .= '<option value="' . $key . '"';
449 if ( isset( $_GET['_marketing'] ) && ! empty( $_GET['_marketing'] ) )
450 {
451 $output .= selected( $key, sanitize_text_field($_GET['_marketing']), false );
452 }
453 $output .= '>' . $value . '</option>';
454 }
455
456 $output .= '</select>';
457
458 return $output;
459 }
460
461 /**
462 * Show a contact filter box
463 */
464 public function contact_filters() {
465 global $wp_query;
466
467 $selected_contact_type = isset( $_GET['_contact_type'] ) && in_array( $_GET['_contact_type'], array( 'owner', 'potentialowner', 'applicant', 'thirdparty' ) ) ? $_GET['_contact_type'] : '';
468
469 // Type filtering
470 $options = array();
471
472 // Owners
473 $option = '<option value="owner"';
474 $option .= selected( 'owner', $selected_contact_type, false );
475 $option .= '>' . __( 'Owners and Landlords', 'propertyhive' ) . '</option>';
476
477 $options[] = $option;
478
479 // Potential Owners
480 $option = '<option value="potentialowner"';
481 $option .= selected( 'potentialowner', $selected_contact_type, false );
482 $option .= '>' . __( 'Potential Owners and Landlords', 'propertyhive' ) . '</option>';
483
484 $options[] = $option;
485
486 // Applicants
487 $option = '<option value="applicant"';
488 $option .= selected( 'applicant', $selected_contact_type, false );
489 $option .= '>' . __( 'Applicants', 'propertyhive' ) . '</option>';
490
491 $options[] = $option;
492
493 // Third Parties
494 $option = '<option value="thirdparty"';
495 $option .= selected( 'thirdparty', $selected_contact_type, false );
496 $option .= '>' . __( 'Third Party Contacts', 'propertyhive' ) . '</option>';
497
498 $options[] = $option;
499
500 $options = apply_filters( 'propertyhive_contact_filter_options', $options );
501
502 $output = '';
503 if (count($options) > 1)
504 {
505 $output = '<select name="_contact_type" id="dropdown_contact_type">';
506
507 $output .= '<option value="">' . __( 'Show all contact types', 'propertyhive' ) . '</option>';
508
509 $output .= implode("", $options);
510
511 $output .= '</select>';
512 }
513
514 echo $output;
515 }
516
517 /**
518 * Show an enquiry filter box
519 */
520 public function enquiry_filters() {
521 global $wp_query;
522
523 // Department filtering
524 $output = '';
525
526 $output .= $this->enquiry_status_filter();
527 $output .= $this->enquiry_source_filter();
528
529 echo apply_filters( 'propertyhive_enquiry_filters', $output );
530 }
531
532 /**
533 * Show an enquiry status filter box
534 */
535 public function enquiry_status_filter() {
536 global $wp_query;
537
538 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'open', 'closed' ) ) ? $_GET['_status'] : '';
539
540 // Status filtering
541 $output = '<select name="_status" id="dropdown_enquiry_status">';
542
543 $output .= '<option value="open"';
544 $output .= selected( 'open', $selected_status, false );
545 $output .= '>' . __( 'Open', 'propertyhive' ) . '</option>';
546
547 $output .= '<option value="closed"';
548 $output .= selected( 'closed', $selected_status, false );
549 $output .= '>' . __( 'Closed', 'propertyhive' ) . '</option>';
550
551 $output .= '</select>';
552
553 return $output;
554 }
555
556 /**
557 * Show an enquiry source filter box
558 */
559 public function enquiry_source_filter() {
560 global $wp_query;
561
562 $sources = array(
563 'office' => __( 'Office', 'propertyhive' ),
564 'website' => __( 'Website', 'propertyhive' )
565 );
566
567 $sources = apply_filters( 'propertyhive_enquiry_sources', $sources );
568
569 // Status filtering
570 $output = '<select name="_source" id="dropdown_enquiry_source">';
571
572 $output .= '<option value="">' . __( 'Show all sources', 'propertyhive' ) . '</option>';
573
574 foreach ( $sources as $key => $value )
575 {
576 $output .= '<option value="' . $key . '"';
577 if ( isset( $_GET['_source'] ) && ! empty( $_GET['_source'] ) )
578 {
579 $output .= selected( $key, sanitize_text_field($_GET['_source']), false );
580 }
581 $output .= '>' . __( $value, 'propertyhive' ) . '</option>';
582 }
583
584 $output .= '</select>';
585
586 return $output;
587 }
588
589 /**
590 * Show am appraisal filter box
591 */
592 public function appraisal_filters() {
593 global $wp_query;
594
595 $output = '';
596
597 $output .= $this->appraisal_status_filter();
598 $output .= $this->appraisal_attending_negotiator_filter();
599
600 echo apply_filters( 'propertyhive_appraisal_filters', $output );
601 }
602
603 /**
604 * Show an appraisal status filter box
605 */
606 public function appraisal_status_filter() {
607 global $wp_query;
608
609 $selected_status = isset( $_GET['_status'] ) && in_array( $_GET['_status'], array( 'pending', 'carried_out', 'won', 'lost', 'instructed', 'cancelled' ) ) ? $_GET['_status'] : '';
610
611 // Status filtering
612 $output = '<select name="_status" id="dropdown_appraisal_status">';
613
614 $output .= '<option value="">All Statuses</option>';
615
616 $output .= '<option value="pending"';
617 $output .= selected( 'pending', $selected_status, false );
618 $output .= '>' . __( 'Pending', 'propertyhive' ) . '</option>';
619
620 $output .= '<option value="carried_out"';
621 $output .= selected( 'carried_out', $selected_status, false );
622 $output .= '>' . __( 'Carried Out', 'propertyhive' ) . '</option>';
623
624 $output .= '<option value="won"';
625 $output .= selected( 'won', $selected_status, false );
626 $output .= '>- ' . __( 'Won', 'propertyhive' ) . '</option>';
627
628 $output .= '<option value="lost"';
629 $output .= selected( 'lost', $selected_status, false );
630 $output .= '>- ' . __( 'Lost', 'propertyhive' ) . '</option>';
631
632 $output .= '<option value="instructed"';
633 $output .= selected( 'instructed', $selected_status, false );
634 $output .= '>- ' . __( 'Instructed', 'propertyhive' ) . '</option>';
635
636 $output .= '<option value="cancelled"';
637 $output .= selected( 'cancelled', $selected_status, false );
638 $output .= '>' . __( 'Cancelled', 'propertyhive' ) . '</option>';
639
640 $output .= '</select>';
641
642 return $output;
643 }
644
645 /**
646 * Show an appraisal attending negotiator filter box
647 */
648 public function appraisal_attending_negotiator_filter() {
649 global $wp_query;
650
651 $selected_negotiator_id = isset( $_GET['_negotiator_id']) ? (int)$_GET['_negotiator_id'] : '';
652
653 // Status filtering
654 $output = '<select name="_negotiator_id" id="dropdown_appraisal_negotiator_id">';
655
656 $output .= '<option value="">Attending Negotiator</option>';
657 $output .= '<option value="">All Negotiators</option>';
658
659 $args = array(
660 'number' => 9999,
661 'orderby' => 'display_name',
662 'role__not_in' => array('property_hive_contact')
663 );
664 $user_query = new WP_User_Query( $args );
665
666 if ( ! empty( $user_query->results ) )
667 {
668 foreach ( $user_query->results as $user )
669 {
670 $output .= '<option value="' . $user->ID . '"';
671 if ( $user->ID == $selected_negotiator_id )
672 {
673 $output .= ' selected';
674 }
675 $output .= '>' . $user->display_name . '</option>';
676 }
677 }
678
679 $output .= '</select>';
680
681 return $output;
682 }
683
684 /**
685 * Show a viewing filter box
686 */
687 public function viewing_filters() {
688 global $wp_query;
689
690 // Department filtering
691 $output = '';
692
693 $output .= $this->viewing_status_filter();
694 $output .= $this->viewing_attending_negotiator_filter();
695
696 echo apply_filters( 'propertyhive_viewing_filters', $output );
697 }
698
699 /**
700 * Show a viewing status filter box
701 */
702 public function viewing_status_filter() {
703 global $wp_query;
704
705 $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'] : '';
706
707 // Status filtering
708 $output = '<select name="_status" id="dropdown_viewing_status">';
709
710 $output .= '<option value="">All Statuses</option>';
711
712 $output .= '<option value="pending"';
713 $output .= selected( 'pending', $selected_status, false );
714 $output .= '>' . __( 'Pending', 'propertyhive' ) . '</option>';
715
716 $output .= '<option value="confirmed"';
717 $output .= selected( 'confirmed', $selected_status, false );
718 $output .= '>- ' . __( 'Confirmed', 'propertyhive' ) . '</option>';
719
720 $output .= '<option value="unconfirmed"';
721 $output .= selected( 'unconfirmed', $selected_status, false );
722 $output .= '>- ' . __( 'Awaiting Confirmation', 'propertyhive' ) . '</option>';
723
724 $output .= '<option value="carried_out"';
725 $output .= selected( 'carried_out', $selected_status, false );
726 $output .= '>' . __( 'Carried Out', 'propertyhive' ) . '</option>';
727
728 $output .= '<option value="feedback_passed_on"';
729 $output .= selected( 'feedback_passed_on', $selected_status, false );
730 $output .= '>- ' . __( 'Feedback Passed On', 'propertyhive' ) . '</option>';
731
732 $output .= '<option value="feedback_not_passed_on"';
733 $output .= selected( 'feedback_not_passed_on', $selected_status, false );
734 $output .= '>- ' . __( 'Feedback Not Passed On', 'propertyhive' ) . '</option>';
735
736 $output .= '<option value="cancelled"';
737 $output .= selected( 'cancelled', $selected_status, false );
738 $output .= '>' . __( 'Cancelled', 'propertyhive' ) . '</option>';
739
740 $output .= '</select>';
741
742 return $output;
743 }
744
745 /**
746 * Show a viewing attending negotiator filter box
747 */
748 public function viewing_attending_negotiator_filter() {
749 global $wp_query;
750
751 $selected_negotiator_id = isset( $_GET['_negotiator_id']) ? (int)$_GET['_negotiator_id'] : '';
752
753 // Status filtering
754 $output = '<select name="_negotiator_id" id="dropdown_viewing_negotiator_id">';
755
756 $output .= '<option value="">Attending Negotiator</option>';
757 $output .= '<option value="">All Negotiators</option>';
758
759 $args = array(
760 'number' => 9999,
761 'orderby' => 'display_name',
762 'role__not_in' => array('property_hive_contact')
763 );
764 $user_query = new WP_User_Query( $args );
765
766 if ( ! empty( $user_query->results ) )
767 {
768 foreach ( $user_query->results as $user )
769 {
770 $output .= '<option value="' . $user->ID . '"';
771 if ( $user->ID == $selected_negotiator_id )
772 {
773 $output .= ' selected';
774 }
775 $output .= '>' . $user->display_name . '</option>';
776 }
777 }
778
779 $output .= '</select>';
780
781 return $output;
782 }
783
784 /**
785 * Filters and sorting handler
786 * @param array $vars
787 * @return array
788 */
789 public function request_query( $vars ) {
790 global $typenow, $wp_query;
791
792 if ( !isset($vars['meta_query']) ) { $vars['meta_query'] = array(); }
793 if ( !isset($vars['tax_query']) ) { $vars['tax_query'] = array(); }
794
795 if ( 'property' === $typenow )
796 {
797 if ( ! empty( $_GET['_department'] ) ) {
798 $vars['meta_query'][] = array(
799 'key' => '_department',
800 'value' => sanitize_text_field( $_GET['_department'] ),
801 );
802 }
803 if ( ! empty( $_GET['_office_id'] ) ) {
804 $vars['meta_query'][] = array(
805 'key' => '_office_id',
806 'value' => (int)$_GET['_office_id'],
807 );
808 }
809 if ( ! empty( $_GET['_negotiator_id'] ) ) {
810 $vars['meta_query'][] = array(
811 'key' => '_negotiator_id',
812 'value' => (int)$_GET['_negotiator_id'],
813 );
814 }
815 if ( ! empty( $_GET['_location_id'] ) ) {
816 $vars['tax_query'][] = array(
817 'taxonomy' => 'location',
818 'terms' => ( (is_array($_GET['_location_id'])) ? (int)$_GET['_location_id'] : array( (int)$_GET['_location_id'] ) )
819 );
820 }
821 if ( ! empty( $_GET['_availability_id'] ) ) {
822 $vars['tax_query'][] = array(
823 'taxonomy' => 'availability',
824 'terms' => ( (is_array($_GET['_availability_id'])) ? (int)$_GET['_availability_id'] : array( (int)$_GET['_availability_id'] ) )
825 );
826 }
827 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'on_market' ) {
828 $vars['meta_query'][] = array(
829 'key' => '_on_market',
830 'value' => 'yes',
831 );
832 }
833 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'off_market' ) {
834 $vars['meta_query'][] = array(
835 'key' => '_on_market',
836 'value' => 'yes',
837 'compare' => '!=',
838 );
839 }
840 if ( ! empty( $_GET['_marketing'] ) && $_GET['_marketing'] == 'featured' ) {
841 $vars['meta_query'][] = array(
842 'key' => '_featured',
843 'value' => 'yes',
844 );
845 }
846 if ( ! empty( $_GET['_marketing'] ) && substr($_GET['_marketing'], 0, 15) == 'marketing_flag_' ) {
847 $marketing_flag_id = sanitize_text_field( str_replace("marketing_flag_", "", $_GET['_marketing']) );
848 $vars['tax_query'][] = array(
849 'taxonomy' => 'marketing_flag',
850 'terms' => ( (is_array($marketing_flag_id)) ? $marketing_flag_id : array( $marketing_flag_id ) )
851 );
852 }
853 }
854 elseif ( 'contact' === $typenow )
855 {
856 if ( ! empty( $_GET['_contact_type'] ) ) {
857 $vars['meta_query'][] = array(
858 'key' => '_contact_types',
859 'value' => sanitize_text_field( $_GET['_contact_type'] ),
860 'compare' => 'LIKE'
861 );
862 }
863 }
864 elseif ( 'enquiry' === $typenow )
865 {
866 if ( ! empty( $_GET['_status'] ) ) {
867 $vars['meta_query'][] = array(
868 'key' => '_status',
869 'value' => sanitize_text_field( $_GET['_status'] ),
870 );
871 }
872 if ( ! empty( $_GET['_source'] ) ) {
873 $vars['meta_query'][] = array(
874 'key' => '_source',
875 'value' => sanitize_text_field( $_GET['_source'] ),
876 );
877 }
878 }
879 elseif ( 'appraisal' === $typenow )
880 {
881 if ( ! empty( $_GET['_status'] ) ) {
882 switch ( sanitize_text_field( $_GET['_status'] ) )
883 {
884 case "confirmed":
885 {
886 $vars['meta_query'][] = array(
887 'key' => '_status',
888 'value' => 'pending',
889 );
890 $vars['meta_query'][] = array(
891 'key' => '_all_confirmed',
892 'value' => 'yes',
893 );
894 break;
895 }
896 case "unconfirmed":
897 {
898 $vars['meta_query'][] = array(
899 'key' => '_status',
900 'value' => 'pending',
901 );
902 $vars['meta_query'][] = array(
903 'key' => '_all_confirmed',
904 'value' => '',
905 );
906 break;
907 }
908 default:
909 {
910 $vars['meta_query'][] = array(
911 'key' => '_status',
912 'value' => sanitize_text_field( $_GET['_status'] ),
913 );
914 }
915 }
916 }
917 if ( ! empty( $_GET['_negotiator_id'] ) )
918 {
919 $vars['meta_query'][] = array(
920 'key' => '_negotiator_id',
921 'value' => (int)$_GET['_negotiator_id'],
922 );
923 }
924 }
925 elseif ( 'viewing' === $typenow )
926 {
927 if ( ! empty( $_GET['_status'] ) ) {
928 switch ( sanitize_text_field( $_GET['_status'] ) )
929 {
930 case "confirmed":
931 {
932 $vars['meta_query'][] = array(
933 'key' => '_status',
934 'value' => 'pending',
935 );
936 $vars['meta_query'][] = array(
937 'key' => '_all_confirmed',
938 'value' => 'yes',
939 );
940 break;
941 }
942 case "unconfirmed":
943 {
944 $vars['meta_query'][] = array(
945 'key' => '_status',
946 'value' => 'pending',
947 );
948 $vars['meta_query'][] = array(
949 'key' => '_all_confirmed',
950 'value' => '',
951 );
952 break;
953 }
954 case "feedback_passed_on":
955 {
956 $vars['meta_query'][] = array(
957 'key' => '_status',
958 'value' => 'carried_out',
959 );
960 $vars['meta_query'][] = array(
961 'key' => '_feedback_status',
962 'value' => array('interested', 'not_interested'),
963 'compare' => 'IN'
964 );
965 $vars['meta_query'][] = array(
966 'key' => '_feedback_passed_on',
967 'value' => 'yes',
968 );
969 break;
970 }
971 case "feedback_not_passed_on":
972 {
973 $vars['meta_query'][] = array(
974 'key' => '_status',
975 'value' => 'carried_out',
976 );
977 $vars['meta_query'][] = array(
978 'key' => '_feedback_status',
979 'value' => array('interested', 'not_interested'),
980 'compare' => 'IN'
981 );
982 $vars['meta_query'][] = array(
983 'key' => '_feedback_passed_on',
984 'value' => '',
985 );
986 break;
987 }
988 default:
989 {
990 $vars['meta_query'][] = array(
991 'key' => '_status',
992 'value' => sanitize_text_field( $_GET['_status'] ),
993 );
994 }
995 }
996 }
997 if ( ! empty( $_GET['_negotiator_id'] ) )
998 {
999 $vars['meta_query'][] = array(
1000 'key' => '_negotiator_id',
1001 'value' => (int)$_GET['_negotiator_id'],
1002 );
1003 }
1004 }
1005
1006 $vars = apply_filters( 'propertyhive_property_filter_query', $vars, $typenow );
1007
1008 return $vars;
1009 }
1010
1011 /**
1012 * Removes variations etc belonging to a deleted post, and clears transients
1013 *
1014 * @access public
1015 * @param mixed $id ID of post being deleted
1016 * @return void
1017 */
1018 public function delete_post( $id ) {
1019 /*global $propertyhive, $wpdb;
1020
1021 if ( ! current_user_can( 'delete_posts' ) )
1022 return;
1023
1024 if ( $id > 0 ) {
1025
1026 $post_type = get_post_type( $id );
1027
1028 switch( $post_type ) {
1029 case 'property' :
1030 ph_delete_property_transients();
1031 break;
1032 case 'contact' :
1033 ph_delete_contact_transients();
1034 break;
1035 case 'enquiry' :
1036 ph_delete_enquiry_transients();
1037 break;
1038 }
1039 }*/
1040 }
1041
1042 /**
1043 * propertyhive_trash_post function.
1044 *
1045 * @access public
1046 * @param mixed $id
1047 * @return void
1048 */
1049 public function trash_post( $id ) {
1050 /*if ( $id > 0 ) {
1051
1052 $post_type = get_post_type( $id );
1053
1054
1055 }*/
1056 }
1057
1058 /**
1059 * propertyhive_untrash_post function.
1060 *
1061 * @access public
1062 * @param mixed $id
1063 * @return void
1064 */
1065 public function untrash_post( $id ) {
1066 /*if ( $id > 0 ) {
1067
1068 $post_type = get_post_type( $id );
1069
1070 }*/
1071 }
1072 }
1073
1074 endif;
1075
1076 return new PH_Admin_Post_Types();