<?php
/**
 * Uninstall for LMN Site Monitor
 *
 * @package LMN_Site_Monitor
 */

if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

// Options used by the plugin.
$lmnsimo_option_keys = array(
    'lmnsimo_sites',
    'lmnsimo_settings',
    'lmnsimo_last_alerts',
);

// Delete options.
foreach ( $lmnsimo_option_keys as $lmnsimo_key ) {
    if ( get_option( $lmnsimo_key, null ) !== null ) {
        delete_option( $lmnsimo_key );
    }
}

// Delete user meta for dashboard widget limit.
delete_metadata( 'user', 0, 'lmnsimo_widget_limit', '', true );

// Clear scheduled hook.
$lmnsimo_hooks = array(
    'lmnsimo_check_sites_cron',
);

foreach ( $lmnsimo_hooks as $lmnsimo_hook ) {
    while ( $lmnsimo_timestamp = wp_next_scheduled( $lmnsimo_hook ) ) {
        wp_unschedule_event( $lmnsimo_timestamp, $lmnsimo_hook );
    }
    wp_clear_scheduled_hook( $lmnsimo_hook );
}
