| 1 |
<?php |
| 2 |
/** |
| 3 |
* Installation related functions and actions. |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Classes |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 12 |
|
| 13 |
if ( ! class_exists( 'PH_Install' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* PH_Install Class |
| 17 |
*/ |
| 18 |
class PH_Install { |
| 19 |
|
| 20 |
/** |
| 21 |
* DB updates and callbacks that need to be run per version. |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
private static $db_updates = array( |
| 26 |
'1.4.68' => array( |
| 27 |
'propertyhive_update_1468_on_market_change_dates', |
| 28 |
), |
| 29 |
'2.0.0' => array( |
| 30 |
'propertyhive_update_200_pre_pro_record_installed_plugins', |
| 31 |
), |
| 32 |
'2.2.0' => array( |
| 33 |
'propertyhive_deactivate_template_assistant', // different naming convention as needs to be run elsewhere too |
| 34 |
), |
| 35 |
); |
| 36 |
|
| 37 |
/** |
| 38 |
* Hook in tabs. |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
register_activation_hook( PH_PLUGIN_FILE, array( $this, 'install' ) ); |
| 42 |
register_deactivation_hook( PH_PLUGIN_FILE, array( $this, 'deactivate' ) ); |
| 43 |
|
| 44 |
add_action( 'admin_init', array( $this, 'install_actions' ) ); |
| 45 |
add_action( 'admin_init', array( $this, 'check_version' ), 5 ); |
| 46 |
|
| 47 |
add_filter( 'cron_schedules', array( $this, 'custom_cron_recurrence' ) ); |
| 48 |
//add_action( 'in_plugin_update_message-propertyhive/propertyhive.php', array( $this, 'in_plugin_update_message' ) ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* check_version function. |
| 53 |
* |
| 54 |
* @access public |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function check_version() { |
| 58 |
if ( ! defined( 'IFRAME_REQUEST' ) && ( get_option( 'propertyhive_version' ) != PH()->version || get_option( 'propertyhive_db_version' ) != PH()->version ) ) { |
| 59 |
$this->install(); |
| 60 |
|
| 61 |
do_action( 'propertyhive_updated' ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Install actions such as installing pages when a button is clicked. |
| 67 |
*/ |
| 68 |
public function install_actions() { |
| 69 |
|
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Install Property Hive |
| 75 |
*/ |
| 76 |
public function install() { |
| 77 |
|
| 78 |
$this->create_options(); |
| 79 |
$this->create_tables(); |
| 80 |
$this->create_roles(); |
| 81 |
|
| 82 |
// Register post types |
| 83 |
include_once( 'class-ph-post-types.php' ); |
| 84 |
PH_Post_types::register_post_types(); |
| 85 |
PH_Post_types::register_taxonomies(); |
| 86 |
|
| 87 |
$this->create_primary_office(); |
| 88 |
$this->create_cron_jobs(); |
| 89 |
|
| 90 |
$this->update(); |
| 91 |
|
| 92 |
// Clear transient cache |
| 93 |
|
| 94 |
// Queue upgrades |
| 95 |
$current_version = get_option( 'propertyhive_version', null ); |
| 96 |
$current_db_version = get_option( 'propertyhive_db_version', null ); |
| 97 |
|
| 98 |
// No existing version set. This must be a new fresh install |
| 99 |
if ( is_null( $current_version ) && is_null( $current_db_version ) ) |
| 100 |
{ |
| 101 |
$this->create_terms(); |
| 102 |
$this->create_pages(); |
| 103 |
set_transient( '_ph_activation_redirect', 1, 30 ); |
| 104 |
} |
| 105 |
|
| 106 |
update_option( 'propertyhive_db_version', PH()->version ); |
| 107 |
|
| 108 |
// Check if pages are needed |
| 109 |
if ( ph_get_page_id( 'search_results' ) < 1 ) { |
| 110 |
update_option( '_ph_needs_pages', 1 ); |
| 111 |
} |
| 112 |
|
| 113 |
// Update version |
| 114 |
update_option( 'propertyhive_version', PH()->version ); |
| 115 |
|
| 116 |
// Flush rules after install |
| 117 |
flush_rewrite_rules(); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Deactivate Property Hive |
| 122 |
*/ |
| 123 |
public function deactivate() { |
| 124 |
// Cron jobs |
| 125 |
wp_clear_scheduled_hook( 'propertyhive_update_currency_exchange_rates' ); |
| 126 |
wp_clear_scheduled_hook( 'propertyhive_process_email_log' ); |
| 127 |
wp_clear_scheduled_hook( 'propertyhive_auto_email_match' ); |
| 128 |
wp_clear_scheduled_hook( 'propertyhive_check_licenses' ); |
| 129 |
wp_clear_scheduled_hook( 'propertyhive_update_address_concatenated' ); |
| 130 |
wp_clear_scheduled_hook( 'propertyhive_cleanup_search_analytics' ); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Get list of DB update callbacks. |
| 135 |
* |
| 136 |
* @return array |
| 137 |
*/ |
| 138 |
public static function get_db_update_callbacks() { |
| 139 |
return self::$db_updates; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Handle updates |
| 144 |
*/ |
| 145 |
public function update() { |
| 146 |
// Do updates |
| 147 |
$current_db_version = get_option( 'propertyhive_db_version' ); |
| 148 |
|
| 149 |
foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) { |
| 150 |
if ( version_compare( $current_db_version, $version, '<' ) ) { |
| 151 |
foreach ( $update_callbacks as $update_callback ) { |
| 152 |
add_action('property_run_update_actions', $update_callback); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
do_action('property_run_update_actions'); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Create cron jobs (clear them first) |
| 161 |
*/ |
| 162 |
private function create_cron_jobs() { |
| 163 |
|
| 164 |
// Cron jobs |
| 165 |
wp_clear_scheduled_hook( 'propertyhive_update_currency_exchange_rates' ); |
| 166 |
wp_clear_scheduled_hook( 'propertyhive_process_email_log' ); |
| 167 |
wp_clear_scheduled_hook( 'propertyhive_auto_email_match' ); |
| 168 |
wp_clear_scheduled_hook( 'propertyhive_check_licenses' ); |
| 169 |
wp_clear_scheduled_hook( 'propertyhive_update_address_concatenated' ); |
| 170 |
wp_clear_scheduled_hook( 'propertyhive_cleanup_search_analytics' ); |
| 171 |
|
| 172 |
// Schedule for midnight as it's likely traffic will be quieter at that time |
| 173 |
wp_schedule_event( strtotime( 'tomorrow' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_update_currency_exchange_rates' ); |
| 174 |
|
| 175 |
wp_schedule_event( time(), 'every_fifteen_minutes', 'propertyhive_process_email_log' ); |
| 176 |
|
| 177 |
$auto_property_match_enabled = get_option( 'propertyhive_auto_property_match', '' ); |
| 178 |
|
| 179 |
if ( $auto_property_match_enabled == 'yes' ) |
| 180 |
{ |
| 181 |
$recurrence = apply_filters( 'propertyhive_auto_email_match_cron_recurrence', 'daily' ); |
| 182 |
if ( $recurrence != 'hourly' ) |
| 183 |
{ |
| 184 |
$timestamp = strtotime( 'tomorrow +2hours') - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
| 185 |
} |
| 186 |
else |
| 187 |
{ |
| 188 |
$timestamp = strtotime( '+1 hours' ); |
| 189 |
} |
| 190 |
wp_schedule_event( |
| 191 |
apply_filters( 'propertyhive_auto_email_match_cron_timestamp', $timestamp ), |
| 192 |
$recurrence, |
| 193 |
'propertyhive_auto_email_match' |
| 194 |
); |
| 195 |
} |
| 196 |
|
| 197 |
// Schedule for 1am as it's likely traffic will be quieter at that time |
| 198 |
// 1am so it doesn't run at exactly the same time as the exchange rate cron |
| 199 |
wp_schedule_event( strtotime( 'tomorrow +1hours' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_check_licenses' ); |
| 200 |
|
| 201 |
wp_schedule_event( strtotime( 'tomorrow +3hours' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_update_address_concatenated' ); |
| 202 |
|
| 203 |
wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'propertyhive_cleanup_search_analytics' ); |
| 204 |
} |
| 205 |
|
| 206 |
public function custom_cron_recurrence( $schedules ) |
| 207 |
{ |
| 208 |
$schedules['every_fifteen_minutes'] = array( |
| 209 |
'interval' => 900, |
| 210 |
'display' => __( 'Every 15 Minutes', 'propertyhive' ) |
| 211 |
); |
| 212 |
|
| 213 |
return $schedules; |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Create pages that the plugin relies on |
| 218 |
* |
| 219 |
* @access public |
| 220 |
* @return void |
| 221 |
*/ |
| 222 |
public function create_pages() { |
| 223 |
|
| 224 |
// Create page object |
| 225 |
$my_post = array( |
| 226 |
'post_title' => __( 'Property Search', 'propertyhive' ), |
| 227 |
'post_content' => '', |
| 228 |
'post_status' => 'publish', |
| 229 |
'post_type' => 'page', |
| 230 |
'comment_status' => 'closed', |
| 231 |
'ping_status' => 'closed', |
| 232 |
); |
| 233 |
|
| 234 |
// Insert the post into the database |
| 235 |
$page_id = wp_insert_post( $my_post, true ); |
| 236 |
|
| 237 |
if ( !is_wp_error($page_id) ) |
| 238 |
{ |
| 239 |
update_option( 'propertyhive_search_results_page_id', $page_id ); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Add the default terms for PH taxonomies - property types, tenures etc. Modify this at your own risk. |
| 245 |
* |
| 246 |
* @access public |
| 247 |
* @return void |
| 248 |
*/ |
| 249 |
private function create_terms() { |
| 250 |
|
| 251 |
$taxonomies = array( |
| 252 |
'availability' => array( |
| 253 |
array( |
| 254 |
'name' => 'For Sale', |
| 255 |
'departments' => array('residential-sales', 'commercial') |
| 256 |
), |
| 257 |
array( |
| 258 |
'name' => 'Under Offer', |
| 259 |
'departments' => array('residential-sales', 'commercial') |
| 260 |
), |
| 261 |
array( |
| 262 |
'name' => 'Sold STC', |
| 263 |
'departments' => array('residential-sales', 'commercial') |
| 264 |
), |
| 265 |
array( |
| 266 |
'name' => 'Sold', |
| 267 |
'departments' => array('residential-sales', 'commercial') |
| 268 |
), |
| 269 |
array( |
| 270 |
'name' => 'To Let', |
| 271 |
'departments' => array('residential-lettings', 'commercial') |
| 272 |
), |
| 273 |
array( |
| 274 |
'name' => 'Let Agreed', |
| 275 |
'departments' => array('residential-lettings', 'commercial') |
| 276 |
), |
| 277 |
array( |
| 278 |
'name' => 'Let', |
| 279 |
'departments' => array('residential-lettings', 'commercial') |
| 280 |
), |
| 281 |
), |
| 282 |
'property_type' => array( |
| 283 |
// HOUSE |
| 284 |
array( |
| 285 |
'name' => 'House' |
| 286 |
), |
| 287 |
array( |
| 288 |
'name' => 'Detached House', |
| 289 |
'child_of_previous' => true |
| 290 |
), |
| 291 |
array( |
| 292 |
'name' => 'Semi-Detached House', |
| 293 |
'child_of_previous' => true |
| 294 |
), |
| 295 |
array( |
| 296 |
'name' => 'Terraced House', |
| 297 |
'child_of_previous' => true |
| 298 |
), |
| 299 |
array( |
| 300 |
'name' => 'End of Terrace House', |
| 301 |
'child_of_previous' => true |
| 302 |
), |
| 303 |
array( |
| 304 |
'name' => 'Mews', |
| 305 |
'child_of_previous' => true |
| 306 |
), |
| 307 |
array( |
| 308 |
'name' => 'Link Detached House', |
| 309 |
'child_of_previous' => true |
| 310 |
), |
| 311 |
array( |
| 312 |
'name' => 'Town House', |
| 313 |
'child_of_previous' => true |
| 314 |
), |
| 315 |
array( |
| 316 |
'name' => 'Cottage', |
| 317 |
'child_of_previous' => true |
| 318 |
), |
| 319 |
// BUNGALOW |
| 320 |
array( |
| 321 |
'name' => 'Bungalow' |
| 322 |
), |
| 323 |
array( |
| 324 |
'name' => 'Detached Bungalow', |
| 325 |
'child_of_previous' => true |
| 326 |
), |
| 327 |
array( |
| 328 |
'name' => 'Semi-Detached Bungalow', |
| 329 |
'child_of_previous' => true |
| 330 |
), |
| 331 |
array( |
| 332 |
'name' => 'Terraced Bungalow', |
| 333 |
'child_of_previous' => true |
| 334 |
), |
| 335 |
array( |
| 336 |
'name' => 'End of Terrace Bungalow', |
| 337 |
'child_of_previous' => true |
| 338 |
), |
| 339 |
// FLATS |
| 340 |
array( |
| 341 |
'name' => 'Flat / Apartment' |
| 342 |
), |
| 343 |
array( |
| 344 |
'name' => 'Flat', |
| 345 |
'child_of_previous' => true |
| 346 |
), |
| 347 |
array( |
| 348 |
'name' => 'Apartment', |
| 349 |
'child_of_previous' => true |
| 350 |
), |
| 351 |
array( |
| 352 |
'name' => 'Maisonette', |
| 353 |
'child_of_previous' => true |
| 354 |
), |
| 355 |
array( |
| 356 |
'name' => 'Studio', |
| 357 |
'child_of_previous' => true |
| 358 |
), |
| 359 |
array( |
| 360 |
'name' => 'Penthouse', |
| 361 |
'child_of_previous' => true |
| 362 |
), |
| 363 |
array( |
| 364 |
'name' => 'Duplex', |
| 365 |
'child_of_previous' => true |
| 366 |
), |
| 367 |
array( |
| 368 |
'name' => 'Triplex', |
| 369 |
'child_of_previous' => true |
| 370 |
), |
| 371 |
// OTHER |
| 372 |
array( |
| 373 |
'name' => 'Other' |
| 374 |
), |
| 375 |
array( |
| 376 |
'name' => 'Commercial', |
| 377 |
'child_of_previous' => true |
| 378 |
), |
| 379 |
array( |
| 380 |
'name' => 'Land', |
| 381 |
'child_of_previous' => true |
| 382 |
), |
| 383 |
array( |
| 384 |
'name' => 'Garage', |
| 385 |
'child_of_previous' => true |
| 386 |
), |
| 387 |
), |
| 388 |
'commercial_property_type' => array( |
| 389 |
array( |
| 390 |
'name' => 'Office' |
| 391 |
), |
| 392 |
array( |
| 393 |
'name' => 'Industrial' |
| 394 |
), |
| 395 |
array( |
| 396 |
'name' => 'Retail' |
| 397 |
), |
| 398 |
array( |
| 399 |
'name' => 'Land' |
| 400 |
), |
| 401 |
array( |
| 402 |
'name' => 'Health' |
| 403 |
), |
| 404 |
array( |
| 405 |
'name' => 'Motoring' |
| 406 |
), |
| 407 |
array( |
| 408 |
'name' => 'Leisure' |
| 409 |
), |
| 410 |
array( |
| 411 |
'name' => 'Investment' |
| 412 |
), |
| 413 |
), |
| 414 |
'outside_space' => array( |
| 415 |
array( |
| 416 |
'name' => 'Balcony' |
| 417 |
), |
| 418 |
array( |
| 419 |
'name' => 'South Facing Garden' |
| 420 |
), |
| 421 |
), |
| 422 |
'parking' => array( |
| 423 |
array( |
| 424 |
'name' => 'On Road Parking' |
| 425 |
), |
| 426 |
array( |
| 427 |
'name' => 'Off Road Parking' |
| 428 |
), |
| 429 |
array( |
| 430 |
'name' => 'Driveway' |
| 431 |
), |
| 432 |
array( |
| 433 |
'name' => 'Single Garage' |
| 434 |
), |
| 435 |
array( |
| 436 |
'name' => 'Double Garage' |
| 437 |
), |
| 438 |
array( |
| 439 |
'name' => 'Triple Garage' |
| 440 |
), |
| 441 |
array( |
| 442 |
'name' => 'Carport' |
| 443 |
), |
| 444 |
), |
| 445 |
'price_qualifier' => array( |
| 446 |
array( |
| 447 |
'name' => 'Guide Price' |
| 448 |
), |
| 449 |
array( |
| 450 |
'name' => 'Fixed Price' |
| 451 |
), |
| 452 |
array( |
| 453 |
'name' => 'Offers Over' |
| 454 |
), |
| 455 |
array( |
| 456 |
'name' => 'OIRO' |
| 457 |
) |
| 458 |
), |
| 459 |
'sale_by' => array( |
| 460 |
array( |
| 461 |
'name' => 'Tender' |
| 462 |
), |
| 463 |
array( |
| 464 |
'name' => 'Private Treaty' |
| 465 |
), |
| 466 |
array( |
| 467 |
'name' => 'Auction' |
| 468 |
), |
| 469 |
), |
| 470 |
'tenure' => array( |
| 471 |
array( |
| 472 |
'name' => 'Freehold' |
| 473 |
), |
| 474 |
array( |
| 475 |
'name' => 'Leasehold' |
| 476 |
), |
| 477 |
array( |
| 478 |
'name' => 'Share of Freehold' |
| 479 |
), |
| 480 |
array( |
| 481 |
'name' => 'Commonhold' |
| 482 |
) |
| 483 |
), |
| 484 |
'commercial_tenure' => array( |
| 485 |
array( |
| 486 |
'name' => 'Freehold' |
| 487 |
), |
| 488 |
array( |
| 489 |
'name' => 'Leasehold' |
| 490 |
), |
| 491 |
array( |
| 492 |
'name' => 'Share of Freehold' |
| 493 |
), |
| 494 |
array( |
| 495 |
'name' => 'Commonhold' |
| 496 |
) |
| 497 |
), |
| 498 |
'furnished' => array( |
| 499 |
array( |
| 500 |
'name' => 'Furnished' |
| 501 |
), |
| 502 |
array( |
| 503 |
'name' => 'Part Furnished' |
| 504 |
), |
| 505 |
array( |
| 506 |
'name' => 'Unfurnished' |
| 507 |
) |
| 508 |
), |
| 509 |
'marketing_flag' => array( |
| 510 |
array( |
| 511 |
'name' => 'New Instruction' |
| 512 |
), |
| 513 |
array( |
| 514 |
'name' => 'Chain Free' |
| 515 |
) |
| 516 |
), |
| 517 |
'management_key_date_type' => array( |
| 518 |
array( |
| 519 |
'name' => 'Initial Inventory', |
| 520 |
'recurrence_type' => 'tenancy_management', |
| 521 |
'recurrence_rule' => 'FREQ=ONCE', |
| 522 |
), |
| 523 |
array( |
| 524 |
'name' => 'Inspection', |
| 525 |
'recurrence_type' => 'tenancy_management', |
| 526 |
'recurrence_rule' => 'FREQ=MONTHLY;INTERVAL=3', |
| 527 |
), |
| 528 |
array( |
| 529 |
'name' => 'Gas Safety Check', |
| 530 |
'recurrence_type' => 'property_management', |
| 531 |
'recurrence_rule' => 'FREQ=YEARLY;INTERVAL=1', |
| 532 |
), |
| 533 |
), |
| 534 |
); |
| 535 |
|
| 536 |
$availability_departments = get_option( 'propertyhive_availability_departments', array() ); |
| 537 |
if ( !is_array($availability_departments) ) { $availability_departments = array(); } |
| 538 |
|
| 539 |
$previous_term_id = ''; |
| 540 |
foreach ( $taxonomies as $taxonomy => $terms ) |
| 541 |
{ |
| 542 |
// Make sure no terms for this taxonomy exist already |
| 543 |
$existing_terms = get_terms( $taxonomy ); |
| 544 |
if ( is_wp_error( $existing_terms ) || (!is_wp_error( $existing_terms ) && empty( $existing_terms ) ) ) |
| 545 |
{ |
| 546 |
foreach ( $terms as $term ) |
| 547 |
{ |
| 548 |
if ( ! get_term_by( 'slug', sanitize_title( $term['name'] ), $taxonomy ) ) |
| 549 |
{ |
| 550 |
$args = array(); |
| 551 |
if ( isset($term['child_of_previous']) && $term['child_of_previous'] === true ) |
| 552 |
{ |
| 553 |
$args = array('parent' => $previous_term_id); |
| 554 |
} |
| 555 |
$return = wp_insert_term( $term['name'], $taxonomy, $args ); |
| 556 |
if ( !is_wp_error($return) ) |
| 557 |
{ |
| 558 |
if ( !isset($term['child_of_previous']) || (isset($term['child_of_previous']) && !$term['child_of_previous']) ) |
| 559 |
{ |
| 560 |
$previous_term_id = $return['term_id']; |
| 561 |
} |
| 562 |
|
| 563 |
if ( $taxonomy == 'availability' && is_array($term['departments']) && !empty($term['departments']) ) |
| 564 |
{ |
| 565 |
$availability_departments[$return['term_id']] = $term['departments']; |
| 566 |
} |
| 567 |
|
| 568 |
if ( $taxonomy == 'management_key_date_type' && isset($term['recurrence_type']) && isset($term['recurrence_rule']) ) |
| 569 |
{ |
| 570 |
$options = get_option( 'propertyhive_key_date_type', array() ); |
| 571 |
if ( !is_array($options) ) { $options = array(); } |
| 572 |
|
| 573 |
$options[$return['term_id']] = array( |
| 574 |
'recurrence_rule' => $term['recurrence_rule'], |
| 575 |
'recurrence_type' => $term['recurrence_type'], |
| 576 |
); |
| 577 |
|
| 578 |
update_option( 'propertyhive_key_date_type', $options ); |
| 579 |
} |
| 580 |
} |
| 581 |
else |
| 582 |
{ |
| 583 |
// Hmm... an error occurred |
| 584 |
// $error_string = $result->get_error_message(); // do something with this? |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
update_option( 'propertyhive_availability_departments', $availability_departments ); |
| 592 |
} |
| 593 |
|
| 594 |
/** |
| 595 |
* Add the first office so at least one exists |
| 596 |
* |
| 597 |
* @access public |
| 598 |
* @return void |
| 599 |
*/ |
| 600 |
function create_primary_office() { |
| 601 |
|
| 602 |
$args = array( |
| 603 |
'post_type' => 'office' |
| 604 |
); |
| 605 |
$office_query = new WP_Query($args); |
| 606 |
if (!$office_query->have_posts()) |
| 607 |
{ |
| 608 |
// Insert office |
| 609 |
$office_post = array( |
| 610 |
'post_title' => 'My Office', |
| 611 |
'post_content' => '', |
| 612 |
'post_status' => 'publish', |
| 613 |
'post_type' => 'office', |
| 614 |
); |
| 615 |
|
| 616 |
// Insert the post into the database |
| 617 |
$office_post_id = wp_insert_post( $office_post ); |
| 618 |
|
| 619 |
update_post_meta($office_post_id, 'primary', '1'); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
/** |
| 624 |
* Default options |
| 625 |
* |
| 626 |
* Sets up the default options used on the settings page |
| 627 |
* |
| 628 |
* @access public |
| 629 |
*/ |
| 630 |
function create_options() { |
| 631 |
|
| 632 |
add_option( 'propertyhive_active_departments_sales', 'yes', '', 'yes' ); |
| 633 |
add_option( 'propertyhive_active_departments_lettings', 'yes', '', 'yes' ); |
| 634 |
add_option( 'propertyhive_primary_department', 'residential-sales', '', 'yes' ); |
| 635 |
|
| 636 |
add_option( 'propertyhive_maps_provider', 'osm', '', 'no' ); |
| 637 |
add_option( 'propertyhive_geocoding_provider', 'osm', '', 'no' ); |
| 638 |
|
| 639 |
add_option( 'propertyhive_default_country', 'GB', '', 'yes' ); |
| 640 |
add_option( 'propertyhive_countries', array('GB'), '', 'yes' ); |
| 641 |
|
| 642 |
add_option( 'propertyhive_applicant_match_price_range_percentage_lower', 20, '', 'no' ); |
| 643 |
add_option( 'propertyhive_applicant_match_price_range_percentage_higher', 5, '', 'no' ); |
| 644 |
|
| 645 |
add_option( 'propertyhive_license_type', 'pro', '', 'yes' ); |
| 646 |
|
| 647 |
add_option( 'propertyhive_install_timestamp', time(), '', 'no' ); |
| 648 |
add_option( 'propertyhive_review_prompt_due_timestamp', strtotime('+30 days'), '', 'no' ); |
| 649 |
|
| 650 |
add_option( 'propertyhive_enquiry_auto_responder_email_subject', __( 'Thank you for your enquiry', 'propertyhive' ), '', 'no' ); |
| 651 |
add_option( 'propertyhive_enquiry_auto_responder_email_body', sprintf( |
| 652 |
/* translators: %s: blog name shown in the email sign-off */ |
| 653 |
__( "Thank you for your recent property enquiry about [property_address_hyperlinked]. A member of our team will be in touch shortly. |
| 654 |
|
| 655 |
Kind regards, |
| 656 |
|
| 657 |
%s |
| 658 |
|
| 659 |
[similar_properties]", 'propertyhive' ), |
| 660 |
get_bloginfo('name') |
| 661 |
), '', 'no' ); |
| 662 |
|
| 663 |
add_option( 'propertyhive_property_match_default_email_subject', __( 'We found [property_count] that might be of interest to you', 'propertyhive' ), '', 'no' ); |
| 664 |
add_option( 'propertyhive_property_match_default_email_body', __( "Hi [contact_dear], |
| 665 |
|
| 666 |
Based on your requirements, we've found [property_count] below that we believe might be suitable for you: |
| 667 |
|
| 668 |
[properties] |
| 669 |
|
| 670 |
If you have any questions or require more information about any of the properties shown above please let me know. |
| 671 |
|
| 672 |
Kind regards, |
| 673 |
|
| 674 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 675 |
|
| 676 |
// Applicant Viewing Booking Confirmation |
| 677 |
add_option( 'propertyhive_viewing_applicant_booking_confirmation_email_subject', __( 'Your Viewing On [property_address]', 'propertyhive' ), '', 'no' ); |
| 678 |
add_option( 'propertyhive_viewing_applicant_booking_confirmation_email_body', __( "Dear [applicant_dear], |
| 679 |
|
| 680 |
This is confirmation that your viewing on [property_address] has been booked for [viewing_time] on [viewing_date]. |
| 681 |
|
| 682 |
Should you need to cancel or amend your booking please do not hesitate to contact us. |
| 683 |
|
| 684 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 685 |
|
| 686 |
// Applicant Viewing Cancellation Notification |
| 687 |
add_option( 'propertyhive_viewing_applicant_cancellation_notification_email_subject', __( 'Your Viewing On [property_address] Has Been Cancelled', 'propertyhive' ), '', 'no' ); |
| 688 |
add_option( 'propertyhive_viewing_applicant_cancellation_notification_email_body', __( "Dear [applicant_dear], |
| 689 |
|
| 690 |
This is confirmation that a viewing on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason] |
| 691 |
|
| 692 |
Should you have any questions please do not hesitate to contact us. |
| 693 |
|
| 694 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 695 |
|
| 696 |
// Owner/Landlord Viewing Booking Confirmation |
| 697 |
add_option( 'propertyhive_viewing_owner_booking_confirmation_email_subject', __( 'Viewing Booked On [property_address]', 'propertyhive' ), '', 'no' ); |
| 698 |
add_option( 'propertyhive_viewing_owner_booking_confirmation_email_body', __( "Dear [owner_dear], |
| 699 |
|
| 700 |
This is confirmation that a viewing has been booked at your property, [property_address], for [viewing_time] on [viewing_date]. |
| 701 |
|
| 702 |
Should you need to cancel or amend this viewing please do not hesitate to contact us. |
| 703 |
|
| 704 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 705 |
|
| 706 |
// Owner/Landlord Viewing Cancellation Notification |
| 707 |
add_option( 'propertyhive_viewing_owner_cancellation_notification_email_subject', __( 'Viewing Cancelled On [property_address]', 'propertyhive' ), '', 'no' ); |
| 708 |
add_option( 'propertyhive_viewing_owner_cancellation_notification_email_body', __( "Dear [owner_dear], |
| 709 |
|
| 710 |
This is confirmation that a viewing on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason] |
| 711 |
|
| 712 |
Should you have any questions please do not hesitate to contact us. |
| 713 |
|
| 714 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 715 |
|
| 716 |
// Attending Negotiator Viewing Booking Confirmation |
| 717 |
add_option( 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_subject', __( 'Viewing Booked On [property_address]', 'propertyhive' ), '', 'no' ); |
| 718 |
add_option( 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_body', __( "This is confirmation you've been assigned to attend a viewing at property, [property_address], for [viewing_time] on [viewing_date]. |
| 719 |
|
| 720 |
Applicant Details: |
| 721 |
[applicant_details] |
| 722 |
|
| 723 |
Owner Details: |
| 724 |
[owner_details] |
| 725 |
|
| 726 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 727 |
|
| 728 |
// Attending Negotiator Viewing Cancellation Notification |
| 729 |
add_option( 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_subject', __( 'Viewing Cancelled On [property_address]', 'propertyhive' ), '', 'no' ); |
| 730 |
add_option( 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_body', __( "This is confirmation that a viewing you were assigned to carry out on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason] |
| 731 |
|
| 732 |
Applicant Details: |
| 733 |
[applicant_details] |
| 734 |
|
| 735 |
Owner Details: |
| 736 |
[owner_details] |
| 737 |
|
| 738 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 739 |
|
| 740 |
// Owner/Landlord Appraisal Booking Confirmation |
| 741 |
add_option( 'propertyhive_appraisal_owner_booking_confirmation_email_subject', __( 'Appraisal Booked On [property_address]', 'propertyhive' ), '', 'no' ); |
| 742 |
add_option( 'propertyhive_appraisal_owner_booking_confirmation_email_body', __( "Dear [owner_dear], |
| 743 |
|
| 744 |
This is confirmation that an appraisal has been booked for your property, [property_address], for [appraisal_time] on [appraisal_date]. |
| 745 |
|
| 746 |
Should you need to cancel or amend this appraisal, please do not hesitate to contact us. |
| 747 |
|
| 748 |
", 'propertyhive' ) . get_bloginfo('name'), '', 'no' ); |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
/** |
| 753 |
* Set up the database tables which the plugin needs to function. |
| 754 |
* |
| 755 |
* Tables: |
| 756 |
* ph_email_log - Queueing table for emails |
| 757 |
* |
| 758 |
* @access public |
| 759 |
* @return void |
| 760 |
*/ |
| 761 |
private function create_tables() { |
| 762 |
global $wpdb, $propertyhive; |
| 763 |
|
| 764 |
$wpdb->hide_errors(); |
| 765 |
|
| 766 |
$collate = ''; |
| 767 |
|
| 768 |
if ( $wpdb->has_cap( 'collation' ) ) { |
| 769 |
$collate = $wpdb->get_charset_collate(); |
| 770 |
} |
| 771 |
|
| 772 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 773 |
|
| 774 |
$tables = " |
| 775 |
CREATE TABLE {$wpdb->prefix}ph_email_log ( |
| 776 |
email_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 777 |
contact_id bigint(20) unsigned NOT NULL, |
| 778 |
property_ids text NOT NULL, |
| 779 |
applicant_profile_id tinyint(3) unsigned NOT NULL, |
| 780 |
to_email_address varchar(255) NOT NULL, |
| 781 |
cc_email_address varchar(255) NOT NULL, |
| 782 |
bcc_email_address varchar(255) NOT NULL, |
| 783 |
from_name varchar(255) NOT NULL, |
| 784 |
from_email_address varchar(255) NOT NULL, |
| 785 |
subject varchar(255) NOT NULL, |
| 786 |
body blob NOT NULL, |
| 787 |
lock_id varchar(23) NOT NULL, |
| 788 |
locked_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 789 |
status varchar(5) NOT NULL, |
| 790 |
send_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 791 |
sent_by bigint(20) unsigned NOT NULL, |
| 792 |
PRIMARY KEY (email_id) |
| 793 |
) $collate;"; |
| 794 |
|
| 795 |
$tables .= " |
| 796 |
CREATE TABLE {$wpdb->prefix}ph_address_keyword_polygon ( |
| 797 |
address_keyword varchar(255) NOT NULL, |
| 798 |
polygon_coordinates longtext NOT NULL |
| 799 |
) $collate;"; |
| 800 |
|
| 801 |
$tables .= " |
| 802 |
CREATE TABLE {$wpdb->prefix}ph_search_log ( |
| 803 |
id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 804 |
searched_at datetime NOT NULL, |
| 805 |
PRIMARY KEY (id), |
| 806 |
KEY searched_at (searched_at) |
| 807 |
) $collate;"; |
| 808 |
|
| 809 |
dbDelta( $tables ); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* Create roles and capabilities |
| 814 |
*/ |
| 815 |
public function create_roles() { |
| 816 |
global $wp_roles; |
| 817 |
|
| 818 |
if ( ! class_exists( 'WP_Roles' ) ) { |
| 819 |
return; |
| 820 |
} |
| 821 |
|
| 822 |
if ( ! isset( $wp_roles ) ) { |
| 823 |
$wp_roles = new WP_Roles(); |
| 824 |
} |
| 825 |
|
| 826 |
// Property Hive Contact role |
| 827 |
add_role( 'property_hive_contact', __( 'Property Hive Contact', 'propertyhive' ), array( |
| 828 |
'read' => true, |
| 829 |
) ); |
| 830 |
|
| 831 |
if ( is_object( $wp_roles ) ) { |
| 832 |
|
| 833 |
$capabilities = $this->get_core_capabilities(); |
| 834 |
|
| 835 |
foreach ( $capabilities as $cap_group ) { |
| 836 |
foreach ( $cap_group as $cap ) { |
| 837 |
$wp_roles->add_cap( 'administrator', $cap ); |
| 838 |
$wp_roles->add_cap( 'editor', $cap ); |
| 839 |
} |
| 840 |
} |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
/** |
| 845 |
* Get capabilities for PropertyHive - these are assigned to admin/shop manager during installation or reset |
| 846 |
* |
| 847 |
* @access public |
| 848 |
* @return array |
| 849 |
*/ |
| 850 |
public function get_core_capabilities() { |
| 851 |
$capabilities = array(); |
| 852 |
|
| 853 |
$capabilities['core'] = array( |
| 854 |
'manage_propertyhive'/*, |
| 855 |
'view_propertyhive_reports'*/ |
| 856 |
); |
| 857 |
|
| 858 |
return $capabilities; |
| 859 |
} |
| 860 |
|
| 861 |
/** |
| 862 |
* propertyhive_remove_roles function. |
| 863 |
* |
| 864 |
* @access public |
| 865 |
* @return void |
| 866 |
*/ |
| 867 |
public function remove_roles() { |
| 868 |
/*global $wp_roles; |
| 869 |
|
| 870 |
if ( class_exists( 'WP_Roles' ) ) { |
| 871 |
if ( ! isset( $wp_roles ) ) { |
| 872 |
$wp_roles = new WP_Roles(); |
| 873 |
} |
| 874 |
}*/ |
| 875 |
} |
| 876 |
|
| 877 |
/** |
| 878 |
* Create files/directories |
| 879 |
*/ |
| 880 |
private function create_files() { |
| 881 |
// Install files and folders for uploading files and prevent hotlinking |
| 882 |
$upload_dir = wp_upload_dir(); |
| 883 |
|
| 884 |
/*$files = array( |
| 885 |
array( |
| 886 |
'base' => $upload_dir['basedir'] . '/propertyhive_uploads', |
| 887 |
'file' => '.htaccess', |
| 888 |
'content' => 'deny from all' |
| 889 |
), |
| 890 |
array( |
| 891 |
'base' => $upload_dir['basedir'] . '/propertyhive_uploads', |
| 892 |
'file' => 'index.html', |
| 893 |
'content' => '' |
| 894 |
), |
| 895 |
array( |
| 896 |
'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs', |
| 897 |
'file' => '.htaccess', |
| 898 |
'content' => 'deny from all' |
| 899 |
), |
| 900 |
array( |
| 901 |
'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs', |
| 902 |
'file' => 'index.html', |
| 903 |
'content' => '' |
| 904 |
) |
| 905 |
); |
| 906 |
|
| 907 |
foreach ( $files as $file ) { |
| 908 |
if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { |
| 909 |
if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) { |
| 910 |
fwrite( $file_handle, $file['content'] ); |
| 911 |
fclose( $file_handle ); |
| 912 |
} |
| 913 |
} |
| 914 |
}*/ |
| 915 |
} |
| 916 |
|
| 917 |
/** |
| 918 |
* Active plugins pre update option filter |
| 919 |
* |
| 920 |
* @param string $new_value |
| 921 |
* @return string |
| 922 |
*/ |
| 923 |
function pre_update_option_active_plugins( $new_value ) { |
| 924 |
/*$old_value = (array) get_option( 'active_plugins' ); |
| 925 |
|
| 926 |
if ( $new_value !== $old_value && in_array( W3TC_FILE, (array) $new_value ) && in_array( W3TC_FILE, (array) $old_value ) ) { |
| 927 |
$this->_config->set( 'notes.plugins_updated', true ); |
| 928 |
try { |
| 929 |
$this->_config->save(); |
| 930 |
} catch( Exception $ex ) {} |
| 931 |
} |
| 932 |
|
| 933 |
return $new_value;*/ |
| 934 |
} |
| 935 |
|
| 936 |
/** |
| 937 |
* Show plugin changes. Code adapted from W3 Total Cache. |
| 938 |
* |
| 939 |
* @return void |
| 940 |
*/ |
| 941 |
function in_plugin_update_message( $args ) { |
| 942 |
/*$transient_name = 'ph_upgrade_notice_' . $args['Version']; |
| 943 |
|
| 944 |
if ( false === ( $upgrade_notice = get_transient( $transient_name ) ) ) { |
| 945 |
|
| 946 |
$response = wp_remote_get( 'https://plugins.svn.wordpress.org/propertyhive/trunk/readme.txt' ); |
| 947 |
|
| 948 |
if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) { |
| 949 |
|
| 950 |
// Output Upgrade Notice |
| 951 |
$matches = null; |
| 952 |
$regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( PH_VERSION ) . '\s*=|$)~Uis'; |
| 953 |
$upgrade_notice = ''; |
| 954 |
|
| 955 |
if ( preg_match( $regexp, $response['body'], $matches ) ) { |
| 956 |
$version = trim( $matches[1] ); |
| 957 |
$notices = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) ); |
| 958 |
|
| 959 |
if ( version_compare( PH_VERSION, $version, '<' ) ) { |
| 960 |
|
| 961 |
$upgrade_notice .= '<div class="ph_plugin_upgrade_notice">'; |
| 962 |
|
| 963 |
foreach ( $notices as $index => $line ) { |
| 964 |
$upgrade_notice .= wp_kses_post( preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $line ) ); |
| 965 |
} |
| 966 |
|
| 967 |
$upgrade_notice .= '</div> '; |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS ); |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
echo wp_kses_post( $upgrade_notice );*/ |
| 976 |
} |
| 977 |
} |
| 978 |
|
| 979 |
endif; |
| 980 |
|
| 981 |
return new PH_Install(); |
| 982 |
|