| 1 |
<?php |
| 2 |
/** |
| 3 |
* Hotelier Uninstall |
| 4 |
* |
| 5 |
* Uninstalling Hotelier deletes user roles, pages, tables, and options. |
| 6 |
* |
| 7 |
* @author Benito Lopez <hello@lopezb.com> |
| 8 |
* @category Core |
| 9 |
* @package HTL/Uninstaller |
| 10 |
* @version 2.6.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
$hotelier_options = get_option( 'hotelier_settings' ); |
| 18 |
|
| 19 |
if ( ! empty( $hotelier_options[ 'remove_data_uninstall' ] ) ) { |
| 20 |
|
| 21 |
// Roles + caps |
| 22 |
include_once( 'includes/class-htl-roles.php' ); |
| 23 |
$roles = new HTL_Roles; |
| 24 |
$roles->remove_roles(); |
| 25 |
|
| 26 |
global $wpdb; |
| 27 |
|
| 28 |
// Pages. |
| 29 |
wp_trash_post( get_option( 'hotelier_booking_page_id' ) ); |
| 30 |
wp_trash_post( get_option( 'hotelier_listing_page_id' ) ); |
| 31 |
|
| 32 |
// Tables. |
| 33 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_bookings" ); |
| 34 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_reservation_itemmeta" ); |
| 35 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_reservation_items" ); |
| 36 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_rooms_bookings" ); |
| 37 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_sessions" ); |
| 38 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_bookings" ); |
| 39 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hotelier_bookings" ); |
| 40 |
|
| 41 |
// Delete options |
| 42 |
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'hotelier\_%';"); |
| 43 |
|
| 44 |
// Delete posts + meta. |
| 45 |
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'room', 'room_reservation', 'coupon', 'extra' );" ); |
| 46 |
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |
| 47 |
|
| 48 |
// Delete cron jobs when uninstalling |
| 49 |
wp_clear_scheduled_hook( 'hotelier_cancel_pending_reservations' ); |
| 50 |
wp_clear_scheduled_hook( 'hotelier_process_completed_reservations' ); |
| 51 |
wp_clear_scheduled_hook( 'hotelier_cleanup_sessions' ); |
| 52 |
wp_clear_scheduled_hook( 'hotelier_check_license_cron' ); |
| 53 |
} |
| 54 |
|