PluginProbe
Property Hive / 1.4.52
Property Hive v1.4.52
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.52, at includes/admin/class-ph-admin-post-types.php

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