157 lines
3.1 KiB
PHP
157 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* Uninstall Script for Instagram Gallery Sync Pro
|
|
*
|
|
* This file runs when the plugin is deleted from WordPress.
|
|
* It removes all plugin data including:
|
|
* - Custom database tables
|
|
* - Plugin options
|
|
* - Uploaded images
|
|
* - Transients
|
|
*
|
|
* @package Instagram_Gallery_Sync_Pro
|
|
*/
|
|
|
|
// Exit if not called by WordPress
|
|
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
|
exit;
|
|
}
|
|
|
|
// Require WordPress database class
|
|
global $wpdb;
|
|
|
|
/**
|
|
* Remove all plugin options
|
|
*/
|
|
$options_to_delete = array(
|
|
// Instagram settings
|
|
'igsp_username',
|
|
'igsp_max_images',
|
|
'igsp_save_locally',
|
|
'igsp_image_quality',
|
|
'igsp_sync_interval',
|
|
'igsp_last_sync',
|
|
|
|
// Layout settings
|
|
'igsp_layout_type',
|
|
'igsp_columns_desktop',
|
|
'igsp_columns_tablet',
|
|
'igsp_columns_mobile',
|
|
'igsp_spacing',
|
|
'igsp_padding',
|
|
'igsp_aspect_ratio',
|
|
'igsp_object_fit',
|
|
'igsp_border_radius',
|
|
'igsp_hover_effect',
|
|
|
|
// Display settings
|
|
'igsp_display_limit',
|
|
'igsp_order',
|
|
'igsp_show_caption',
|
|
'igsp_caption_position',
|
|
'igsp_show_instagram_btn',
|
|
'igsp_link_behavior',
|
|
'igsp_lightbox',
|
|
'igsp_lazy_loading',
|
|
'igsp_loader_type',
|
|
|
|
// Styling
|
|
'igsp_primary_color',
|
|
'igsp_hover_color',
|
|
'igsp_text_color',
|
|
'igsp_caption_font_size',
|
|
'igsp_custom_css',
|
|
'igsp_css_prefix',
|
|
|
|
// Advanced
|
|
'igsp_debug_mode',
|
|
'igsp_cache_duration',
|
|
'igsp_request_timeout',
|
|
'igsp_user_agent',
|
|
'igsp_proxy_host',
|
|
'igsp_proxy_port',
|
|
'igsp_auto_delete_days',
|
|
|
|
// Database version
|
|
'igsp_db_version',
|
|
);
|
|
|
|
foreach ($options_to_delete as $option) {
|
|
delete_option($option);
|
|
}
|
|
|
|
/**
|
|
* Drop custom database tables
|
|
*/
|
|
$tables = array(
|
|
$wpdb->prefix . 'instagram_gallery_posts',
|
|
$wpdb->prefix . 'instagram_gallery_log',
|
|
);
|
|
|
|
foreach ($tables as $table) {
|
|
$wpdb->query("DROP TABLE IF EXISTS {$table}");
|
|
}
|
|
|
|
/**
|
|
* Delete all transients
|
|
*/
|
|
$wpdb->query(
|
|
"DELETE FROM {$wpdb->options}
|
|
WHERE option_name LIKE '_transient_igsp_%'
|
|
OR option_name LIKE '_transient_timeout_igsp_%'"
|
|
);
|
|
|
|
/**
|
|
* Remove uploaded images directory
|
|
*/
|
|
$upload_dir = wp_upload_dir();
|
|
$instagram_dir = $upload_dir['basedir'] . '/instagram-gallery';
|
|
|
|
if (is_dir($instagram_dir)) {
|
|
igsp_recursive_delete($instagram_dir);
|
|
}
|
|
|
|
/**
|
|
* Recursively delete a directory and its contents
|
|
*
|
|
* @param string $dir Directory path
|
|
* @return bool
|
|
*/
|
|
function igsp_recursive_delete($dir)
|
|
{
|
|
if (!is_dir($dir)) {
|
|
return false;
|
|
}
|
|
|
|
$files = array_diff(scandir($dir), array('.', '..'));
|
|
|
|
foreach ($files as $file) {
|
|
$path = $dir . '/' . $file;
|
|
|
|
if (is_dir($path)) {
|
|
igsp_recursive_delete($path);
|
|
} else {
|
|
unlink($path);
|
|
}
|
|
}
|
|
|
|
return rmdir($dir);
|
|
}
|
|
|
|
/**
|
|
* Clear scheduled cron events
|
|
*/
|
|
$timestamp = wp_next_scheduled('igsp_sync_instagram');
|
|
if ($timestamp) {
|
|
wp_unschedule_event($timestamp, 'igsp_sync_instagram');
|
|
}
|
|
|
|
// Clear any remaining cron events
|
|
wp_clear_scheduled_hook('igsp_sync_instagram');
|
|
wp_clear_scheduled_hook('igsp_cleanup_logs');
|
|
|
|
/**
|
|
* Flush rewrite rules
|
|
*/
|
|
flush_rewrite_rules();
|