PluginProbe
Property Hive / 1.4.60
Property Hive v1.4.60
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.60, at includes/admin/post-types/class-ph-admin-cpt-property.php

759 lines 22.8 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 $columns['owner'] = __( 'Owner / Landlord', 'propertyhive' );
180
181 $columns['negotiator_office'] = __( 'Neg / Office', 'propertyhive' );
182
183 return array_merge( $columns, $existing_columns );
184 }
185
186 /**
187 * Define our custom columns shown in admin.
188 * @param string $column
189 */
190 public function custom_columns( $column ) {
191 global $post, $propertyhive, $the_property;
192
193 if ( empty( $the_property ) || $the_property->ID != $post->ID )
194 {
195 $the_property = new PH_Property( $post->ID );
196 }
197
198 switch ( $column ) {
199 case 'thumb' :
200
201 $thumb_src = $the_property->get_main_photo_src();
202
203 echo '<a href="' . get_edit_post_link( $post->ID ) . '">';
204 if ($thumb_src !== FALSE)
205 {
206 echo '<img src="' . $thumb_src . '" alt="" width="50">';
207 }
208 else
209 {
210 // placeholder image
211 }
212 echo '</a>';
213 break;
214 case 'address' :
215
216 $edit_link = get_edit_post_link( $post->ID );
217 //$title = _draft_or_post_title();
218 $title = $the_property->get_formatted_summary_address();
219 if ( empty($title) )
220 {
221 $title = __( '(no address entered)' );
222 }
223 $post_type_object = get_post_type_object( $post->post_type );
224 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
225
226 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a>';
227
228 $post_status = get_post_status( $post->ID );
229 $post_title_output = '';
230 if ( $post_status == 'draft' || $post_status == 'private' )
231 {
232 $post_title_output = ucfirst($post_status);
233 }
234 $post_title_output = apply_filters( 'propertyhive_admin_property_column_post_address_output', $post_title_output );
235 if ( $post_title_output != '' )
236 {
237 echo ' - ' . $post_title_output;
238 }
239
240 echo '</strong>';
241
242 // Excerpt view
243 if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
244 echo apply_filters( 'the_excerpt', $post->post_excerpt );
245 }
246
247 // Get actions
248 $actions = array();
249
250 $actions['ref'] = 'Ref: ' . $the_property->_reference_number;
251
252 //$actions['id'] = 'ID: ' . $post->ID;
253
254 if ( $can_edit_post && 'trash' != $post->post_status ) {
255 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'propertyhive' ) ) . '">' . __( 'Edit', 'propertyhive' ) . '</a>';
256 }
257 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
258 if ( 'trash' == $post->post_status ) {
259 $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>';
260 } elseif ( EMPTY_TRASH_DAYS ) {
261 //$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>';
262 }
263
264 if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
265 $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>';
266 }
267 }
268 if ( $post_type_object->public ) {
269 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
270 if ( $can_edit_post )
271 $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>';
272 } elseif ( 'trash' != $post->post_status ) {
273 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'View', 'propertyhive' ) . '</a>';
274 }
275 }
276
277 $actions = apply_filters( 'post_row_actions', $actions, $post );
278
279 echo '<div class="row-actions">';
280
281 $i = 0;
282 $action_count = sizeof($actions);
283
284 foreach ( $actions as $action => $link ) {
285 ++$i;
286 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
287 echo '<span class="' . $action . '">' . $link . $sep . '</span>';
288 }
289 echo '</div>';
290
291 get_inline_data( $post );
292
293 /* Custom inline data for propertyhive */
294 /*echo '
295 <div class="hidden" id="propertyhive_inline_' . $post->ID . '">
296 <div class="on_market">' . $the_property->on_market . '</div>
297 <div class="featured">' . $the_property->featured . '</div>
298 </div>
299 ';*/
300
301 break;
302 case 'size' :
303
304 $floor_area = $the_property->get_formatted_floor_area();
305 if ( $floor_area != '' )
306 {
307 echo 'Floor Area: ' . $floor_area . '<br>';
308 }
309 $site_area = $the_property->get_formatted_site_area();
310 if ( $site_area != '' )
311 {
312 echo 'Site Area: ' . $site_area;
313 }
314
315 if ( $floor_area == '' && $site_area == '' )
316 {
317 echo '-';
318 }
319
320 break;
321 case 'price' :
322
323 $price = $the_property->get_formatted_price();
324 if ( $price == '' )
325 {
326 $price = '-';
327 }
328 else
329 {
330 if ( $the_property->_department == 'residential-sales' && $the_property->price_qualifier != '' )
331 {
332 $price .= '<br>' . $the_property->price_qualifier;
333 }
334 }
335 echo $price;
336
337 break;
338 case 'status' :
339
340 $term_list = wp_get_post_terms($post->ID, 'availability', array("fields" => "names"));
341
342 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
343 {
344 echo $term_list[0]. '<br>';
345 }
346
347 if (isset($the_property->_on_market) && $the_property->_on_market == 'yes')
348 {
349 echo __( 'On The Market', 'propertyhive' );
350 }
351 else
352 {
353 echo __( 'Not On The Market', 'propertyhive' );
354 }
355
356 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
357 {
358 echo '<br>' . __( 'Featured', 'propertyhive' );
359 }
360
361 $marketing_flags = $the_property->marketing_flag;
362 if ( $marketing_flags != '' )
363 {
364 echo '<br>' . implode( "<br>", explode( ",", $marketing_flags ) );
365 }
366
367 break;
368 case 'owner' :
369
370 $owner_contact_ids = $the_property->_owner_contact_id;
371 if (
372 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
373 ||
374 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
375 )
376 {
377 if ( !is_array($owner_contact_ids) )
378 {
379 $owner_contact_ids = array($owner_contact_ids);
380 }
381
382 foreach ( $owner_contact_ids as $owner_contact_id )
383 {
384 echo get_the_title($owner_contact_id) . '<br>';
385 if ( count($owner_contact_ids) == 1 )
386 {
387 echo '<div class="row-actions">';
388 echo 'T: ' . get_post_meta($owner_contact_id, '_telephone_number', TRUE) . '<br>';
389 echo 'E: ' . get_post_meta($owner_contact_id, '_email_address', TRUE);
390 echo '</div>';
391 }
392 }
393 }
394 else
395 {
396 echo '-';
397 }
398 break;
399 case 'negotiator_office' :
400
401 $user_info = get_userdata($the_property->_negotiator_id);
402
403 if ($user_info !== FALSE)
404 {
405 echo $user_info->display_name . '<br>';
406 }
407
408 if ($the_property->_office_id != '')
409 {
410 echo get_the_title($the_property->_office_id);
411 }
412
413 break;
414 default :
415 break;
416 }
417 }
418
419 /**
420 * Search by ID, address and reference number
421 *
422 * @param string $where
423 * @return string
424 */
425 public function property_search( $where ) {
426 global $pagenow, $wpdb, $wp;
427
428 if ( 'edit.php' != $pagenow || ! is_search() || ! isset( $wp->query_vars['s'] ) || 'property' != $wp->query_vars['post_type'] ) {
429 return $where;
430 }
431
432 if ( trim($wp->query_vars['s']) == '' )
433 {
434 return $where;
435 }
436
437 $search_ids = array();
438 $terms = explode( ',', $wp->query_vars['s'] );
439
440 foreach ( $terms as $term )
441 {
442 if ( is_numeric( $term ) )
443 {
444 $search_ids[] = $term;
445 }
446
447 // Attempt to get an ID by searching for address and reference number
448 $query = $wpdb->prepare(
449 "SELECT
450 ID
451 FROM
452 {$wpdb->posts}
453 INNER JOIN {$wpdb->postmeta} AS mt1 ON {$wpdb->posts}.ID = mt1.post_id
454 WHERE
455 (
456 (mt1.meta_key='_address_name_number' AND mt1.meta_value LIKE %s)
457 OR
458 (mt1.meta_key='_address_street' AND mt1.meta_value LIKE %s)
459 OR
460 (mt1.meta_key='_address_2' AND mt1.meta_value LIKE %s)
461 OR
462 (mt1.meta_key='_address_3' AND mt1.meta_value LIKE %s)
463 OR
464 (mt1.meta_key='_address_4' AND mt1.meta_value LIKE %s)
465 OR
466 (mt1.meta_key='_address_postcode' AND mt1.meta_value LIKE %s)
467 OR
468 (mt1.meta_key='_reference_number' AND mt1.meta_value = %s)
469 )
470 AND
471 post_type='property'
472 GROUP BY ID
473 ",
474 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
475 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
476 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
477 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
478 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
479 '%' . $wpdb->esc_like( ph_clean( $term ) ) . '%',
480 '' . $wpdb->esc_like( ph_clean( $term ) ) . ''
481 );
482 $search_posts = $wpdb->get_results( $query );
483 $search_posts = wp_list_pluck( $search_posts, 'ID' );
484
485 if ( sizeof( $search_posts ) > 0 )
486 {
487 $search_ids = array_merge( $search_ids, $search_posts );
488 }
489 }
490 $search_ids = array_filter( array_unique( array_map( 'absint', $search_ids ) ) );
491 if ( sizeof( $search_ids ) > 0 )
492 {
493 $where = str_replace( 'AND (((', "AND ( ({$wpdb->posts}.ID IN (" . implode( ',', $search_ids ) . ")) OR ((", $where );
494 }
495 return $where;
496 }
497
498 /**
499 * Make property columns sortable
500 *
501 * https://gist.github.com/906872
502 *
503 * @access public
504 * @param mixed $columns
505 * @return array
506 */
507 public function custom_columns_sort( $columns ) {
508 $custom = array(
509 'price' => '_price_actual',
510 'size' => '_floor_area_from_sqft'
511 );
512 return wp_parse_args( $custom, $columns );
513 }
514
515 /**
516 * Property column orderby
517 *
518 * @access public
519 * @param mixed $vars
520 * @return array
521 */
522 public function custom_columns_orderby( $vars ) {
523 if ( isset( $vars['orderby'] ) ) {
524 if ( '_price_actual' == $vars['orderby'] ) {
525 $vars = array_merge( $vars, array(
526 'meta_key' => '_price_actual',
527 'orderby' => 'meta_value_num'
528 ) );
529 }
530 elseif ( '_floor_area_from_sqft' == $vars['orderby'] ) {
531 $vars = array_merge( $vars, array(
532 'meta_key' => '_floor_area_from_sqft',
533 'orderby' => 'meta_value_num'
534 ) );
535 }
536 }
537
538 return $vars;
539 }
540
541 /**
542 * Remove 'Mine' view option
543 *
544 * @param array $views
545 * @return array
546 */
547 public function remove_mine( $views ) {
548 global $post_type, $wp_query;
549
550 if ( ! current_user_can('edit_others_pages') ) {
551 return $views;
552 }
553
554 if( isset( $views['mine'] ) )
555 unset( $views['mine'] );
556
557 return $views;
558 }
559
560 /**
561 * Show a category filter box
562 */
563 public function propertyhive_filters() {
564 global $typenow, $wp_query;
565
566 if ( 'property' != $typenow ) {
567 return;
568 }
569
570 echo apply_filters( 'propertyhive_property_filters', $output );
571 }
572
573 /**
574 * Filter the products in admin based on options
575 *
576 * @param mixed $query
577 */
578 public function property_filters_query( $query ) {
579 global $typenow, $wp_query;
580
581 if ( 'property' == $typenow ) {
582
583 }
584 }
585
586 /**
587 * Maintain term hierarchy when editing a property.
588 * @param array $args
589 * @return array
590 */
591 public function disable_checked_ontop( $args ) {
592 if ( 'product_cat' == $args['taxonomy'] ) {
593 $args['checked_ontop'] = false;
594 }
595
596 return $args;
597 }
598
599 /**
600 * Custom bulk edit - form
601 *
602 * @access public
603 * @param mixed $column_name
604 * @param mixed $post_type
605 */
606 public function bulk_edit( $column_name, $post_type ) {
607 if ( 'price' != $column_name || 'property' != $post_type ) {
608 return;
609 }
610
611 include( PH()->plugin_path() . '/includes/admin/views/html-bulk-edit-property.php' );
612 }
613
614 /**
615 * Custom quick edit - form
616 *
617 * @access public
618 * @param mixed $column_name
619 * @param mixed $post_type
620 */
621 public function quick_edit( $column_name, $post_type ) {
622 if ( 'price' != $column_name || 'property' != $post_type ) {
623 return;
624 }
625
626 include( PH()->plugin_path() . '/includes/admin/views/html-quick-edit-property.php' );
627 }
628
629 /**
630 * Quick and bulk edit saving
631 *
632 * @access public
633 * @param int $post_id
634 * @param WP_Post $post
635 * @return int
636 */
637 public function bulk_and_quick_edit_save_post( $post_id, $post ) {
638 // If this is an autosave, our form has not been submitted, so we don't want to do anything.
639 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
640 return $post_id;
641 }
642
643 // Don't save revisions and autosaves
644 if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
645 return $post_id;
646 }
647
648 // Check post type is product
649 if ( 'property' != $post->post_type ) {
650 return $post_id;
651 }
652
653 // Check user permission
654 if ( ! current_user_can( 'edit_post', $post_id ) ) {
655 return $post_id;
656 }
657
658 // Check nonces
659 if ( ! isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) ) {
660 return $post_id;
661 }
662 if ( isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_quick_edit_nonce'], 'propertyhive_quick_edit_nonce' ) ) {
663 return $post_id;
664 }
665 if ( isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_bulk_edit_nonce'], 'propertyhive_bulk_edit_nonce' ) ) {
666 return $post_id;
667 }
668
669 // Get the product and save
670 $property = get_property( $post );
671
672 if ( ! empty( $_REQUEST['propertyhive_quick_edit'] ) ) {
673 $this->quick_edit_save( $post_id, $property );
674 } else {
675 $this->bulk_edit_save( $post_id, $property );
676 }
677
678 // Clear transient
679 //ph_delete_property_transients( $post_id );
680
681 return $post_id;
682 }
683
684 /**
685 * Quick edit
686 */
687 private function quick_edit_save( $post_id, $property ) {
688 global $wpdb;
689
690 /*
691 // Save fields
692 if ( isset( $_REQUEST['_address_name_number'] ) ) {
693 update_post_meta( $post_id, '_address_name_number', ph_clean( $_REQUEST['_address_name_number'] ) );
694 }*/
695
696 do_action( 'propertyhive_property_quick_edit_save', $property );
697 }
698
699 /**
700 * Bulk edit
701 */
702 public function bulk_edit_save( $post_id, $property ) {
703
704 // Save fields
705 if ( ! empty( $_REQUEST['_on_market'] ) )
706 {
707 $on_market = ph_clean( $_REQUEST['_on_market'] );
708 if ( $_REQUEST['_on_market'] != 'yes' ) { $on_market = ''; } // can only be 'yes' or blank
709 update_post_meta( $post_id, '_on_market', ph_clean( $on_market ) );
710 }
711
712 if ( ! empty( $_REQUEST['_availability'] ) && is_numeric( $_REQUEST['_availability'] ) )
713 {
714 wp_set_post_terms( $post_id, (int)$_REQUEST['_availability'], 'availability' );
715 }
716
717 if ( ! empty( $_REQUEST['_negotiator_id'] ) && is_numeric( $_REQUEST['_negotiator_id'] ) && $_REQUEST['_negotiator_id'] != '-1' )
718 {
719 update_post_meta( $post_id, '_negotiator_id', (int)$_REQUEST['_negotiator_id'] );
720 }
721
722 if ( ! empty( $_REQUEST['_office_id'] ) && is_numeric( $_REQUEST['_office_id'] ) )
723 {
724 update_post_meta( $post_id, '_office_id', (int)$_REQUEST['_office_id'] );
725 }
726
727 do_action( 'propertyhive_property_bulk_edit_save', $property );
728 }
729
730 /**
731 * Filter the directory for uploads.
732 *
733 * @param array $pathdata
734 * @return array
735 */
736 public function upload_dir( $pathdata ) {
737 // Change upload dir for downloadable files
738 if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) {
739 if ( empty( $pathdata['subdir'] ) ) {
740 $pathdata['path'] = $pathdata['path'] . '/propertyhive_uploads';
741 $pathdata['url'] = $pathdata['url']. '/propertyhive_uploads';
742 $pathdata['subdir'] = '/propertyhive_uploads';
743 } else {
744 $new_subdir = '/propertyhive_uploads' . $pathdata['subdir'];
745
746 $pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
747 $pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
748 $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
749 }
750 }
751
752 return $pathdata;
753 }
754 }
755
756 endif;
757
758 return new PH_Admin_CPT_Property();
759