PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
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.5, at includes/class-ph-post-types.php

534 lines 23.7 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( 'before_delete_post', array( __CLASS__, 'delete_property_media' ), 5 );
27 }
28
29 /**
30 * Register PropertyHive taxonomies.
31 */
32 public static function register_taxonomies() {
33
34 if ( taxonomy_exists( 'property_type' ) )
35 return;
36
37 do_action( 'propertyhive_register_taxonomy' );
38
39 //$permalinks = get_option( 'propertyhive_permalinks' );
40
41 register_taxonomy( 'availability',
42 'property',
43 array(
44 'hierarchical' => true,
45 'show_ui' => false,
46 'show_in_nav_menus' => false,
47 'query_var' => is_admin(),
48 'rewrite' => false,
49 'public' => true
50 )
51 );
52
53 register_taxonomy( 'property_type',
54 'property',
55 array(
56 'hierarchical' => true,
57 'show_ui' => false,
58 'show_in_nav_menus' => false,
59 'query_var' => is_admin(),
60 'rewrite' => false,
61 'public' => true
62 )
63 );
64
65 register_taxonomy( 'commercial_property_type',
66 'property',
67 array(
68 'hierarchical' => true,
69 'show_ui' => false,
70 'show_in_nav_menus' => false,
71 'query_var' => is_admin(),
72 'rewrite' => false,
73 'public' => true
74 )
75 );
76
77 register_taxonomy( 'location',
78 'property',
79 array(
80 'hierarchical' => true,
81 'show_ui' => false,
82 'show_in_nav_menus' => false,
83 'query_var' => is_admin(),
84 'rewrite' => false,
85 'public' => true
86 )
87 );
88
89 register_taxonomy( 'parking',
90 'property',
91 array(
92 'hierarchical' => true,
93 'show_ui' => false,
94 'show_in_nav_menus' => false,
95 'query_var' => is_admin(),
96 'rewrite' => false,
97 'public' => true
98 )
99 );
100
101 register_taxonomy( 'outside_space',
102 'property',
103 array(
104 'hierarchical' => true,
105 'show_ui' => false,
106 'show_in_nav_menus' => false,
107 'query_var' => is_admin(),
108 'rewrite' => false,
109 'public' => true
110 )
111 );
112
113 register_taxonomy( 'price_qualifier',
114 'property',
115 array(
116 'hierarchical' => true,
117 'show_ui' => false,
118 'show_in_nav_menus' => false,
119 'query_var' => is_admin(),
120 'rewrite' => false,
121 'public' => true
122 )
123 );
124
125 register_taxonomy( 'tenure',
126 'property',
127 array(
128 'hierarchical' => true,
129 'show_ui' => false,
130 'show_in_nav_menus' => false,
131 'query_var' => is_admin(),
132 'rewrite' => false,
133 'public' => true
134 )
135 );
136
137 register_taxonomy( 'commercial_tenure',
138 'property',
139 array(
140 'hierarchical' => true,
141 'show_ui' => false,
142 'show_in_nav_menus' => false,
143 'query_var' => is_admin(),
144 'rewrite' => false,
145 'public' => true
146 )
147 );
148
149 register_taxonomy( 'sale_by',
150 'property',
151 array(
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( 'furnished',
162 'property',
163 array(
164 'hierarchical' => true,
165 'show_ui' => false,
166 'show_in_nav_menus' => false,
167 'query_var' => is_admin(),
168 'rewrite' => false,
169 'public' => true
170 )
171 );
172
173 register_taxonomy( 'marketing_flag',
174 'property',
175 array(
176 'hierarchical' => true,
177 'show_ui' => false,
178 'show_in_nav_menus' => false,
179 'query_var' => is_admin(),
180 'rewrite' => false,
181 'public' => true
182 )
183 );
184
185 register_taxonomy( 'property_feature',
186 'property',
187 array(
188 'hierarchical' => true,
189 'show_ui' => false,
190 'show_in_nav_menus' => false,
191 'query_var' => is_admin(),
192 'rewrite' => false,
193 'public' => true
194 )
195 );
196
197 do_action( 'do_action_after_register_taxonomies' );
198 }
199
200 /**
201 * Register core post types
202 */
203 public static function register_post_types() {
204
205 if ( post_type_exists('property') )
206 return;
207
208 do_action( 'propertyhive_register_post_type' );
209
210 //$permalinks = get_option( 'property_permalinks' );
211 //$product_permalink = empty( $permalinks['property_base'] ) ? _x( 'property', 'slug', 'propertyhive' ) : $permalinks['property_base'];
212
213 register_post_type( "property",
214 apply_filters( 'propertyhive_register_post_type_property',
215 array(
216 'labels' => array(
217 'name' => __( 'Properties', 'propertyhive' ),
218 'singular_name' => __( 'Property', 'propertyhive' ),
219 'menu_name' => _x( 'Properties', 'Admin menu name', 'propertyhive' ),
220 'add_new' => __( 'Add Property', 'propertyhive' ),
221 'add_new_item' => __( 'Add New Property', 'propertyhive' ),
222 'edit' => __( 'Edit', 'propertyhive' ),
223 'edit_item' => __( 'Edit Property', 'propertyhive' ),
224 'new_item' => __( 'New Property', 'propertyhive' ),
225 'view' => __( 'View Property', 'propertyhive' ),
226 'view_item' => __( 'View Property', 'propertyhive' ),
227 'search_items' => __( 'Search Properties', 'propertyhive' ),
228 'not_found' => __( 'No properties found', 'propertyhive' ),
229 'not_found_in_trash' => __( 'No properties found in trash', 'propertyhive' ),
230 'parent' => __( 'Parent Property', 'propertyhive' )
231 ),
232 'description' => __( 'This is where you can add new properties to your site.', 'propertyhive' ),
233 'public' => true,
234 'show_ui' => true,
235 'capability_type' => 'post',
236 'map_meta_cap' => true,
237 'publicly_queryable' => true,
238 'exclude_from_search' => false,
239 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
240 //'rewrite' => $product_permalink ? array( 'slug' => untrailingslashit( $product_permalink ), 'with_front' => false, 'feeds' => true ) : false,
241 'query_var' => true,
242 'supports' => array( 'title', 'excerpt' ),
243 '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',
244 'show_in_nav_menus' => false,
245 'show_in_menu' => false,
246 'show_in_admin_bar' => true,
247 'show_in_rest' => true,
248 )
249 )
250 );
251
252 register_post_type( "contact",
253 apply_filters( 'propertyhive_register_post_type_contact',
254 array(
255 'labels' => array(
256 'name' => __( 'Contacts', 'propertyhive' ),
257 'singular_name' => __( 'Contact', 'propertyhive' ),
258 'menu_name' => _x( 'Contacts', 'Admin menu name', 'propertyhive' ),
259 'add_new' => __( 'Add Contact', 'propertyhive' ),
260 'add_new_item' => __( 'Add New Contact', 'propertyhive' ),
261 'edit' => __( 'Edit', 'propertyhive' ),
262 'edit_item' => __( 'Edit Contact', 'propertyhive' ),
263 'new_item' => __( 'New Contact', 'propertyhive' ),
264 'view' => __( 'View Contact', 'propertyhive' ),
265 'view_item' => __( 'View Contact', 'propertyhive' ),
266 'search_items' => __( 'Search Contacts', 'propertyhive' ),
267 'not_found' => __( 'No contacts found', 'propertyhive' ),
268 'not_found_in_trash' => __( 'No contacts found in trash', 'propertyhive' ),
269 'parent' => __( 'Parent Contact', 'propertyhive' )
270 ),
271 'description' => __( 'This is where you can add new contacts to your site.', 'propertyhive' ),
272 'public' => false,
273 'show_ui' => true,
274 'capability_type' => 'post',
275 'map_meta_cap' => true,
276 'publicly_queryable' => true,
277 'exclude_from_search' => true,
278 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
279 'query_var' => true,
280 'supports' => array( 'title' ),
281 'show_in_nav_menus' => false,
282 'show_in_menu' => false
283 )
284 )
285 );
286
287 register_post_type( "office",
288 apply_filters( 'propertyhive_register_post_type_office',
289 array(
290 'public' => true,
291 'show_ui' => false,
292 'capability_type' => 'post',
293 'map_meta_cap' => true,
294 'publicly_queryable' => true,
295 'exclude_from_search' => true,
296 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
297 'query_var' => true,
298 'supports' => array( 'title' ),
299 'show_in_nav_menus' => false,
300 'show_in_menu' => false
301 )
302 )
303 );
304
305 register_post_type( "enquiry",
306 apply_filters( 'propertyhive_register_post_type_enquiry',
307 array(
308 'labels' => array(
309 'name' => __( 'Enquiries', 'propertyhive' ),
310 'singular_name' => __( 'Enquiry', 'propertyhive' ),
311 'menu_name' => _x( 'Enquiries', 'Admin menu name', 'propertyhive' ),
312 'add_new' => __( 'Add Enquiry', 'propertyhive' ),
313 'add_new_item' => __( 'Add New Enquiry', 'propertyhive' ),
314 'edit' => __( 'Edit', 'propertyhive' ),
315 'edit_item' => __( 'Edit Enquiry', 'propertyhive' ),
316 'new_item' => __( 'New Enquiry', 'propertyhive' ),
317 'view' => __( 'View Enquiry', 'propertyhive' ),
318 'view_item' => __( 'View Enquiry', 'propertyhive' ),
319 'search_items' => __( 'Search Enquiries', 'propertyhive' ),
320 'not_found' => __( 'No enquiries found', 'propertyhive' ),
321 'not_found_in_trash' => __( 'No enquiries found in trash', 'propertyhive' ),
322 'parent' => __( 'Parent Enquiry', 'propertyhive' )
323 ),
324 'public' => false,
325 'show_ui' => true,
326 'capability_type' => 'post',
327 'map_meta_cap' => true,
328 'publicly_queryable' => false,
329 'exclude_from_search' => true,
330 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
331 'query_var' => true,
332 'supports' => array( 'title' ),
333 'show_in_nav_menus' => false,
334 'show_in_menu' => false
335 )
336 )
337 );
338
339 register_post_type( "viewing",
340 apply_filters( 'propertyhive_register_post_type_viewing',
341 array(
342 'labels' => array(
343 'name' => __( 'Viewings', 'propertyhive' ),
344 'singular_name' => __( 'Viewing', 'propertyhive' ),
345 'menu_name' => _x( 'Viewings', 'Admin menu name', 'propertyhive' ),
346 'add_new' => __( 'Add Viewing', 'propertyhive' ),
347 'add_new_item' => __( 'Add New Viewing', 'propertyhive' ),
348 'edit' => __( 'Edit', 'propertyhive' ),
349 'edit_item' => __( 'Edit Viewing', 'propertyhive' ),
350 'new_item' => __( 'New Viewing', 'propertyhive' ),
351 'view' => __( 'View Viewing', 'propertyhive' ),
352 'view_item' => __( 'View Viewing', 'propertyhive' ),
353 'search_items' => __( 'Search Viewings', 'propertyhive' ),
354 'not_found' => __( 'No viewings found', 'propertyhive' ),
355 'not_found_in_trash' => __( 'No viewings found in trash', 'propertyhive' ),
356 'parent' => __( 'Parent Viewing', 'propertyhive' )
357 ),
358 'public' => false,
359 'show_ui' => true,
360 'capability_type' => 'post',
361 'map_meta_cap' => true,
362 'publicly_queryable' => false,
363 'exclude_from_search' => true,
364 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
365 'query_var' => true,
366 'supports' => false,
367 'show_in_nav_menus' => false,
368 'show_in_menu' => false
369 )
370 )
371 );
372
373 register_post_type( "offer",
374 apply_filters( 'propertyhive_register_post_type_offer',
375 array(
376 'labels' => array(
377 'name' => __( 'Offers', 'propertyhive' ),
378 'singular_name' => __( 'Offer', 'propertyhive' ),
379 'menu_name' => _x( 'Offers', 'Admin menu name', 'propertyhive' ),
380 'add_new' => __( 'Add Offer', 'propertyhive' ),
381 'add_new_item' => __( 'Add New Offer', 'propertyhive' ),
382 'edit' => __( 'Edit', 'propertyhive' ),
383 'edit_item' => __( 'Edit Offer', 'propertyhive' ),
384 'new_item' => __( 'New Offer', 'propertyhive' ),
385 'view' => __( 'View Offer', 'propertyhive' ),
386 'view_item' => __( 'View Offer', 'propertyhive' ),
387 'search_items' => __( 'Search Offers', 'propertyhive' ),
388 'not_found' => __( 'No offers found', 'propertyhive' ),
389 'not_found_in_trash' => __( 'No offers found in trash', 'propertyhive' ),
390 'parent' => __( 'Parent Offer', 'propertyhive' )
391 ),
392 'public' => false,
393 'show_ui' => true,
394 'capability_type' => 'post',
395 'map_meta_cap' => true,
396 'publicly_queryable' => false,
397 'exclude_from_search' => true,
398 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
399 'query_var' => true,
400 'supports' => false,
401 'show_in_nav_menus' => false,
402 'show_in_menu' => false
403 )
404 )
405 );
406
407 register_post_type( "sale",
408 apply_filters( 'propertyhive_register_post_type_sale',
409 array(
410 'labels' => array(
411 'name' => __( 'Sales', 'propertyhive' ),
412 'singular_name' => __( 'Sale', 'propertyhive' ),
413 'menu_name' => _x( 'Sales', 'Admin menu name', 'propertyhive' ),
414 'add_new' => __( 'Add Sale', 'propertyhive' ),
415 'add_new_item' => __( 'Add New Sale', 'propertyhive' ),
416 'edit' => __( 'Edit', 'propertyhive' ),
417 'edit_item' => __( 'Edit Sale', 'propertyhive' ),
418 'new_item' => __( 'New Sale', 'propertyhive' ),
419 'view' => __( 'View Sale', 'propertyhive' ),
420 'view_item' => __( 'View Sale', 'propertyhive' ),
421 'search_items' => __( 'Search Sales', 'propertyhive' ),
422 'not_found' => __( 'No sales found', 'propertyhive' ),
423 'not_found_in_trash' => __( 'No sales found in trash', 'propertyhive' ),
424 'parent' => __( 'Parent Sale', 'propertyhive' )
425 ),
426 'public' => false,
427 'show_ui' => true,
428 'capability_type' => 'post',
429 'capabilities' => array(
430 'create_posts' => false
431 ),
432 'map_meta_cap' => true,
433 'publicly_queryable' => false,
434 'exclude_from_search' => true,
435 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
436 'query_var' => true,
437 'supports' => false,
438 'show_in_nav_menus' => false,
439 'show_in_menu' => false
440 )
441 )
442 );
443
444 do_action( 'propertyhive_after_register_post_types' );
445 }
446
447 public static function delete_property_media( $post_id ) {
448
449 $property = new PH_Property( (int)$post_id );
450
451 $media_ids = $property->get_gallery_attachment_ids();
452 self::do_delete_media_attachments( $post_id, $media_ids );
453
454 $media_ids = $property->get_floorplan_attachment_ids();
455 self::do_delete_media_attachments( $post_id, $media_ids );
456
457 $media_ids = $property->get_brochure_attachment_ids();
458 self::do_delete_media_attachments( $post_id, $media_ids );
459
460 $media_ids = $property->get_epc_attachment_ids();
461 self::do_delete_media_attachments( $post_id, $media_ids );
462 }
463
464 private static function do_delete_media_attachments( $post_id, $media_ids = array() )
465 {
466 if ( is_array($media_ids) && !empty($media_ids) )
467 {
468 foreach ( $media_ids as $media_id )
469 {
470 // Make sure this media isn't used anywhere else
471 $args = array(
472 'post_type' => 'property',
473 'fields' => 'ids',
474 'posts_per_page' => 1,
475 'post__not_in' => array( $post_id ),
476 'meta_query' => array(
477 'relation' => 'OR',
478 array(
479 'key' => '_photos',
480 'value' => ':' . $media_id . ';',
481 'compare' => 'LIKE'
482 ),
483 array(
484 'key' => '_photos',
485 'value' => ':"' . $media_id . '";',
486 'compare' => 'LIKE'
487 ),
488 array(
489 'key' => '_floorplans',
490 'value' => ':' . $media_id . ';',
491 'compare' => 'LIKE'
492 ),
493 array(
494 'key' => '_floorplans',
495 'value' => ':"' . $media_id . '";',
496 'compare' => 'LIKE'
497 ),
498 array(
499 'key' => '_epcs',
500 'value' => ':' . $media_id . ';',
501 'compare' => 'LIKE'
502 ),
503 array(
504 'key' => '_epcs',
505 'value' => ':"' . $media_id . '";',
506 'compare' => 'LIKE'
507 ),
508 array(
509 'key' => '_brochures',
510 'value' => ':' . $media_id . ';',
511 'compare' => 'LIKE'
512 ),
513 array(
514 'key' => '_brochures',
515 'value' => ':"' . $media_id . '";',
516 'compare' => 'LIKE'
517 ),
518 )
519 );
520
521 $property_query = new WP_Query( $args );
522
523 if ( !$property_query->have_posts() )
524 {
525 // We're ok to delete
526 wp_delete_attachment( $media_id, true );
527 }
528 }
529 }
530 }
531 }
532
533 new PH_Post_types();
534