PluginProbe
Property Hive / 1.4.62
Property Hive v1.4.62
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / post-types / class-ph-admin-cpt-property.php

class-ph-admin-cpt-property.php in Property Hive 1.4.62, at includes/admin/post-types/class-ph-admin-cpt-property.php

767 lines 23.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin functions for the property post type
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin/Post Types
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Admin_CPT' ) ) {
16 include( 'class-ph-admin-cpt.php' );
17 }
18
19 if ( ! class_exists( 'PH_Admin_CPT_Property' ) ) :
20
21 /**
22 * PH_Admin_CPT_Property Class
23 */
24 class PH_Admin_CPT_Property extends PH_Admin_CPT {
25
26 /**
27 * Constructor
28 */
29 public function __construct() {
30 $this->type = 'property';
31
32 // Admin notices
33 add_action( 'admin_notices', array( $this, 'property_admin_notices') );
34
35 // Post title fields
36 add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
37
38 // Featured image text
39 //add_filter( 'gettext', array( $this, 'featured_image_gettext' ) );
40 //add_filter( 'media_view_strings', array( $this, 'media_view_strings' ), 10, 2 );
41
42 // Visibility option
43 //add_action( 'post_submitbox_misc_actions', array( $this, 'property_data_visibility' ) );
44
45 // Before data updates
46 add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
47 add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
48
49 // Admin Columns
50 add_filter( 'manage_edit-property_columns', array( $this, 'edit_columns' ) );
51 add_action( 'manage_property_posts_custom_column', array( $this, 'custom_columns' ), 2 );
52 add_filter( 'manage_edit-property_sortable_columns', array( $this, 'custom_columns_sort' ) );
53 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
54
55 // Sort link
56 add_filter( 'views_edit-property', array( $this, 'remove_mine' ) );
57
58 // Prouct filtering
59 /*add_action( 'restrict_manage_posts', array( $this, 'property_filters' ) );
60 add_filter( 'parse_query', array( $this, 'property_filters_query' ) );*/
61
62 // Enhanced search
63 add_filter( 'posts_search', array( $this, 'property_search' ) );
64
65 // Maintain hierarchy of terms
66 /*add_filter( 'wp_terms_checklist_args', array( $this, 'disable_checked_ontop' ) );*/
67
68 // Bulk / quick edit
69 add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
70 /*add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );*/
71 add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );
72
73 // Uploads
74 add_filter( 'upload_dir', array( $this, 'upload_dir' ) );
75 add_action( 'media_upload_downloadable_product', array( $this, 'media_upload_downloadable_product' ) );
76 //add_filter( 'mod_rewrite_rules', array( $this, 'ms_protect_download_rewite_rules' ) );
77
78 // Download permissions
79 //add_action( 'propertyhive_process_product_file_download_paths', array( $this, 'process_product_file_download_paths' ), 10, 3 );*/
80
81 // Call PH_Admin_CPT constructor
82 parent::__construct();
83 }
84
85 /**
86 * Output admin notices relating to property
87 */
88 public function property_admin_notices()
89 {
90 global $post;
91
92 $screen = get_current_screen();
93 if ($screen->id == 'property' && $post->post_type == 'property' && $post->post_parent != 0 && $post->post_parent != '')
94 {
95 $property = new PH_Property((int)$post->post_parent);
96 $message = __( "This property is a unit belonging to", 'propertyhive' ) . ' <a href="' . get_edit_post_link( $post->post_parent ) . '">' . $property->get_formatted_full_address() . '</a>';
97 echo "<div class=\"notice notice-info\"> <p>$message</p></div>";
98 }
99 }
100
101 /**
102 * Check if we're editing or adding a property
103 * @return boolean
104 */
105 private function is_editing_property() {
106 if ( ! empty( $_GET['post_type'] ) && 'property' == $_GET['post_type'] ) {
107 return true;
108 }
109 if ( ! empty( $_GET['post'] ) && 'property' == get_post_type( (int)$_GET['post'] ) ) {
110 return true;
111 }
112 if ( ! empty( $_REQUEST['post_id'] ) && 'property' == get_post_type( (int)$_REQUEST['post_id'] ) ) {
113 return true;
114 }
115 return false;
116 }
117
118 /**
119 * Change title boxes in admin.
120 * @param string $text
121 * @param object $post
122 * @return string
123 */
124 public function enter_title_here( $text, $post ) {
125 if ( is_admin() && $post->post_type == 'property' ) {
126 return __( 'Enter Display Address', 'propertyhive' );
127 }
128
129 return $text;
130 }
131
132 /**
133 * Some functions, like the term recount, require the visibility to be set prior. Lets save that here.
134 *
135 * @param int $post_id
136 */
137 public function pre_post_update( $post_id ) {
138
139 }
140
141 /**
142 * Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
143 *
144 * @param array $data
145 * @return array
146 */
147 public function wp_insert_post_data( $data ) {
148
149
150 return $data;
151 }
152
153 /**
154 * Change the columns shown in admin.
155 */
156 public function edit_columns( $existing_columns ) {
157
158 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
159 $existing_columns = array();
160 }
161
162 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
163
164 $columns = array();
165 $columns['cb'] = '<input type="checkbox" />';
166 $columns['thumb'] = '<span class="ph-image tips" data-tip="' . __( 'Image', 'propertyhive' ) . '">' . __( 'Image', 'propertyhive' ) . '</span>';
167
168 $columns['address'] = __( 'Address', 'propertyhive' );
169
170 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
171 {
172 $columns['size'] = __( 'Size', 'propertyhive' );
173 }
174
175 $columns['price'] = __( 'Price', 'propertyhive' );
176
177 $columns['status'] = __( 'Marketing Status', 'propertyhive' );
178
179 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
180 {
181 $columns['owner'] = __( 'Owner / Landlord', 'propertyhive' );
182 }
183
184 $columns['negotiator_office'] = __( 'Neg / Office', 'propertyhive' );
185
186 return array_merge( $columns, $existing_columns );
187 }
188
189 /**
190 * Define our custom columns shown in admin.
191 * @param string $column
192 */
193 public function custom_columns( $column ) {
194 global $post, $propertyhive, $the_property;
195
196 if ( empty( $the_property ) || $the_property->ID != $post->ID )
197 {
198 $the_property = new PH_Property( $post->ID );
199 }
200
201 switch ( $column ) {
202 case 'thumb' :
203
204 $thumb_src = $the_property->get_main_photo_src();
205
206 echo '<a href="' . get_edit_post_link( $post->ID ) . '">';
207 if ($thumb_src !== FALSE)
208 {
209 echo '<img src="' . $thumb_src . '" alt="" width="50">';
210 }
211 else
212 {
213 // placeholder image
214 }
215 echo '</a>';
216 break;
217 case 'address' :
218
219 $edit_link = get_edit_post_link( $post->ID );
220 //$title = _draft_or_post_title();
221 $title = $the_property->get_formatted_summary_address();
222 if ( empty($title) )
223 {
224 $title = __( '(no address entered)' );
225 }
226 $post_type_object = get_post_type_object( $post->post_type );
227 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
228
229 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a>';
230
231 $post_status = get_post_status( $post->ID );
232 $post_title_output = '';
233 if ( $post_status == 'draft' || $post_status == 'private' )
234 {
235 $post_title_output = ucfirst($post_status);
236 }
237 $post_title_output = apply_filters( 'propertyhive_admin_property_column_post_address_output', $post_title_output );
238 if ( $post_title_output != '' )
239 {
240 echo ' - ' . $post_title_output;
241 }
242
243 echo '</strong>';
244
245 // Excerpt view
246 if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
247 echo apply_filters( 'the_excerpt', $post->post_excerpt );
248 }
249
250 if ( $the_property->bedrooms != '' || $the_property->property_type != '' )
251 {
252 echo '<br>' . ( ( ( $the_property->department == 'residential-sales' || $the_property->department == 'residential-lettings' ) && $the_property->bedrooms != '' ) ? $the_property->bedrooms . ' ' . __( 'bedroom', 'propertyhive' ) . ' ' : '' ) . $the_property->property_type;
253 }
254
255 // Get actions
256 $actions = array();
257
258 $actions['ref'] = 'Ref: ' . $the_property->_reference_number;
259
260 //$actions['id'] = 'ID: ' . $post->ID;
261
262 if ( $can_edit_post && 'trash' != $post->post_status ) {
263 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'propertyhive' ) ) . '">' . __( 'Edit', 'propertyhive' ) . '</a>';
264 }
265 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
266 if ( 'trash' == $post->post_status ) {
267 $actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'propertyhive' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'propertyhive' ) . '</a>';
268 } elseif ( EMPTY_TRASH_DAYS ) {
269 //$actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID ) . '">' . __( 'Trash', 'propertyhive' ) . '</a>';
270 }
271
272 if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
273 $actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID, '', true ) . '">' . __( 'Delete Permanently', 'propertyhive' ) . '</a>';
274 }
275 }
276 if ( $post_type_object->public ) {
277 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
278 if ( $can_edit_post )
279 $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'Preview', 'propertyhive' ) . '</a>';
280 } elseif ( 'trash' != $post->post_status ) {
281 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'View', 'propertyhive' ) . '</a>';
282 }
283 }
284
285 $actions = apply_filters( 'post_row_actions', $actions, $post );
286
287 echo '<div class="row-actions">';
288
289 $i = 0;
290 $action_count = sizeof($actions);
291
292 foreach ( $actions as $action => $link ) {
293 ++$i;
294 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
295 echo '<span class="' . $action . '">' . $link . $sep . '</span>';
296 }
297 echo '</div>';
298
299 get_inline_data( $post );
300
301 /* Custom inline data for propertyhive */
302 /*echo '
303 <div class="hidden" id="propertyhive_inline_' . $post->ID . '">
304 <div class="on_market">' . $the_property->on_market . '</div>
305 <div class="featured">' . $the_property->featured . '</div>
306 </div>
307 ';*/
308
309 break;
310 case 'size' :
311
312 $floor_area = $the_property->get_formatted_floor_area();
313 if ( $floor_area != '' )
314 {
315 echo 'Floor Area: ' . $floor_area . '<br>';
316 }
317 $site_area = $the_property->get_formatted_site_area();
318 if ( $site_area != '' )
319 {
320 echo 'Site Area: ' . $site_area;
321 }
322
323 if ( $floor_area == '' && $site_area == '' )
324 {
325 echo '-';
326 }
327
328 break;
329 case 'price' :
330
331 $price = $the_property->get_formatted_price();
332 if ( $price == '' )
333 {
334 $price = '-';
335 }
336 else
337 {
338 if ( $the_property->_department == 'residential-sales' && $the_property->price_qualifier != '' )
339 {
340 $price .= '<br>' . $the_property->price_qualifier;
341 }
342 }
343 echo $price;
344
345 break;
346 case 'status' :
347
348 $term_list = wp_get_post_terms($post->ID, 'availability', array("fields" => "names"));
349
350 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
351 {
352 echo $term_list[0]. '<br>';
353 }
354
355 if (isset($the_property->_on_market) && $the_property->_on_market == 'yes')
356 {
357 echo __( 'On The Market', 'propertyhive' );
358 }
359 else
360 {
361 echo __( 'Not On The Market', 'propertyhive' );
362 }
363
364 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
365 {
366 echo '<br>' . __( 'Featured', 'propertyhive' );
367 }
368
369 $marketing_flags = $the_property->marketing_flag;
370 if ( $marketing_flags != '' )
371 {
372 echo '<br>' . implode( "<br>", explode( ",", $marketing_flags ) );
373 }
374
375 break;
376 case 'owner' :
377
378 $owner_contact_ids = $the_property->_owner_contact_id;
379 if (
380 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
381 ||
382 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
383 )
384 {
385 if ( !is_array($owner_contact_ids) )
386 {
387 $owner_contact_ids = array($owner_contact_ids);
388 }
389
390 foreach ( $owner_contact_ids as $owner_contact_id )
391 {
392 echo get_the_title($owner_contact_id) . '<br>';
393 if ( count($owner_contact_ids) == 1 )
394 {
395 echo '<div class="row-actions">';
396 echo 'T: ' . get_post_meta($owner_contact_id, '_telephone_number', TRUE) . '<br>';
397 echo 'E: ' . get_post_meta($owner_contact_id, '_email_address', TRUE);
398 echo '</div>';
399 }
400 }
401 }
402 else
403 {
404 echo '-';
405 }
406 break;
407 case 'negotiator_office' :
408
409 $user_info = get_userdata($the_property->_negotiator_id);
410
411 if ($user_info !== FALSE)
412 {
413 echo $user_info->display_name . '<br>';
414 }
415
416 if ($the_property->_office_id != '')
417 {
418 echo get_the_title($the_property->_office_id);
419 }
420
421 break;
422 default :
423 break;
424 }
425 }
426
427 /**
428 * Search by ID, address and reference number
429 *
430 * @param string $where
431 * @return string
432 */
433 public function property_search( $where ) {
434 global $pagenow, $wpdb, $wp;
435
436 if ( 'edit.php' != $pagenow || ! is_search() || ! isset( $wp->query_vars['s'] ) || 'property' != $wp->query_vars['post_type'] ) {
437 return $where;
438 }
439
440 if ( trim($wp->query_vars['s']) == '' )
441 {
442 return $where;
443 }
444
445 $search_ids = array();
446 $terms = explode( ',', $wp->query_vars['s'] );
447
448 foreach ( $terms as $term )
449 {
450 if ( is_numeric( $term ) )
451 {
452 $search_ids[] = $term;
453 }
454
455 // Attempt to get an ID by searching for address and reference number
456 $query = $wpdb->prepare(
457 "SELECT
458 ID
459 FROM
460 {$wpdb->posts}
461 INNER JOIN {$wpdb->postmeta} AS mt1 ON {$wpdb->posts}.ID = mt1.post_id
462 WHERE
463 (
464 (mt1.meta_key='_address_name_number' AND mt1.meta_value LIKE %s)
465 OR
466 (mt1.meta_key='_address_street' AND mt1.meta_value LIKE %s)
467 OR
468 (mt1.meta_key='_address_2' AND mt1.meta_value LIKE %s)
469 OR
470 (mt1.meta_key='_address_3' AND mt1.meta_value LIKE %s)
471 OR
472 (mt1.meta_key='_address_4' AND mt1.meta_value LIKE %s)
473 OR
474 (mt1.meta_key='_address_postcode' AND mt1.meta_value LIKE %s)
475 OR
476 (mt1.meta_key='_reference_number' AND mt1.meta_value = %s)
477 )
478 AND
479 post_type='property'
480 GROUP BY ID
481 ",
482 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
483 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
484 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
485 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
486 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
487 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
488 '' . $wpdb->esc_like( ph_clean( $term ) ) . ''
489 );
490 $search_posts = $wpdb->get_results( $query );
491 $search_posts = wp_list_pluck( $search_posts, 'ID' );
492
493 if ( sizeof( $search_posts ) > 0 )
494 {
495 $search_ids = array_merge( $search_ids, $search_posts );
496 }
497 }
498 $search_ids = array_filter( array_unique( array_map( 'absint', $search_ids ) ) );
499 if ( sizeof( $search_ids ) > 0 )
500 {
501 $where = str_replace( 'AND (((', "AND ( ({$wpdb->posts}.ID IN (" . implode( ',', $search_ids ) . ")) OR ((", $where );
502 }
503 return $where;
504 }
505
506 /**
507 * Make property columns sortable
508 *
509 * https://gist.github.com/906872
510 *
511 * @access public
512 * @param mixed $columns
513 * @return array
514 */
515 public function custom_columns_sort( $columns ) {
516 $custom = array(
517 'price' => '_price_actual',
518 'size' => '_floor_area_from_sqft'
519 );
520 return wp_parse_args( $custom, $columns );
521 }
522
523 /**
524 * Property column orderby
525 *
526 * @access public
527 * @param mixed $vars
528 * @return array
529 */
530 public function custom_columns_orderby( $vars ) {
531 if ( isset( $vars['orderby'] ) ) {
532 if ( '_price_actual' == $vars['orderby'] ) {
533 $vars = array_merge( $vars, array(
534 'meta_key' => '_price_actual',
535 'orderby' => 'meta_value_num'
536 ) );
537 }
538 elseif ( '_floor_area_from_sqft' == $vars['orderby'] ) {
539 $vars = array_merge( $vars, array(
540 'meta_key' => '_floor_area_from_sqft',
541 'orderby' => 'meta_value_num'
542 ) );
543 }
544 }
545
546 return $vars;
547 }
548
549 /**
550 * Remove 'Mine' view option
551 *
552 * @param array $views
553 * @return array
554 */
555 public function remove_mine( $views ) {
556 global $post_type, $wp_query;
557
558 if ( ! current_user_can('edit_others_pages') ) {
559 return $views;
560 }
561
562 if( isset( $views['mine'] ) )
563 unset( $views['mine'] );
564
565 return $views;
566 }
567
568 /**
569 * Show a category filter box
570 */
571 public function propertyhive_filters() {
572 global $typenow, $wp_query;
573
574 if ( 'property' != $typenow ) {
575 return;
576 }
577
578 echo apply_filters( 'propertyhive_property_filters', $output );
579 }
580
581 /**
582 * Filter the products in admin based on options
583 *
584 * @param mixed $query
585 */
586 public function property_filters_query( $query ) {
587 global $typenow, $wp_query;
588
589 if ( 'property' == $typenow ) {
590
591 }
592 }
593
594 /**
595 * Maintain term hierarchy when editing a property.
596 * @param array $args
597 * @return array
598 */
599 public function disable_checked_ontop( $args ) {
600 if ( 'product_cat' == $args['taxonomy'] ) {
601 $args['checked_ontop'] = false;
602 }
603
604 return $args;
605 }
606
607 /**
608 * Custom bulk edit - form
609 *
610 * @access public
611 * @param mixed $column_name
612 * @param mixed $post_type
613 */
614 public function bulk_edit( $column_name, $post_type ) {
615 if ( 'price' != $column_name || 'property' != $post_type ) {
616 return;
617 }
618
619 include( PH()->plugin_path() . '/includes/admin/views/html-bulk-edit-property.php' );
620 }
621
622 /**
623 * Custom quick edit - form
624 *
625 * @access public
626 * @param mixed $column_name
627 * @param mixed $post_type
628 */
629 public function quick_edit( $column_name, $post_type ) {
630 if ( 'price' != $column_name || 'property' != $post_type ) {
631 return;
632 }
633
634 include( PH()->plugin_path() . '/includes/admin/views/html-quick-edit-property.php' );
635 }
636
637 /**
638 * Quick and bulk edit saving
639 *
640 * @access public
641 * @param int $post_id
642 * @param WP_Post $post
643 * @return int
644 */
645 public function bulk_and_quick_edit_save_post( $post_id, $post ) {
646 // If this is an autosave, our form has not been submitted, so we don't want to do anything.
647 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
648 return $post_id;
649 }
650
651 // Don't save revisions and autosaves
652 if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
653 return $post_id;
654 }
655
656 // Check post type is product
657 if ( 'property' != $post->post_type ) {
658 return $post_id;
659 }
660
661 // Check user permission
662 if ( ! current_user_can( 'edit_post', $post_id ) ) {
663 return $post_id;
664 }
665
666 // Check nonces
667 if ( ! isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) ) {
668 return $post_id;
669 }
670 if ( isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_quick_edit_nonce'], 'propertyhive_quick_edit_nonce' ) ) {
671 return $post_id;
672 }
673 if ( isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_bulk_edit_nonce'], 'propertyhive_bulk_edit_nonce' ) ) {
674 return $post_id;
675 }
676
677 // Get the product and save
678 $property = get_property( $post );
679
680 if ( ! empty( $_REQUEST['propertyhive_quick_edit'] ) ) {
681 $this->quick_edit_save( $post_id, $property );
682 } else {
683 $this->bulk_edit_save( $post_id, $property );
684 }
685
686 // Clear transient
687 //ph_delete_property_transients( $post_id );
688
689 return $post_id;
690 }
691
692 /**
693 * Quick edit
694 */
695 private function quick_edit_save( $post_id, $property ) {
696 global $wpdb;
697
698 /*
699 // Save fields
700 if ( isset( $_REQUEST['_address_name_number'] ) ) {
701 update_post_meta( $post_id, '_address_name_number', ph_clean( $_REQUEST['_address_name_number'] ) );
702 }*/
703
704 do_action( 'propertyhive_property_quick_edit_save', $property );
705 }
706
707 /**
708 * Bulk edit
709 */
710 public function bulk_edit_save( $post_id, $property ) {
711
712 // Save fields
713 if ( ! empty( $_REQUEST['_on_market'] ) )
714 {
715 $on_market = ph_clean( $_REQUEST['_on_market'] );
716 if ( $_REQUEST['_on_market'] != 'yes' ) { $on_market = ''; } // can only be 'yes' or blank
717 update_post_meta( $post_id, '_on_market', ph_clean( $on_market ) );
718 }
719
720 if ( ! empty( $_REQUEST['_availability'] ) && is_numeric( $_REQUEST['_availability'] ) )
721 {
722 wp_set_post_terms( $post_id, (int)$_REQUEST['_availability'], 'availability' );
723 }
724
725 if ( ! empty( $_REQUEST['_negotiator_id'] ) && is_numeric( $_REQUEST['_negotiator_id'] ) && $_REQUEST['_negotiator_id'] != '-1' )
726 {
727 update_post_meta( $post_id, '_negotiator_id', (int)$_REQUEST['_negotiator_id'] );
728 }
729
730 if ( ! empty( $_REQUEST['_office_id'] ) && is_numeric( $_REQUEST['_office_id'] ) )
731 {
732 update_post_meta( $post_id, '_office_id', (int)$_REQUEST['_office_id'] );
733 }
734
735 do_action( 'propertyhive_property_bulk_edit_save', $property );
736 }
737
738 /**
739 * Filter the directory for uploads.
740 *
741 * @param array $pathdata
742 * @return array
743 */
744 public function upload_dir( $pathdata ) {
745 // Change upload dir for downloadable files
746 if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) {
747 if ( empty( $pathdata['subdir'] ) ) {
748 $pathdata['path'] = $pathdata['path'] . '/propertyhive_uploads';
749 $pathdata['url'] = $pathdata['url']. '/propertyhive_uploads';
750 $pathdata['subdir'] = '/propertyhive_uploads';
751 } else {
752 $new_subdir = '/propertyhive_uploads' . $pathdata['subdir'];
753
754 $pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
755 $pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
756 $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
757 }
758 }
759
760 return $pathdata;
761 }
762 }
763
764 endif;
765
766 return new PH_Admin_CPT_Property();
767