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