PluginProbe
Property Hive / 2.2.6
Property Hive v2.2.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 2.2.6, at includes/admin/post-types/class-ph-admin-cpt-property.php

898 lines 26.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( 'list_table_primary_column', array( $this, 'set_primary_column' ), 10, 2 );
53 add_filter( 'post_row_actions', array( $this, 'remove_actions' ), 10, 2 );
54 add_filter( 'manage_edit-property_sortable_columns', array( $this, 'custom_columns_sort' ) );
55 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
56 add_filter( 'display_post_states', array( $this, 'flag_search_results_page' ), 10, 2 );
57
58 // Sort link
59 add_filter( 'views_edit-property', array( $this, 'remove_mine' ) );
60
61 // Prouct filtering
62 /*add_action( 'restrict_manage_posts', array( $this, 'property_filters' ) );
63 add_filter( 'parse_query', array( $this, 'property_filters_query' ) );*/
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 add_action( 'load-edit.php', array( $this, 'render_blank' ) );
82
83 // Call PH_Admin_CPT constructor
84 parent::__construct();
85 }
86
87 public function flag_search_results_page( $post_states, $post )
88 {
89 // Get the page ID set in your option
90 $search_results_page_id = get_option( 'propertyhive_search_results_page_id' );
91
92 // Check if this is that page
93 if ( $post->ID == $search_results_page_id )
94 {
95 $post_states['property_search_results'] = __( 'Property Search Results', 'propertyhive' );
96 }
97
98 return $post_states;
99 }
100
101 public function render_blank()
102 {
103 // Check if we are on the 'property' post type listing page
104 $screen = get_current_screen();
105 if ($screen->post_type !== 'property') {
106 return;
107 }
108
109 // Check if there are any properties
110 $query = new WP_Query([
111 'post_type' => 'property',
112 'post_status' => ['any', 'trash'],
113 'posts_per_page' => 1
114 ]);
115
116 if ($query->have_posts()) {
117 return; // Let the default table load
118 }
119
120 // No properties found, replace the table with a custom splash screen
121 add_filter('views_edit-property', function ($views) {
122 // Clear default view filters (All, Published, etc.)
123 return [];
124 });
125
126 add_action('manage_posts_extra_tablenav', function ($which) {
127 if ( $which == 'bottom' )
128 {
129 return;
130 }
131 echo '
132 <div style="padding: 50px; text-align: center;">
133
134 <img style="max-width:400px; margin-bottom:45px;" src="' . esc_url(PH()->plugin_url()) . '/assets/images/no-properties.png" alt="' . esc_attr( __( 'Your property journey begins here!', 'propertyhive' ) ) . '">
135
136 <h2 style="font-size:1.8em; color:#444; margin:0 0 1.5em">' . esc_html( __( 'Your property journey begins here!', 'propertyhive' ) ) . '</h2>
137 <a href="' . esc_url(admin_url('post-new.php?post_type=property&tutorial=yes')) . '" class="button button-primary button-hero" style="font-size:1.2em; padding:0 24px;">
138 ' . esc_html( __( 'Add Your First Property', 'propertyhive' ) ) . '
139 </a>&nbsp;
140 <a href="' . esc_url(admin_url('admin.php?page=ph-settings&tab=demo_data')) . '" class="button button-hero" style="font-size:1.2em; padding:0 24px;">
141 ' . esc_html( __( 'Create Demo Data', 'propertyhive' ) ) . '
142 </a>&nbsp; ';
143
144 if ( apply_filters( 'propertyhive_no_properties_property_import_button', true ) === true )
145 {
146 $button_to_output = false;
147
148 if ( class_exists('PH_Property_Import') )
149 {
150 // Already activated. Check can be used
151 if ( apply_filters( 'propertyhive_add_on_can_be_used', true, 'propertyhive-property-import' ) === true )
152 {
153 $button_to_output = 'normal';
154 }
155 }
156
157 if ( !$button_to_output )
158 {
159 $license_type = get_option( 'propertyhive_license_type', '' );
160
161 switch ( $license_type )
162 {
163 case "": { $button_to_output = 'dummy'; break; }
164 case "pro":
165 {
166 if ( PH()->license->is_valid_pro_license_key() )
167 {
168 // It should never get this far if import add on already activated, that's why show activate page
169 $button_to_output = 'activate';
170 }
171 else
172 {
173 $button_to_output = 'dummy';
174 }
175 break;
176 }
177 }
178 }
179
180 // only show dummy button to administrators
181 if ( $button_to_output == 'dummy' || $button_to_output == 'activate' )
182 {
183 if ( !current_user_can( 'manage_options' ) )
184 {
185 // not an admin
186 $button_to_output = false;
187 }
188 }
189
190 // only show dummy button to people with it installed eyond 1st nov 2023 (when PRO was introduced)
191 if ( $button_to_output == 'dummy' )
192 {
193 $propertyhive_install_timestamp = get_option( 'propertyhive_install_timestamp', '' );
194 if ( !empty($propertyhive_install_timestamp) )
195 {
196 $november_first_2023 = strtotime('2023-11-01 00:00:00');
197 if ( $propertyhive_install_timestamp < $november_first_2023 )
198 {
199 $button_to_output = false;
200 }
201 }
202 }
203
204 switch ( $button_to_output )
205 {
206 case "normal":
207 {
208 echo '<a href="' . esc_url(admin_url('admin.php?page=propertyhive_import_properties')) . '" class="button button-hero" style="font-size:1.2em; padding:0 24px;">
209 ' . esc_html( __( 'Automatically Import Properties', 'propertyhive' ) ) . '
210 </a>';
211 break;
212 }
213 case "dummy":
214 {
215 echo '<a href="' . esc_url(admin_url('admin.php?page=ph-import_properties_dummy')) . '" class="button button-hero" style="font-size:1.2em; padding:0 24px;">
216 ' . esc_html( __( 'Automatically Import Properties', 'propertyhive' ) ) . ' <span style="color:#FFF; font-size:10px; font-weight:500; border-radius:12px; padding:2px 8px; letter-spacing:1px; background:#00a32a;">PRO</span>
217 </a>';
218 break;
219 }
220 case "activate":
221 {
222 echo '<a href="' . esc_url(admin_url('admin.php?page=ph-settings&tab=features&profilter=import')) . '" class="button button-hero" style="font-size:1.2em; padding:0 24px;">
223 ' . esc_html( __( 'Activate Property Imports', 'propertyhive' ) ) . '
224 </a>';
225 break;
226 }
227 }
228 }
229
230 echo '</div>';
231 }, 99);
232
233 // Remove the filters
234 remove_all_actions('restrict_manage_posts');
235
236 // Hide the search box
237 add_action('admin_head', function () {
238 echo '<style>
239 .page-title-action,
240 .wrap .wp-list-table,
241 .search-box { display: none !important; }
242 </style>';
243 });
244
245 add_filter('bulk_actions-edit-property', function ($bulk_actions) {
246 // Clear all bulk actions
247 return [];
248 });
249 }
250
251 /**
252 * Output admin notices relating to property
253 */
254 public function property_admin_notices()
255 {
256 global $post;
257
258 $screen = get_current_screen();
259 if ($screen->id == 'property' && $post->post_type == 'property' && $post->post_parent != 0 && $post->post_parent != '')
260 {
261 $property = new PH_Property((int)$post->post_parent);
262 $message = __( "This property is a unit belonging to", 'propertyhive' ) . ' <a href="' . esc_url(get_edit_post_link( $post->post_parent )) . '">' . esc_html($property->get_formatted_full_address()) . '</a>';
263 echo "<div class=\"notice notice-info\"> <p>$message</p></div>";
264 }
265 }
266
267 /**
268 * Check if we're editing or adding a property
269 * @return boolean
270 */
271 private function is_editing_property() {
272 if ( ! empty( $_GET['post_type'] ) && 'property' == $_GET['post_type'] ) {
273 return true;
274 }
275 if ( ! empty( $_GET['post'] ) && 'property' == get_post_type( (int)$_GET['post'] ) ) {
276 return true;
277 }
278 if ( ! empty( $_REQUEST['post_id'] ) && 'property' == get_post_type( (int)$_REQUEST['post_id'] ) ) {
279 return true;
280 }
281 return false;
282 }
283
284 /**
285 * Change title boxes in admin.
286 * @param string $text
287 * @param object $post
288 * @return string
289 */
290 public function enter_title_here( $text, $post ) {
291 if ( is_admin() && $post->post_type == 'property' ) {
292 return __( 'Enter Display Address', 'propertyhive' );
293 }
294
295 return $text;
296 }
297
298 /**
299 * Some functions, like the term recount, require the visibility to be set prior. Lets save that here.
300 *
301 * @param int $post_id
302 */
303 public function pre_post_update( $post_id ) {
304
305 }
306
307 /**
308 * Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
309 *
310 * @param array $data
311 * @return array
312 */
313 public function wp_insert_post_data( $data ) {
314
315
316 return $data;
317 }
318
319 /**
320 * Change the columns shown in admin.
321 */
322 public function edit_columns( $existing_columns ) {
323
324 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
325 $existing_columns = array();
326 }
327
328 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
329
330 $columns = array();
331 $columns['cb'] = '<input type="checkbox" />';
332 $columns['thumb'] = '<span class="ph-image tips" data-tip="' . __( 'Image', 'propertyhive' ) . '">' . __( 'Image', 'propertyhive' ) . '</span>';
333
334 $columns['address'] = __( 'Address', 'propertyhive' );
335
336 $commercial_department_active = false;
337 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
338 {
339 $commercial_department_active = true;
340 }
341 else
342 {
343 $custom_departments = ph_get_custom_departments();
344 if ( !empty($custom_departments) )
345 {
346 foreach ( $custom_departments as $key => $department )
347 {
348 if ( isset($department['based_on']) && $department['based_on'] == 'commercial' )
349 {
350 $commercial_department_active = true;
351 }
352 }
353 }
354 }
355 if ( $commercial_department_active )
356 {
357 $columns['size'] = __( 'Size', 'propertyhive' );
358 }
359
360 $columns['price'] = __( 'Price', 'propertyhive' );
361
362 $columns['status'] = __( 'Marketing Status', 'propertyhive' );
363
364 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
365 {
366 $columns['owner'] = __( 'Owner / Landlord', 'propertyhive' );
367 }
368
369 $columns['negotiator_office'] = __( 'Neg / Office', 'propertyhive' );
370
371 return array_merge( $columns, $existing_columns );
372 }
373
374 /**
375 * Define our custom columns shown in admin.
376 * @param string $column
377 */
378 public function custom_columns( $column ) {
379 global $post, $propertyhive, $the_property;
380
381 if ( empty( $the_property ) || $the_property->ID != $post->ID )
382 {
383 $the_property = new PH_Property( $post->ID );
384 }
385
386 switch ( $column ) {
387 case 'thumb' :
388
389 $thumb_src = $the_property->get_main_photo_src();
390
391 echo '<a href="' . esc_url(get_edit_post_link( $post->ID )) . '">';
392 if ($thumb_src !== FALSE)
393 {
394 echo '<img src="' . esc_url($thumb_src) . '" alt="" width="50">';
395 }
396 else
397 {
398 // placeholder image
399 }
400 echo '</a>';
401 break;
402 case 'address' :
403
404 $edit_link = get_edit_post_link( $post->ID );
405 //$title = _draft_or_post_title();
406 $title = $the_property->get_formatted_summary_address();
407 if ( empty($title) )
408 {
409 $title = '(' . __( 'no address entered', 'propertyhive' ) . ')';
410 }
411 $post_type_object = get_post_type_object( $post->post_type );
412 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
413
414 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . esc_html($title) . '</a>';
415
416 $post_status = get_post_status( $post->ID );
417 $post_title_output = '';
418 if ( $post_status == 'draft' || $post_status == 'private' )
419 {
420 $post_title_output = ucfirst($post_status);
421 }
422 $post_title_output = apply_filters( 'propertyhive_admin_property_column_post_address_output', $post_title_output );
423 if ( $post_title_output != '' )
424 {
425 echo ' - ' . esc_html($post_title_output);
426 }
427
428 echo '</strong>';
429
430 // Excerpt view
431 if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
432 echo apply_filters( 'the_excerpt', $post->post_excerpt );
433 }
434
435 if ( $the_property->bedrooms != '' || $the_property->property_type != '' || $the_property->reference_number != '' )
436 {
437 echo '<br>';
438
439 $details = array();
440
441 if ( $the_property->bedrooms != '' || $the_property->property_type != '' )
442 {
443 $details[] = (
444 (
445 (
446 $the_property->department == 'residential-sales' ||
447 $the_property->department == 'residential-lettings' ||
448 ph_get_custom_department_based_on($the_property->department) == 'residential-sales' ||
449 ph_get_custom_department_based_on($the_property->department) == 'residential-lettings'
450 )
451 &&
452 $the_property->bedrooms != ''
453 ) ? esc_html($the_property->bedrooms . ' ' . __( 'bedroom', 'propertyhive' )) . ' ' : ''
454 ) . esc_html($the_property->property_type);
455 }
456
457 if ( $the_property->reference_number )
458 {
459 $details[] = '<span style="opacity:0.6">' . esc_html(__( 'Ref', 'propertyhive' )) . ': ' . esc_html($the_property->reference_number) . '</span>';
460 }
461
462 $details = apply_filters( 'propertyhive_admin_property_column_address_details', $details, $post->ID );
463
464 echo implode("<br>", $details);
465 }
466
467 get_inline_data( $post );
468
469 /* Custom inline data for propertyhive */
470 /*echo '
471 <div class="hidden" id="propertyhive_inline_' . $post->ID . '">
472 <div class="on_market">' . $the_property->on_market . '</div>
473 <div class="featured">' . $the_property->featured . '</div>
474 </div>
475 ';*/
476
477 break;
478 case 'size' :
479
480 $floor_area = $the_property->get_formatted_floor_area();
481 if ( $floor_area != '' )
482 {
483 echo 'Floor Area: ' . $floor_area . '<br>';
484 }
485 $site_area = $the_property->get_formatted_site_area();
486 if ( $site_area != '' )
487 {
488 echo 'Site Area: ' . $site_area;
489 }
490
491 if ( $floor_area == '' && $site_area == '' )
492 {
493 echo '-';
494 }
495
496 break;
497 case 'price' :
498
499 $price = $the_property->get_formatted_price();
500 if ( $price == '' )
501 {
502 $price = '-';
503 }
504 else
505 {
506 if (
507 ( $the_property->_department == 'residential-sales' || ph_get_custom_department_based_on($the_property->_department) == 'residential-sales' )
508 &&
509 $the_property->price_qualifier != ''
510 )
511 {
512 $price .= '<br>' . esc_html($the_property->price_qualifier);
513 }
514 }
515 echo $price;
516
517 break;
518 case 'status' :
519
520 $term_list = wp_get_post_terms($post->ID, 'availability', array("fields" => "names"));
521
522 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
523 {
524 echo esc_html($term_list[0]). '<br>';
525 }
526
527 if (isset($the_property->_on_market) && $the_property->_on_market == 'yes')
528 {
529 echo esc_html(__( 'On The Market', 'propertyhive' ));
530 }
531 else
532 {
533 echo esc_html(__( 'Not On The Market', 'propertyhive' ));
534 }
535
536 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
537 {
538 echo '<br>' . esc_html(__( 'Featured', 'propertyhive' ));
539 }
540
541 $marketing_flags = $the_property->marketing_flag;
542 if ( $marketing_flags != '' )
543 {
544 echo '<br>' . implode( "<br>", explode( ",", esc_html($marketing_flags) ) );
545 }
546
547 break;
548 case 'owner' :
549
550 $owner_contact_ids = $the_property->_owner_contact_id;
551 if (
552 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
553 ||
554 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
555 )
556 {
557 if ( !is_array($owner_contact_ids) )
558 {
559 $owner_contact_ids = array($owner_contact_ids);
560 }
561
562 foreach ( $owner_contact_ids as $owner_contact_id )
563 {
564 echo esc_html(get_the_title($owner_contact_id)) . '<br>';
565 if ( count($owner_contact_ids) == 1 )
566 {
567 echo '<div class="row-actions">';
568 echo 'T: ' . esc_html(get_post_meta($owner_contact_id, '_telephone_number', TRUE)) . '<br>';
569 echo 'E: ' . esc_html(get_post_meta($owner_contact_id, '_email_address', TRUE));
570 echo '</div>';
571 }
572 }
573 }
574 else
575 {
576 echo '-';
577 }
578 break;
579 case 'negotiator_office' :
580
581 $user_info = get_userdata($the_property->_negotiator_id);
582
583 if ($user_info !== FALSE)
584 {
585 echo esc_html($user_info->display_name) . '<br>';
586 }
587
588 if ($the_property->_office_id != '')
589 {
590 echo esc_html(get_the_title($the_property->_office_id));
591 }
592
593 break;
594 default :
595 break;
596 }
597 }
598
599 public function set_primary_column( $default, $screen ) {
600
601 if ( 'edit-property' === $screen )
602 {
603 $default = 'address';
604 }
605
606 return $default;
607 }
608
609 public function remove_actions($actions, $post) {
610
611 if ( $post->post_type !== 'property' )
612 {
613 return $actions;
614 }
615
616 // Remove 'Quick Edit' link
617 if ( isset($actions['inline hide-if-no-js']) )
618 {
619 unset($actions['inline hide-if-no-js']);
620 }
621
622 if ( isset($actions['trash']) )
623 {
624 unset($actions['trash']);
625 }
626
627 return $actions;
628 }
629
630 /**
631 * Make property columns sortable
632 *
633 * https://gist.github.com/906872
634 *
635 * @access public
636 * @param mixed $columns
637 * @return array
638 */
639 public function custom_columns_sort( $columns ) {
640 $custom = array(
641 'price' => '_price_actual',
642 'size' => '_floor_area_from_sqft'
643 );
644 return wp_parse_args( $custom, $columns );
645 }
646
647 /**
648 * Property column orderby
649 *
650 * @access public
651 * @param mixed $vars
652 * @return array
653 */
654 public function custom_columns_orderby( $vars ) {
655 if ( isset( $vars['orderby'] ) ) {
656 if ( '_price_actual' == $vars['orderby'] ) {
657 $vars = array_merge( $vars, array(
658 'meta_key' => '_price_actual',
659 'orderby' => 'meta_value_num'
660 ) );
661 }
662 elseif ( '_floor_area_from_sqft' == $vars['orderby'] ) {
663 $vars = array_merge( $vars, array(
664 'meta_key' => '_floor_area_from_sqft',
665 'orderby' => 'meta_value_num'
666 ) );
667 }
668 }
669
670 return $vars;
671 }
672
673 /**
674 * Remove 'Mine' view option
675 *
676 * @param array $views
677 * @return array
678 */
679 public function remove_mine( $views ) {
680 global $post_type, $wp_query;
681
682 if ( ! current_user_can('edit_others_pages') ) {
683 return $views;
684 }
685
686 if( isset( $views['mine'] ) )
687 unset( $views['mine'] );
688
689 return $views;
690 }
691
692 /**
693 * Show a category filter box
694 */
695 public function propertyhive_filters() {
696 global $typenow, $wp_query;
697
698 if ( 'property' != $typenow ) {
699 return;
700 }
701
702 echo apply_filters( 'propertyhive_property_filters', $output );
703 }
704
705 /**
706 * Filter the products in admin based on options
707 *
708 * @param mixed $query
709 */
710 public function property_filters_query( $query ) {
711 global $typenow, $wp_query;
712
713 if ( 'property' == $typenow ) {
714
715 }
716 }
717
718 /**
719 * Maintain term hierarchy when editing a property.
720 * @param array $args
721 * @return array
722 */
723 public function disable_checked_ontop( $args ) {
724 if ( 'product_cat' == $args['taxonomy'] ) {
725 $args['checked_ontop'] = false;
726 }
727
728 return $args;
729 }
730
731 /**
732 * Custom bulk edit - form
733 *
734 * @access public
735 * @param mixed $column_name
736 * @param mixed $post_type
737 */
738 public function bulk_edit( $column_name, $post_type ) {
739 if ( 'price' != $column_name || 'property' != $post_type ) {
740 return;
741 }
742
743 include( PH()->plugin_path() . '/includes/admin/views/html-bulk-edit-property.php' );
744 }
745
746 /**
747 * Custom quick edit - form
748 *
749 * @access public
750 * @param mixed $column_name
751 * @param mixed $post_type
752 */
753 public function quick_edit( $column_name, $post_type ) {
754 if ( 'price' != $column_name || 'property' != $post_type ) {
755 return;
756 }
757
758 include( PH()->plugin_path() . '/includes/admin/views/html-quick-edit-property.php' );
759 }
760
761 /**
762 * Quick and bulk edit saving
763 *
764 * @access public
765 * @param int $post_id
766 * @param WP_Post $post
767 * @return int
768 */
769 public function bulk_and_quick_edit_save_post( $post_id, $post ) {
770 // If this is an autosave, our form has not been submitted, so we don't want to do anything.
771 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
772 return $post_id;
773 }
774
775 // Don't save revisions and autosaves
776 if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
777 return $post_id;
778 }
779
780 // Check post type is product
781 if ( 'property' != $post->post_type ) {
782 return $post_id;
783 }
784
785 // Check user permission
786 if ( ! current_user_can( 'edit_post', $post_id ) ) {
787 return $post_id;
788 }
789
790 // Check nonces
791 if ( ! isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) ) {
792 return $post_id;
793 }
794 if ( isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_quick_edit_nonce'], 'propertyhive_quick_edit_nonce' ) ) {
795 return $post_id;
796 }
797 if ( isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_bulk_edit_nonce'], 'propertyhive_bulk_edit_nonce' ) ) {
798 return $post_id;
799 }
800
801 // Get the product and save
802 $property = get_property( $post );
803
804 if ( ! empty( $_REQUEST['propertyhive_quick_edit'] ) ) {
805 $this->quick_edit_save( $post_id, $property );
806 } else {
807 $this->bulk_edit_save( $post_id, $property );
808 }
809
810 // Clear transient
811 //ph_delete_property_transients( $post_id );
812
813 return $post_id;
814 }
815
816 /**
817 * Quick edit
818 */
819 private function quick_edit_save( $post_id, $property ) {
820 global $wpdb;
821
822 /*
823 // Save fields
824 if ( isset( $_REQUEST['_address_name_number'] ) ) {
825 update_post_meta( $post_id, '_address_name_number', ph_clean( $_REQUEST['_address_name_number'] ) );
826 }*/
827
828 do_action( 'propertyhive_property_quick_edit_save', $property );
829 }
830
831 /**
832 * Bulk edit
833 */
834 public function bulk_edit_save( $post_id, $property ) {
835
836 // Save fields
837 if ( ! empty( $_REQUEST['_on_market'] ) )
838 {
839 $on_market = ph_clean( $_REQUEST['_on_market'] );
840 if ( $_REQUEST['_on_market'] != 'yes' ) { $on_market = ''; } // can only be 'yes' or blank
841 update_post_meta( $post_id, '_on_market', ph_clean( $on_market ) );
842 }
843
844 if ( ! empty( $_REQUEST['_featured'] ) )
845 {
846 $featured = ph_clean( $_REQUEST['_featured'] );
847 if ( $_REQUEST['_featured'] != 'yes' ) { $featured = ''; } // can only be 'yes' or blank
848 update_post_meta( $post_id, '_featured', ph_clean( $featured ) );
849 }
850
851 if ( ! empty( $_REQUEST['_availability'] ) && is_numeric( $_REQUEST['_availability'] ) )
852 {
853 wp_set_post_terms( $post_id, (int)$_REQUEST['_availability'], 'availability' );
854 }
855
856 if ( ! empty( $_REQUEST['_negotiator_id'] ) && is_numeric( $_REQUEST['_negotiator_id'] ) && $_REQUEST['_negotiator_id'] != '-1' )
857 {
858 update_post_meta( $post_id, '_negotiator_id', (int)$_REQUEST['_negotiator_id'] );
859 }
860
861 if ( ! empty( $_REQUEST['_office_id'] ) && is_numeric( $_REQUEST['_office_id'] ) )
862 {
863 update_post_meta( $post_id, '_office_id', (int)$_REQUEST['_office_id'] );
864 }
865
866 do_action( 'propertyhive_property_bulk_edit_save', $property );
867 }
868
869 /**
870 * Filter the directory for uploads.
871 *
872 * @param array $pathdata
873 * @return array
874 */
875 public function upload_dir( $pathdata ) {
876 // Change upload dir for downloadable files
877 if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) {
878 if ( empty( $pathdata['subdir'] ) ) {
879 $pathdata['path'] = $pathdata['path'] . '/propertyhive_uploads';
880 $pathdata['url'] = $pathdata['url']. '/propertyhive_uploads';
881 $pathdata['subdir'] = '/propertyhive_uploads';
882 } else {
883 $new_subdir = '/propertyhive_uploads' . $pathdata['subdir'];
884
885 $pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
886 $pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
887 $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
888 }
889 }
890
891 return $pathdata;
892 }
893 }
894
895 endif;
896
897 return new PH_Admin_CPT_Property();
898