<?php

// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	exit;
}

/**
 * Uninstall MDJM Google Calendar Sync.
 *
 * Removes all settings.
 *
 * @package     MDJM Google Calendar Sync
 * @subpackage  Uninstall
 * @copyright   Copyright (c) 2017, Mike Howard
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       2.0
 *
 */

global $wpdb;

// Call the MDJM Google Calendar main class file
require_once 'mdjm-google-calendar-sync.php';

// Delete all meta keys
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '_mdjm_event_google_calendar_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching

// Delete all Plugin Options & transients
$mdjm_gc_all_options = array(
	'google_calendar_auth_code',
    'google_calendar',
    'google_calendar_absence_sync',
    'google_calendar_absence_reminder_type',
    'google_calendar_absence_reminder_when',
    'google_calendar_absence_title',
    'google_calendar_absence_body',
	'google_calendar_full_sync',
	'google_calendar_reminder_type',
	'google_calendar_reminder_when',
	'google_calendar_event_status',
	'google_calendar_entry_title',
	'google_calendar_entry_venue',
	'google_calendar_entry_body',
	'mdjm_gcal_oauth_access_token',
	'mdjm_gcal_oauth_refresh_token',
	'mdjm_gcal_token_time_created'
);

foreach ( $mdjm_gc_all_options as $mdjm_gc_all_option ) {
	mdjm_delete_option( $mdjm_gc_all_option );
}

delete_transient( 'mdjm_google_calendar_token' );
delete_option( 'mdjm_google_calendar_version' );
