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 / class-ph-post-types.php

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

657 lines 30.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 /**
7 * Post types
8 *
9 * Registers post types
10 *
11 * @class PH_Post_types
12 * @version 1.0.0
13 * @package PropertyHive/Classes
14 * @category Class
15 * @author PropertyHive
16 */
17 class PH_Post_types {
18
19 /**
20 * Constructor
21 */
22 public function __construct() {
23 add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 );
24 add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
25
26 add_action( 'wp_trash_post', array( __CLASS__, 'trash_property_children' ), 5 );
27
28 add_action( 'before_delete_post', array( __CLASS__, 'delete_property_media' ), 5 );
29 add_action( 'before_delete_post', array( __CLASS__, 'delete_property_children' ), 5 );
30 }
31
32 /**
33 * Register PropertyHive taxonomies.
34 */
35 public static function register_taxonomies() {
36
37 if ( taxonomy_exists( 'property_type' ) )
38 return;
39
40 do_action( 'propertyhive_register_taxonomy' );
41
42 //$permalinks = get_option( 'propertyhive_permalinks' );
43
44 register_taxonomy( 'availability',
45 'property',
46 array(
47 'label' => __( 'Availabilities', 'propertyhive' ),
48 'hierarchical' => true,
49 'show_ui' => false,
50 'show_in_nav_menus' => false,
51 'query_var' => is_admin(),
52 'rewrite' => false,
53 'public' => true
54 )
55 );
56
57 register_taxonomy( 'property_type',
58 array( 'property', 'appraisal' ),
59 array(
60 'label' => __( 'Property Types', 'propertyhive' ),
61 'hierarchical' => true,
62 'show_ui' => false,
63 'show_in_nav_menus' => false,
64 'query_var' => is_admin(),
65 'rewrite' => false,
66 'public' => true
67 )
68 );
69
70 register_taxonomy( 'commercial_property_type',
71 array( 'property', 'appraisal' ),
72 array(
73 'label' => __( 'Commercial Property Types', 'propertyhive' ),
74 'hierarchical' => true,
75 'show_ui' => false,
76 'show_in_nav_menus' => false,
77 'query_var' => is_admin(),
78 'rewrite' => false,
79 'public' => true
80 )
81 );
82
83 register_taxonomy( 'location',
84 'property',
85 array(
86 'label' => __( 'Locations', 'propertyhive' ),
87 'hierarchical' => true,
88 'show_ui' => false,
89 'show_in_nav_menus' => false,
90 'query_var' => is_admin(),
91 'rewrite' => false,
92 'public' => true
93 )
94 );
95
96 register_taxonomy( 'parking',
97 array( 'property', 'appraisal' ),
98 array(
99 'label' => __( 'Parking', 'propertyhive' ),
100 'hierarchical' => true,
101 'show_ui' => false,
102 'show_in_nav_menus' => false,
103 'query_var' => is_admin(),
104 'rewrite' => false,
105 'public' => true
106 )
107 );
108
109 register_taxonomy( 'outside_space',
110 array( 'property', 'appraisal' ),
111 array(
112 'label' => __( 'Outside Spaces', 'propertyhive' ),
113 'hierarchical' => true,
114 'show_ui' => false,
115 'show_in_nav_menus' => false,
116 'query_var' => is_admin(),
117 'rewrite' => false,
118 'public' => true
119 )
120 );
121
122 register_taxonomy( 'price_qualifier',
123 'property',
124 array(
125 'label' => __( 'Price Qualifiers', 'propertyhive' ),
126 'hierarchical' => true,
127 'show_ui' => false,
128 'show_in_nav_menus' => false,
129 'query_var' => is_admin(),
130 'rewrite' => false,
131 'public' => true
132 )
133 );
134
135 register_taxonomy( 'tenure',
136 'property',
137 array(
138 'label' => __( 'Tenures', 'propertyhive' ),
139 'hierarchical' => true,
140 'show_ui' => false,
141 'show_in_nav_menus' => false,
142 'query_var' => is_admin(),
143 'rewrite' => false,
144 'public' => true
145 )
146 );
147
148 register_taxonomy( 'commercial_tenure',
149 'property',
150 array(
151 'label' => __( 'Commercial Tenures', 'propertyhive' ),
152 'hierarchical' => true,
153 'show_ui' => false,
154 'show_in_nav_menus' => false,
155 'query_var' => is_admin(),
156 'rewrite' => false,
157 'public' => true
158 )
159 );
160
161 register_taxonomy( 'sale_by',
162 'property',
163 array(
164 'label' => __( 'Sale By', 'propertyhive' ),
165 'hierarchical' => true,
166 'show_ui' => false,
167 'show_in_nav_menus' => false,
168 'query_var' => is_admin(),
169 'rewrite' => false,
170 'public' => true
171 )
172 );
173
174 register_taxonomy( 'furnished',
175 array( 'property', 'appraisal' ),
176 array(
177 'label' => __( 'Furnished', 'propertyhive' ),
178 'hierarchical' => true,
179 'show_ui' => false,
180 'show_in_nav_menus' => false,
181 'query_var' => is_admin(),
182 'rewrite' => false,
183 'public' => true
184 )
185 );
186
187 register_taxonomy( 'marketing_flag',
188 'property',
189 array(
190 'label' => __( 'Marketing Flags', 'propertyhive' ),
191 'hierarchical' => true,
192 'show_ui' => false,
193 'show_in_nav_menus' => false,
194 'query_var' => is_admin(),
195 'rewrite' => false,
196 'public' => true
197 )
198 );
199
200 register_taxonomy( 'property_feature',
201 'property',
202 array(
203 'label' => __( 'Property Features', 'propertyhive' ),
204 'hierarchical' => true,
205 'show_ui' => false,
206 'show_in_nav_menus' => false,
207 'query_var' => is_admin(),
208 'rewrite' => false,
209 'public' => true
210 )
211 );
212
213 do_action( 'do_action_after_register_taxonomies' );
214 }
215
216 /**
217 * Register core post types
218 */
219 public static function register_post_types() {
220
221 if ( post_type_exists('property') )
222 return;
223
224 do_action( 'propertyhive_register_post_type' );
225
226 //$permalinks = get_option( 'property_permalinks' );
227 //$product_permalink = empty( $permalinks['property_base'] ) ? _x( 'property', 'slug', 'propertyhive' ) : $permalinks['property_base'];
228
229 register_post_type( "property",
230 apply_filters( 'propertyhive_register_post_type_property',
231 array(
232 'labels' => array(
233 'name' => __( 'Properties', 'propertyhive' ),
234 'singular_name' => __( 'Property', 'propertyhive' ),
235 'menu_name' => _x( 'Properties', 'Admin menu name', 'propertyhive' ),
236 'add_new' => __( 'Add Property', 'propertyhive' ),
237 'add_new_item' => __( 'Add New Property', 'propertyhive' ),
238 'edit' => __( 'Edit', 'propertyhive' ),
239 'edit_item' => __( 'Edit Property', 'propertyhive' ),
240 'new_item' => __( 'New Property', 'propertyhive' ),
241 'view' => __( 'View Property', 'propertyhive' ),
242 'view_item' => __( 'View Property', 'propertyhive' ),
243 'search_items' => __( 'Search Properties', 'propertyhive' ),
244 'not_found' => __( 'No properties found', 'propertyhive' ),
245 'not_found_in_trash' => __( 'No properties found in trash', 'propertyhive' ),
246 'parent' => __( 'Parent Property', 'propertyhive' )
247 ),
248 'description' => __( 'This is where you can add new properties to your site.', 'propertyhive' ),
249 'public' => true,
250 'show_ui' => true,
251 'capability_type' => 'post',
252 'map_meta_cap' => true,
253 'publicly_queryable' => true,
254 'exclude_from_search' => false,
255 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
256 //'rewrite' => $product_permalink ? array( 'slug' => untrailingslashit( $product_permalink ), 'with_front' => false, 'feeds' => true ) : false,
257 'query_var' => true,
258 'supports' => array( 'title', 'excerpt' ),
259 'has_archive' => ( $search_results_page_id = ph_get_page_id( 'search_results' ) ) && get_page( $search_results_page_id ) ? get_page_uri( $search_results_page_id ) : 'search_results',
260 'show_in_nav_menus' => false,
261 'show_in_menu' => false,
262 'show_in_admin_bar' => true,
263 'show_in_rest' => true,
264 )
265 )
266 );
267
268 register_post_type( "contact",
269 apply_filters( 'propertyhive_register_post_type_contact',
270 array(
271 'labels' => array(
272 'name' => __( 'Contacts', 'propertyhive' ),
273 'singular_name' => __( 'Contact', 'propertyhive' ),
274 'menu_name' => _x( 'Contacts', 'Admin menu name', 'propertyhive' ),
275 'add_new' => __( 'Add Contact', 'propertyhive' ),
276 'add_new_item' => __( 'Add New Contact', 'propertyhive' ),
277 'edit' => __( 'Edit', 'propertyhive' ),
278 'edit_item' => __( 'Edit Contact', 'propertyhive' ),
279 'new_item' => __( 'New Contact', 'propertyhive' ),
280 'view' => __( 'View Contact', 'propertyhive' ),
281 'view_item' => __( 'View Contact', 'propertyhive' ),
282 'search_items' => __( 'Search Contacts', 'propertyhive' ),
283 'not_found' => __( 'No contacts found', 'propertyhive' ),
284 'not_found_in_trash' => __( 'No contacts found in trash', 'propertyhive' ),
285 'parent' => __( 'Parent Contact', 'propertyhive' )
286 ),
287 'description' => __( 'This is where you can add new contacts to your site.', 'propertyhive' ),
288 'public' => false,
289 'show_ui' => true,
290 'capability_type' => 'post',
291 'map_meta_cap' => true,
292 'publicly_queryable' => false,
293 'exclude_from_search' => true,
294 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
295 'query_var' => true,
296 'supports' => array( 'title' ),
297 'show_in_nav_menus' => false,
298 'show_in_menu' => false
299 )
300 )
301 );
302
303 register_post_type( "office",
304 apply_filters( 'propertyhive_register_post_type_office',
305 array(
306 'labels' => array(
307 'name' => __( 'Offices', 'propertyhive' ),
308 'singular_name' => __( 'Office', 'propertyhive' ),
309 'menu_name' => _x( 'Offices', 'Admin menu name', 'propertyhive' ),
310 'add_new' => __( 'Add Office', 'propertyhive' ),
311 'add_new_item' => __( 'Add New Office', 'propertyhive' ),
312 'edit' => __( 'Edit', 'propertyhive' ),
313 'edit_item' => __( 'Edit Office', 'propertyhive' ),
314 'new_item' => __( 'New Office', 'propertyhive' ),
315 'view' => __( 'View Office', 'propertyhive' ),
316 'view_item' => __( 'View Office', 'propertyhive' ),
317 'search_items' => __( 'Search Offices', 'propertyhive' ),
318 'not_found' => __( 'No offices found', 'propertyhive' ),
319 'not_found_in_trash' => __( 'No offices found in trash', 'propertyhive' ),
320 'parent' => __( 'Parent Office', 'propertyhive' )
321 ),
322 'public' => true,
323 'show_ui' => false,
324 'capability_type' => 'post',
325 'map_meta_cap' => true,
326 'publicly_queryable' => false,
327 'exclude_from_search' => true,
328 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
329 'query_var' => true,
330 'supports' => array( 'title' ),
331 'show_in_nav_menus' => false,
332 'show_in_menu' => false
333 )
334 )
335 );
336
337 register_post_type( "enquiry",
338 apply_filters( 'propertyhive_register_post_type_enquiry',
339 array(
340 'labels' => array(
341 'name' => __( 'Enquiries', 'propertyhive' ),
342 'singular_name' => __( 'Enquiry', 'propertyhive' ),
343 'menu_name' => _x( 'Enquiries', 'Admin menu name', 'propertyhive' ),
344 'add_new' => __( 'Add Enquiry', 'propertyhive' ),
345 'add_new_item' => __( 'Add New Enquiry', 'propertyhive' ),
346 'edit' => __( 'Edit', 'propertyhive' ),
347 'edit_item' => __( 'Edit Enquiry', 'propertyhive' ),
348 'new_item' => __( 'New Enquiry', 'propertyhive' ),
349 'view' => __( 'View Enquiry', 'propertyhive' ),
350 'view_item' => __( 'View Enquiry', 'propertyhive' ),
351 'search_items' => __( 'Search Enquiries', 'propertyhive' ),
352 'not_found' => __( 'No enquiries found', 'propertyhive' ),
353 'not_found_in_trash' => __( 'No enquiries found in trash', 'propertyhive' ),
354 'parent' => __( 'Parent Enquiry', 'propertyhive' )
355 ),
356 'public' => false,
357 'show_ui' => true,
358 'capability_type' => 'post',
359 'map_meta_cap' => true,
360 'publicly_queryable' => false,
361 'exclude_from_search' => true,
362 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
363 'query_var' => true,
364 'supports' => array( 'title' ),
365 'show_in_nav_menus' => false,
366 'show_in_menu' => false
367 )
368 )
369 );
370
371 register_post_type( "appraisal",
372 apply_filters( 'propertyhive_register_post_type_appraisal',
373 array(
374 'labels' => array(
375 'name' => __( 'Appraisals', 'propertyhive' ),
376 'singular_name' => __( 'Appraisal', 'propertyhive' ),
377 'menu_name' => _x( 'Appraisals', 'Admin menu name', 'propertyhive' ),
378 'add_new' => __( 'Add Appraisal', 'propertyhive' ),
379 'add_new_item' => __( 'Add New Appraisal', 'propertyhive' ),
380 'edit' => __( 'Edit', 'propertyhive' ),
381 'edit_item' => __( 'Edit Appraisal', 'propertyhive' ),
382 'new_item' => __( 'New Appraisal', 'propertyhive' ),
383 'view' => __( 'View Appraisal', 'propertyhive' ),
384 'view_item' => __( 'View Appraisal', 'propertyhive' ),
385 'search_items' => __( 'Search Appraisals', 'propertyhive' ),
386 'not_found' => __( 'No appraisals found', 'propertyhive' ),
387 'not_found_in_trash' => __( 'No appraisals found in trash', 'propertyhive' ),
388 'parent' => __( 'Parent Appraisal', 'propertyhive' )
389 ),
390 'public' => false,
391 'show_ui' => true,
392 'capability_type' => 'post',
393 'map_meta_cap' => true,
394 'publicly_queryable' => false,
395 'exclude_from_search' => true,
396 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
397 'query_var' => true,
398 'supports' => false,
399 'show_in_nav_menus' => false,
400 'show_in_menu' => false
401 )
402 )
403 );
404
405 register_post_type( "viewing",
406 apply_filters( 'propertyhive_register_post_type_viewing',
407 array(
408 'labels' => array(
409 'name' => __( 'Viewings', 'propertyhive' ),
410 'singular_name' => __( 'Viewing', 'propertyhive' ),
411 'menu_name' => _x( 'Viewings', 'Admin menu name', 'propertyhive' ),
412 'add_new' => __( 'Add Viewing', 'propertyhive' ),
413 'add_new_item' => __( 'Add New Viewing', 'propertyhive' ),
414 'edit' => __( 'Edit', 'propertyhive' ),
415 'edit_item' => __( 'Edit Viewing', 'propertyhive' ),
416 'new_item' => __( 'New Viewing', 'propertyhive' ),
417 'view' => __( 'View Viewing', 'propertyhive' ),
418 'view_item' => __( 'View Viewing', 'propertyhive' ),
419 'search_items' => __( 'Search Viewings', 'propertyhive' ),
420 'not_found' => __( 'No viewings found', 'propertyhive' ),
421 'not_found_in_trash' => __( 'No viewings found in trash', 'propertyhive' ),
422 'parent' => __( 'Parent Viewing', 'propertyhive' )
423 ),
424 'public' => false,
425 'show_ui' => true,
426 'capability_type' => 'post',
427 'map_meta_cap' => true,
428 'publicly_queryable' => false,
429 'exclude_from_search' => true,
430 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
431 'query_var' => true,
432 'supports' => false,
433 'show_in_nav_menus' => false,
434 'show_in_menu' => false
435 )
436 )
437 );
438
439 register_post_type( "offer",
440 apply_filters( 'propertyhive_register_post_type_offer',
441 array(
442 'labels' => array(
443 'name' => __( 'Offers', 'propertyhive' ),
444 'singular_name' => __( 'Offer', 'propertyhive' ),
445 'menu_name' => _x( 'Offers', 'Admin menu name', 'propertyhive' ),
446 'add_new' => __( 'Add Offer', 'propertyhive' ),
447 'add_new_item' => __( 'Add New Offer', 'propertyhive' ),
448 'edit' => __( 'Edit', 'propertyhive' ),
449 'edit_item' => __( 'Edit Offer', 'propertyhive' ),
450 'new_item' => __( 'New Offer', 'propertyhive' ),
451 'view' => __( 'View Offer', 'propertyhive' ),
452 'view_item' => __( 'View Offer', 'propertyhive' ),
453 'search_items' => __( 'Search Offers', 'propertyhive' ),
454 'not_found' => __( 'No offers found', 'propertyhive' ),
455 'not_found_in_trash' => __( 'No offers found in trash', 'propertyhive' ),
456 'parent' => __( 'Parent Offer', 'propertyhive' )
457 ),
458 'public' => false,
459 'show_ui' => true,
460 'capability_type' => 'post',
461 'map_meta_cap' => true,
462 'publicly_queryable' => false,
463 'exclude_from_search' => true,
464 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
465 'query_var' => true,
466 'supports' => false,
467 'show_in_nav_menus' => false,
468 'show_in_menu' => false
469 )
470 )
471 );
472
473 register_post_type( "sale",
474 apply_filters( 'propertyhive_register_post_type_sale',
475 array(
476 'labels' => array(
477 'name' => __( 'Sales', 'propertyhive' ),
478 'singular_name' => __( 'Sale', 'propertyhive' ),
479 'menu_name' => _x( 'Sales', 'Admin menu name', 'propertyhive' ),
480 'add_new' => __( 'Add Sale', 'propertyhive' ),
481 'add_new_item' => __( 'Add New Sale', 'propertyhive' ),
482 'edit' => __( 'Edit', 'propertyhive' ),
483 'edit_item' => __( 'Edit Sale', 'propertyhive' ),
484 'new_item' => __( 'New Sale', 'propertyhive' ),
485 'view' => __( 'View Sale', 'propertyhive' ),
486 'view_item' => __( 'View Sale', 'propertyhive' ),
487 'search_items' => __( 'Search Sales', 'propertyhive' ),
488 'not_found' => __( 'No sales found', 'propertyhive' ),
489 'not_found_in_trash' => __( 'No sales found in trash', 'propertyhive' ),
490 'parent' => __( 'Parent Sale', 'propertyhive' )
491 ),
492 'public' => false,
493 'show_ui' => true,
494 'capability_type' => 'post',
495 'capabilities' => array(
496 'create_posts' => false
497 ),
498 'map_meta_cap' => true,
499 'publicly_queryable' => false,
500 'exclude_from_search' => true,
501 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
502 'query_var' => true,
503 'supports' => false,
504 'show_in_nav_menus' => false,
505 'show_in_menu' => false
506 )
507 )
508 );
509
510 do_action( 'propertyhive_after_register_post_types' );
511 }
512
513 public static function trash_property_children( $post_id )
514 {
515 if ( get_post_type($post_id) == 'property' )
516 {
517 // get all children
518 $args = array(
519 'post_type' => 'property',
520 'nopaging' => true,
521 'post_parent' => (int)$post_id,
522 'post_status' => array('publish', 'pending', 'private', 'draft', 'auto-draft', 'future'),
523 );
524
525 $properties_query = new WP_Query($args);
526
527 if ( $properties_query->have_posts() )
528 {
529 while( $properties_query->have_posts() )
530 {
531 $properties_query->the_post();
532
533 wp_trash_post( get_the_ID() );
534 }
535 }
536 wp_reset_postdata();
537 }
538 }
539
540 public static function delete_property_media( $post_id )
541 {
542 if ( get_post_type($post_id) == 'property' )
543 {
544 $property = new PH_Property( (int)$post_id );
545
546 $media_ids = $property->get_gallery_attachment_ids();
547 self::do_delete_media_attachments( $post_id, $media_ids );
548
549 $media_ids = $property->get_floorplan_attachment_ids();
550 self::do_delete_media_attachments( $post_id, $media_ids );
551
552 $media_ids = $property->get_brochure_attachment_ids();
553 self::do_delete_media_attachments( $post_id, $media_ids );
554
555 $media_ids = $property->get_epc_attachment_ids();
556 self::do_delete_media_attachments( $post_id, $media_ids );
557 }
558 }
559
560 private static function do_delete_media_attachments( $post_id, $media_ids = array() )
561 {
562 if ( is_array($media_ids) && !empty($media_ids) )
563 {
564 foreach ( $media_ids as $media_id )
565 {
566 // Make sure this media isn't used anywhere else
567 $args = array(
568 'post_type' => 'property',
569 'fields' => 'ids',
570 'posts_per_page' => 1,
571 'post__not_in' => array( $post_id ),
572 'meta_query' => array(
573 'relation' => 'OR',
574 array(
575 'key' => '_photos',
576 'value' => ':' . $media_id . ';',
577 'compare' => 'LIKE'
578 ),
579 array(
580 'key' => '_photos',
581 'value' => ':"' . $media_id . '";',
582 'compare' => 'LIKE'
583 ),
584 array(
585 'key' => '_floorplans',
586 'value' => ':' . $media_id . ';',
587 'compare' => 'LIKE'
588 ),
589 array(
590 'key' => '_floorplans',
591 'value' => ':"' . $media_id . '";',
592 'compare' => 'LIKE'
593 ),
594 array(
595 'key' => '_epcs',
596 'value' => ':' . $media_id . ';',
597 'compare' => 'LIKE'
598 ),
599 array(
600 'key' => '_epcs',
601 'value' => ':"' . $media_id . '";',
602 'compare' => 'LIKE'
603 ),
604 array(
605 'key' => '_brochures',
606 'value' => ':' . $media_id . ';',
607 'compare' => 'LIKE'
608 ),
609 array(
610 'key' => '_brochures',
611 'value' => ':"' . $media_id . '";',
612 'compare' => 'LIKE'
613 ),
614 )
615 );
616
617 $property_query = new WP_Query( $args );
618
619 if ( !$property_query->have_posts() )
620 {
621 // We're ok to delete
622 wp_delete_attachment( $media_id, true );
623 }
624 }
625 }
626 }
627
628 public static function delete_property_children( $post_id )
629 {
630 if ( get_post_type($post_id) == 'property' )
631 {
632 // get all children
633 $args = array(
634 'post_type' => 'property',
635 'nopaging' => true,
636 'post_parent' => (int)$post_id,
637 'post_status' => array('publish', 'pending', 'private', 'draft', 'auto-draft', 'future', 'trash'),
638 );
639
640 $properties_query = new WP_Query($args);
641
642 if ( $properties_query->have_posts() )
643 {
644 while( $properties_query->have_posts() )
645 {
646 $properties_query->the_post();
647
648 wp_delete_post( get_the_ID(), true );
649 }
650 }
651 wp_reset_postdata();
652 }
653 }
654 }
655
656 new PH_Post_types();
657