| 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 |
add_filter( 'posts_where', array( $this, 'search_property_reference' ) ); |
| 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-viewing.php' ); |
| 55 |
include( 'post-types/class-ph-admin-cpt-offer.php' ); |
| 56 |
include( 'post-types/class-ph-admin-cpt-sale.php' ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Change messages when a post type is updated. |
| 61 |
* |
| 62 |
* @param array $messages |
| 63 |
* @return array |
| 64 |
*/ |
| 65 |
public function post_updated_messages( $messages ) { |
| 66 |
global $post, $post_ID; |
| 67 |
|
| 68 |
$messages['property'] = array( |
| 69 |
0 => '', // Unused. Messages start at index 1. |
| 70 |
1 => sprintf( __( 'Property updated. <a href="%s">View Property</a>', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ), |
| 71 |
2 => __( 'Custom field updated.', 'propertyhive' ), |
| 72 |
3 => __( 'Custom field deleted.', 'propertyhive' ), |
| 73 |
4 => __( 'Property updated.', 'propertyhive' ), |
| 74 |
5 => isset($_GET['revision']) ? sprintf( __( 'Property restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 75 |
6 => sprintf( __( 'Property published. <a href="%s">View Property</a>', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ), |
| 76 |
7 => __( 'Property saved.', 'propertyhive' ), |
| 77 |
8 => sprintf( __( 'Property submitted. <a target="_blank" href="%s">Preview Property</a>', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), |
| 78 |
9 => sprintf( __( 'Property scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Property</a>', 'propertyhive' ), |
| 79 |
date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), |
| 80 |
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) ) ) ), |
| 81 |
); |
| 82 |
|
| 83 |
$messages['contact'] = array( |
| 84 |
0 => '', // Unused. Messages start at index 1. |
| 85 |
1 => __( 'Contact updated.', 'propertyhive' ), |
| 86 |
2 => __( 'Custom field updated.', 'propertyhive' ), |
| 87 |
3 => __( 'Custom field deleted.', 'propertyhive' ), |
| 88 |
4 => __( 'Contact updated.', 'propertyhive' ), |
| 89 |
5 => isset($_GET['revision']) ? sprintf( __( 'Contact restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 90 |
6 => __( 'Contact published.', 'propertyhive' ), |
| 91 |
7 => __( 'Contact saved.', 'propertyhive' ), |
| 92 |
8 => __( 'Contact submitted.', 'propertyhive' ), |
| 93 |
9 => sprintf( __( 'Contact scheduled for: <strong>%1$s</strong>.', 'propertyhive' ), date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) )), |
| 94 |
10 => __( 'Contact draft updated.', 'propertyhive' ), |
| 95 |
); |
| 96 |
|
| 97 |
$messages['office'] = array( |
| 98 |
0 => '', // Unused. Messages start at index 1. |
| 99 |
1 => __( 'Office updated.', 'propertyhive' ), |
| 100 |
2 => __( 'Custom field updated.', 'propertyhive' ), |
| 101 |
3 => __( 'Custom field deleted.', 'propertyhive' ), |
| 102 |
4 => __( 'Office updated.', 'propertyhive' ), |
| 103 |
5 => isset($_GET['revision']) ? sprintf( __( 'Office restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 104 |
6 => sprintf( __( 'Office published.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ), |
| 105 |
7 => __( 'Office saved.', 'propertyhive' ), |
| 106 |
8 => sprintf( __( 'Office submitted.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), |
| 107 |
9 => sprintf( __( 'Office scheduled for: <strong>%1$s</strong>.', 'propertyhive' ), |
| 108 |
date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), |
| 109 |
10 => sprintf( __( 'Office draft updated. ', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), |
| 110 |
); |
| 111 |
|
| 112 |
$messages['enquiry'] = array( |
| 113 |
0 => '', // Unused. Messages start at index 1. |
| 114 |
1 => sprintf( __( 'Enquiry updated.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ), |
| 115 |
2 => __( 'Custom field updated.', 'propertyhive' ), |
| 116 |
3 => __( 'Custom field deleted.', 'propertyhive' ), |
| 117 |
4 => __( 'Enquiry updated.', 'propertyhive' ), |
| 118 |
5 => isset($_GET['revision']) ? sprintf( __( 'Enquiry restored to revision from %s', 'propertyhive' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 119 |
6 => sprintf( __( 'Enquiry published.', 'propertyhive' ), esc_url( get_permalink($post_ID) ) ), |
| 120 |
7 => __( 'Enquiry saved.', 'propertyhive' ), |
| 121 |
8 => sprintf( __( 'Enquiry submitted.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), |
| 122 |
9 => sprintf( __( 'Enquiry scheduled for: <strong>%1$s</strong>.', 'propertyhive' ), |
| 123 |
date_i18n( __( 'M j, Y @ G:i', 'propertyhive' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), |
| 124 |
10 => sprintf( __( 'Enquiry draft updated.', 'propertyhive' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), |
| 125 |
); |
| 126 |
|
| 127 |
return $messages; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Remove month filter from some property hive pages |
| 132 |
*/ |
| 133 |
public function remove_month_filter() { |
| 134 |
global $typenow; |
| 135 |
|
| 136 |
if ($typenow == 'property' || $typenow == 'contact' || $typenow == 'viewing' || $typenow == 'offer' || $typenow == 'sale') |
| 137 |
{ |
| 138 |
add_filter('months_dropdown_results', '__return_empty_array'); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Disable the auto-save functionality for certain CPT's. |
| 144 |
* |
| 145 |
* @access public |
| 146 |
* @return void |
| 147 |
*/ |
| 148 |
public function disable_autosave(){ |
| 149 |
/*global $post; |
| 150 |
|
| 151 |
if ( $post && get_post_type( $post->ID ) === 'enquiry' ) { |
| 152 |
wp_dequeue_script( 'autosave' ); |
| 153 |
}*/ |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Filters for post types |
| 158 |
*/ |
| 159 |
public function restrict_manage_posts() { |
| 160 |
global $typenow, $wp_query; |
| 161 |
|
| 162 |
switch ( $typenow ) { |
| 163 |
case 'property' : |
| 164 |
$this->property_filters(); |
| 165 |
break; |
| 166 |
case 'contact' : |
| 167 |
$this->contact_filters(); |
| 168 |
break; |
| 169 |
case 'enquiry' : |
| 170 |
$this->enquiry_filters(); |
| 171 |
break; |
| 172 |
default : |
| 173 |
break; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Show a property filter box |
| 179 |
*/ |
| 180 |
public function property_filters() { |
| 181 |
global $wp_query; |
| 182 |
|
| 183 |
// Department filtering |
| 184 |
$output = ''; |
| 185 |
|
| 186 |
$output .= $this->property_department_filter(); |
| 187 |
$output .= $this->property_availability_filter(); |
| 188 |
$output .= $this->property_location_filter(); |
| 189 |
$output .= $this->property_office_filter(); |
| 190 |
$output .= $this->property_negotiator_filter(); |
| 191 |
|
| 192 |
echo apply_filters( 'propertyhive_property_filters', $output ); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Show a property department filter box |
| 197 |
*/ |
| 198 |
public function property_department_filter() { |
| 199 |
global $wp_query; |
| 200 |
|
| 201 |
// Department filtering |
| 202 |
$output = '<select name="_department" id="dropdown_property_department">'; |
| 203 |
|
| 204 |
$output .= '<option value="">' . __( 'All Departments', 'propertyhive' ) . '</option>'; |
| 205 |
|
| 206 |
if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' ) |
| 207 |
{ |
| 208 |
$output .= '<option value="residential-sales"'; |
| 209 |
if ( isset( $_GET['_department'] ) && ! empty( $_GET['_department'] ) ) |
| 210 |
{ |
| 211 |
$output .= selected( 'residential-sales', $_GET['_department'], false ); |
| 212 |
} |
| 213 |
$output .= '>' . __( 'Residential Sales', 'propertyhive' ) . '</option>'; |
| 214 |
} |
| 215 |
if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' ) |
| 216 |
{ |
| 217 |
$output .= '<option value="residential-lettings"'; |
| 218 |
if ( isset( $_GET['_department'] ) && ! empty( $_GET['_department'] ) ) |
| 219 |
{ |
| 220 |
$output .= selected( 'residential-lettings', $_GET['_department'], false ); |
| 221 |
} |
| 222 |
$output .= '>' . __( 'Residential Lettings', 'propertyhive' ) . '</option>'; |
| 223 |
} |
| 224 |
if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' ) |
| 225 |
{ |
| 226 |
$output .= '<option value="commercial"'; |
| 227 |
if ( isset( $_GET['_department'] ) && ! empty( $_GET['_department'] ) ) |
| 228 |
{ |
| 229 |
$output .= selected( 'commercial', $_GET['_department'], false ); |
| 230 |
} |
| 231 |
$output .= '>' . __( 'Commercial', 'propertyhive' ) . '</option>'; |
| 232 |
} |
| 233 |
$output .= '</select>'; |
| 234 |
|
| 235 |
return $output; |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Show a property office filter box |
| 240 |
*/ |
| 241 |
public function property_office_filter() { |
| 242 |
global $wp_query, $post; |
| 243 |
|
| 244 |
// Department filtering |
| 245 |
$output = '<select name="_office_id" id="dropdown_property_office_id">'; |
| 246 |
|
| 247 |
$output .= '<option value="">' . __( 'All Offices', 'propertyhive' ) . '</option>'; |
| 248 |
|
| 249 |
$args = array( |
| 250 |
'post_type' => 'office', |
| 251 |
'nopaging' => true, |
| 252 |
'orderby' => 'title', |
| 253 |
'order' => 'ASC' |
| 254 |
); |
| 255 |
$office_query = new WP_Query($args); |
| 256 |
|
| 257 |
if ($office_query->have_posts()) |
| 258 |
{ |
| 259 |
while ($office_query->have_posts()) |
| 260 |
{ |
| 261 |
$office_query->the_post(); |
| 262 |
|
| 263 |
$output .= '<option value="' . $post->ID . '"'; |
| 264 |
if ( isset( $_GET['_office_id'] ) && ! empty( $_GET['_office_id'] ) ) |
| 265 |
{ |
| 266 |
$output .= selected( $post->ID, $_GET['_office_id'], false ); |
| 267 |
} |
| 268 |
$output .= '>' . get_the_title() . '</option>'; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
wp_reset_postdata(); |
| 273 |
|
| 274 |
$output .= '</select>'; |
| 275 |
|
| 276 |
return $output; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Show a property negotiator filter box |
| 281 |
*/ |
| 282 |
public function property_negotiator_filter() { |
| 283 |
global $wp_query, $post; |
| 284 |
|
| 285 |
$selected = ''; |
| 286 |
if ( isset( $_GET['_negotiator_id'] ) && ! empty( $_GET['_negotiator_id'] ) ) |
| 287 |
{ |
| 288 |
$selected = $_GET['_negotiator_id']; |
| 289 |
} |
| 290 |
|
| 291 |
$args = array( |
| 292 |
'name' => '_negotiator_id', |
| 293 |
'id' => 'dropdown_property_negotiator_id', |
| 294 |
'show_option_all' => __( 'All Negotiators', 'propertyhive' ), |
| 295 |
'selected' => $selected, |
| 296 |
'echo' => false, |
| 297 |
'role__not_in' => array('property_hive_contact') |
| 298 |
); |
| 299 |
$output = wp_dropdown_users($args); |
| 300 |
|
| 301 |
return $output; |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Show a property location filter box |
| 306 |
*/ |
| 307 |
public function property_location_filter() { |
| 308 |
global $wp_query, $post; |
| 309 |
|
| 310 |
// Department filtering |
| 311 |
$output = '<select name="_location_id" id="dropdown_property_location_id">'; |
| 312 |
|
| 313 |
$options = array( ); |
| 314 |
$args = array( |
| 315 |
'hide_empty' => false, |
| 316 |
'parent' => 0 |
| 317 |
); |
| 318 |
$terms = get_terms( 'location', $args ); |
| 319 |
|
| 320 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 321 |
{ |
| 322 |
foreach ($terms as $term) |
| 323 |
{ |
| 324 |
$options[$term->term_id] = $term->name; |
| 325 |
|
| 326 |
$args = array( |
| 327 |
'hide_empty' => false, |
| 328 |
'parent' => $term->term_id |
| 329 |
); |
| 330 |
$subterms = get_terms( 'location', $args ); |
| 331 |
|
| 332 |
if ( !empty( $subterms ) && !is_wp_error( $subterms ) ) |
| 333 |
{ |
| 334 |
foreach ($subterms as $term) |
| 335 |
{ |
| 336 |
$options[$term->term_id] = '- ' . $term->name; |
| 337 |
|
| 338 |
$args = array( |
| 339 |
'hide_empty' => false, |
| 340 |
'parent' => $term->term_id |
| 341 |
); |
| 342 |
$subsubterms = get_terms( 'location', $args ); |
| 343 |
|
| 344 |
if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) ) |
| 345 |
{ |
| 346 |
foreach ($subsubterms as $term) |
| 347 |
{ |
| 348 |
$options[$term->term_id] = '- ' . $term->name; |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
$output .= '<option value="">' . __( 'All Locations', 'propertyhive' ) . '</option>'; |
| 357 |
|
| 358 |
if ( !empty($options) ) |
| 359 |
{ |
| 360 |
foreach ( $options as $value => $label ) |
| 361 |
{ |
| 362 |
$output .= '<option value="' . $value . '"'; |
| 363 |
if ( isset( $_GET['_location_id'] ) && ! empty( $_GET['_location_id'] ) ) |
| 364 |
{ |
| 365 |
$output .= selected( $value, $_GET['_location_id'], false ); |
| 366 |
} |
| 367 |
$output .= '>' . $label . '</option>'; |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
$output .= '</select>'; |
| 372 |
|
| 373 |
return $output; |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* Show a property availability filter box |
| 378 |
*/ |
| 379 |
public function property_availability_filter() { |
| 380 |
global $wp_query, $post; |
| 381 |
|
| 382 |
// Department filtering |
| 383 |
$output = '<select name="_availability_id" id="dropdown_property_availability_id">'; |
| 384 |
|
| 385 |
$options = array( ); |
| 386 |
$args = array( |
| 387 |
'hide_empty' => false, |
| 388 |
'parent' => 0 |
| 389 |
); |
| 390 |
$terms = get_terms( 'availability', $args ); |
| 391 |
|
| 392 |
if ( !empty( $terms ) && !is_wp_error( $terms ) ) |
| 393 |
{ |
| 394 |
foreach ($terms as $term) |
| 395 |
{ |
| 396 |
$options[$term->term_id] = $term->name; |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
$output .= '<option value="">' . __( 'All Availabilities', 'propertyhive' ) . '</option>'; |
| 401 |
|
| 402 |
if ( !empty($options) ) |
| 403 |
{ |
| 404 |
foreach ( $options as $value => $label ) |
| 405 |
{ |
| 406 |
$output .= '<option value="' . $value . '"'; |
| 407 |
if ( isset( $_GET['_availability_id'] ) && ! empty( $_GET['_availability_id'] ) ) |
| 408 |
{ |
| 409 |
$output .= selected( $value, $_GET['_availability_id'], false ); |
| 410 |
} |
| 411 |
$output .= '>' . $label . '</option>'; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
$output .= '</select>'; |
| 416 |
|
| 417 |
return $output; |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* Show a contact filter box |
| 422 |
*/ |
| 423 |
public function contact_filters() { |
| 424 |
global $wp_query; |
| 425 |
|
| 426 |
// Type filtering |
| 427 |
$options = array(); |
| 428 |
|
| 429 |
// Owners |
| 430 |
$option = '<option value="owner"'; |
| 431 |
if ( isset( $_GET['_contact_type'] ) && ! empty( $_GET['_contact_type'] ) ) |
| 432 |
{ |
| 433 |
$option .= selected( 'owner', $_GET['_contact_type'], false ); |
| 434 |
} |
| 435 |
$option .= '>' . __( 'Owners and Landlords', 'propertyhive' ) . '</option>'; |
| 436 |
|
| 437 |
$options[] = $option; |
| 438 |
|
| 439 |
// Applicants |
| 440 |
$option = '<option value="applicant"'; |
| 441 |
if ( isset( $_GET['_contact_type'] ) && ! empty( $_GET['_contact_type'] ) ) |
| 442 |
{ |
| 443 |
$option .= selected( 'applicant', $_GET['_contact_type'], false ); |
| 444 |
} |
| 445 |
$option .= '>' . __( 'Applicants', 'propertyhive' ) . '</option>'; |
| 446 |
|
| 447 |
$options[] = $option; |
| 448 |
|
| 449 |
// Third Parties |
| 450 |
$option = '<option value="thirdparty"'; |
| 451 |
if ( isset( $_GET['_contact_type'] ) && ! empty( $_GET['_contact_type'] ) ) |
| 452 |
{ |
| 453 |
$option .= selected( 'thirdparty', $_GET['_contact_type'], false ); |
| 454 |
} |
| 455 |
$option .= '>' . __( 'Third Party Contacts', 'propertyhive' ) . '</option>'; |
| 456 |
|
| 457 |
$options[] = $option; |
| 458 |
|
| 459 |
$options = apply_filters( 'propertyhive_contact_filter_options', $options ); |
| 460 |
|
| 461 |
$output = ''; |
| 462 |
if (count($options) > 1) |
| 463 |
{ |
| 464 |
$output = '<select name="_contact_type" id="dropdown_contact_type">'; |
| 465 |
|
| 466 |
$output .= '<option value="">' . __( 'Show all contact types', 'propertyhive' ) . '</option>'; |
| 467 |
|
| 468 |
$output .= implode("", $options); |
| 469 |
|
| 470 |
$output .= '</select>'; |
| 471 |
} |
| 472 |
|
| 473 |
echo $output; |
| 474 |
} |
| 475 |
|
| 476 |
/** |
| 477 |
* Show an enquiry filter box |
| 478 |
*/ |
| 479 |
public function enquiry_filters() { |
| 480 |
global $wp_query; |
| 481 |
|
| 482 |
// Department filtering |
| 483 |
$output = ''; |
| 484 |
|
| 485 |
$output .= $this->enquiry_status_filter(); |
| 486 |
$output .= $this->enquiry_source_filter(); |
| 487 |
|
| 488 |
echo apply_filters( 'propertyhive_enquiry_filters', $output ); |
| 489 |
} |
| 490 |
|
| 491 |
/** |
| 492 |
* Show an enquiry status filter box |
| 493 |
*/ |
| 494 |
public function enquiry_status_filter() { |
| 495 |
global $wp_query; |
| 496 |
|
| 497 |
// Status filtering |
| 498 |
$output = '<select name="_status" id="dropdown_enquiry_status">'; |
| 499 |
|
| 500 |
$output .= '<option value="open"'; |
| 501 |
if ( isset( $_GET['_status'] ) && ! empty( $_GET['_status'] ) ) |
| 502 |
{ |
| 503 |
$output .= selected( 'open', $_GET['_status'], false ); |
| 504 |
} |
| 505 |
$output .= '>' . __( 'Open', 'propertyhive' ) . '</option>'; |
| 506 |
$output .= '<option value="closed"'; |
| 507 |
if ( isset( $_GET['_status'] ) && ! empty( $_GET['_status'] ) ) |
| 508 |
{ |
| 509 |
$output .= selected( 'closed', $_GET['_status'], false ); |
| 510 |
} |
| 511 |
$output .= '>' . __( 'Closed', 'propertyhive' ) . '</option>'; |
| 512 |
|
| 513 |
$output .= '</select>'; |
| 514 |
|
| 515 |
return $output; |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Show an enquiry source filter box |
| 520 |
*/ |
| 521 |
public function enquiry_source_filter() { |
| 522 |
global $wp_query; |
| 523 |
|
| 524 |
// Status filtering |
| 525 |
$output = '<select name="_source" id="dropdown_enquiry_source">'; |
| 526 |
|
| 527 |
$output .= '<option value="">' . __( 'Show all sources', 'propertyhive' ) . '</option>'; |
| 528 |
|
| 529 |
$output .= '<option value="office"'; |
| 530 |
if ( isset( $_GET['_source'] ) && ! empty( $_GET['_source'] ) ) |
| 531 |
{ |
| 532 |
$output .= selected( 'office', $_GET['_source'], false ); |
| 533 |
} |
| 534 |
$output .= '>' . __( 'Office', 'propertyhive' ) . '</option>'; |
| 535 |
$output .= '<option value="website"'; |
| 536 |
if ( isset( $_GET['_source'] ) && ! empty( $_GET['_source'] ) ) |
| 537 |
{ |
| 538 |
$output .= selected( 'website', $_GET['_source'], false ); |
| 539 |
} |
| 540 |
$output .= '>' . __( 'Website', 'propertyhive' ) . '</option>'; |
| 541 |
|
| 542 |
$output .= '</select>'; |
| 543 |
|
| 544 |
return $output; |
| 545 |
} |
| 546 |
|
| 547 |
/** |
| 548 |
* Filters and sorting handler |
| 549 |
* @param array $vars |
| 550 |
* @return array |
| 551 |
*/ |
| 552 |
public function request_query( $vars ) { |
| 553 |
global $typenow, $wp_query; |
| 554 |
|
| 555 |
if ( !isset($vars['meta_query']) ) { $vars['meta_query'] = array(); } |
| 556 |
if ( !isset($vars['tax_query']) ) { $vars['tax_query'] = array(); } |
| 557 |
|
| 558 |
if ( 'property' === $typenow ) |
| 559 |
{ |
| 560 |
if ( ! empty( $_GET['_department'] ) ) { |
| 561 |
$vars['meta_query'][] = array( |
| 562 |
'key' => '_department', |
| 563 |
'value' => sanitize_text_field( $_GET['_department'] ), |
| 564 |
); |
| 565 |
} |
| 566 |
if ( ! empty( $_GET['_office_id'] ) ) { |
| 567 |
$vars['meta_query'][] = array( |
| 568 |
'key' => '_office_id', |
| 569 |
'value' => sanitize_text_field( $_GET['_office_id'] ), |
| 570 |
); |
| 571 |
} |
| 572 |
if ( ! empty( $_GET['_negotiator_id'] ) ) { |
| 573 |
$vars['meta_query'][] = array( |
| 574 |
'key' => '_negotiator_id', |
| 575 |
'value' => sanitize_text_field( $_GET['_negotiator_id'] ), |
| 576 |
); |
| 577 |
} |
| 578 |
if ( ! empty( $_GET['_location_id'] ) ) { |
| 579 |
$vars['tax_query'][] = array( |
| 580 |
'taxonomy' => 'location', |
| 581 |
'terms' => ( (is_array($_GET['_location_id'])) ? $_GET['_location_id'] : array( $_GET['_location_id'] ) ) |
| 582 |
); |
| 583 |
} |
| 584 |
if ( ! empty( $_GET['_availability_id'] ) ) { |
| 585 |
$vars['tax_query'][] = array( |
| 586 |
'taxonomy' => 'availability', |
| 587 |
'terms' => ( (is_array($_GET['_availability_id'])) ? $_GET['_availability_id'] : array( $_GET['_availability_id'] ) ) |
| 588 |
); |
| 589 |
} |
| 590 |
} |
| 591 |
elseif ( 'contact' === $typenow ) |
| 592 |
{ |
| 593 |
if ( ! empty( $_GET['_contact_type'] ) ) { |
| 594 |
//$vars['meta_key '] = '_contact_types'; |
| 595 |
//$vars['meta_value'] = sanitize_text_field( $_GET['_contact_type'] ); |
| 596 |
//$vars['meta_compare '] = 'LIKE'; |
| 597 |
$vars['meta_query'] = array( |
| 598 |
array( |
| 599 |
'key' => '_contact_types', |
| 600 |
'value' => sanitize_text_field( $_GET['_contact_type'] ), |
| 601 |
'compare' => 'LIKE' |
| 602 |
) |
| 603 |
); |
| 604 |
} |
| 605 |
} |
| 606 |
elseif ( 'enquiry' === $typenow ) |
| 607 |
{ |
| 608 |
if ( ! empty( $_GET['_status'] ) ) { |
| 609 |
$vars['meta_key'] = '_status'; |
| 610 |
$vars['meta_value'] = sanitize_text_field( $_GET['_status'] ); |
| 611 |
} |
| 612 |
if ( ! empty( $_GET['_source'] ) ) { |
| 613 |
$vars['meta_key'] = '_source'; |
| 614 |
$vars['meta_value'] = sanitize_text_field( $_GET['_source'] ); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
return $vars; |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* search_property_reference function. |
| 623 |
* |
| 624 |
* @access public |
| 625 |
* @param string $where (default: '') |
| 626 |
* @return string (modified where clause) |
| 627 |
*/ |
| 628 |
public function search_property_reference( $where = '' ) { |
| 629 |
global $typenow; |
| 630 |
|
| 631 |
if ( $typenow == 'property' && isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) |
| 632 |
{ |
| 633 |
//$where .= 'hel'; |
| 634 |
} |
| 635 |
|
| 636 |
return $where; |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* Removes variations etc belonging to a deleted post, and clears transients |
| 641 |
* |
| 642 |
* @access public |
| 643 |
* @param mixed $id ID of post being deleted |
| 644 |
* @return void |
| 645 |
*/ |
| 646 |
public function delete_post( $id ) { |
| 647 |
/*global $propertyhive, $wpdb; |
| 648 |
|
| 649 |
if ( ! current_user_can( 'delete_posts' ) ) |
| 650 |
return; |
| 651 |
|
| 652 |
if ( $id > 0 ) { |
| 653 |
|
| 654 |
$post_type = get_post_type( $id ); |
| 655 |
|
| 656 |
switch( $post_type ) { |
| 657 |
case 'property' : |
| 658 |
ph_delete_property_transients(); |
| 659 |
break; |
| 660 |
case 'contact' : |
| 661 |
ph_delete_contact_transients(); |
| 662 |
break; |
| 663 |
case 'enquiry' : |
| 664 |
ph_delete_enquiry_transients(); |
| 665 |
break; |
| 666 |
} |
| 667 |
}*/ |
| 668 |
} |
| 669 |
|
| 670 |
/** |
| 671 |
* propertyhive_trash_post function. |
| 672 |
* |
| 673 |
* @access public |
| 674 |
* @param mixed $id |
| 675 |
* @return void |
| 676 |
*/ |
| 677 |
public function trash_post( $id ) { |
| 678 |
/*if ( $id > 0 ) { |
| 679 |
|
| 680 |
$post_type = get_post_type( $id ); |
| 681 |
|
| 682 |
|
| 683 |
}*/ |
| 684 |
} |
| 685 |
|
| 686 |
/** |
| 687 |
* propertyhive_untrash_post function. |
| 688 |
* |
| 689 |
* @access public |
| 690 |
* @param mixed $id |
| 691 |
* @return void |
| 692 |
*/ |
| 693 |
public function untrash_post( $id ) { |
| 694 |
/*if ( $id > 0 ) { |
| 695 |
|
| 696 |
$post_type = get_post_type( $id ); |
| 697 |
|
| 698 |
}*/ |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
endif; |
| 703 |
|
| 704 |
return new PH_Admin_Post_Types(); |