PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 1.4.62 All 260 releases
propertyhive / includes / class-ph-install.php

class-ph-install.php in Property Hive 2.3.0, at includes/class-ph-install.php

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