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

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