This commit is contained in:
Javier Casares 2026-08-10 16:21:45 +00:00
commit cc1bca74fa
29 changed files with 770 additions and 204 deletions

View file

@ -2,7 +2,10 @@
/**
* Uninstall script for iDrivee2 Media Upload.
*
* Runs when the plugin is uninstalled. Cleans up any plugin data if needed.
* Runs when the plugin is uninstalled. By default, all plugin data is
* preserved unless the administrator explicitly opted in to removal via
* the "Delete all plugin data on uninstall" setting (data preservation
* policy per AGENTS-database-roles-performance-i18n.md).
*
* @package iDrivee2Media
* @since 0.3.0
@ -20,41 +23,28 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
/**
* Clean up plugin data.
*
* Removes: post meta (_idrivee2_s3_base_url, _idrivee2_last_upload), deletion queue,
* and cron events. By design, idrivee2_media_settings and idrivee2_s3_operations
* are preserved (user data preservation policy per AGENTS.md).
* By default all plugin data (post meta, options, statistics) is preserved.
* Data is only removed when the administrator has explicitly checked the
* "Delete all plugin data on uninstall" option on the settings page.
*
* WARNING: This action cannot be undone.
* Cron events are always cleared to prevent orphaned scheduled tasks.
*/
global $wpdb;
$idrivee2_settings = get_option( 'idrivee2_media_settings', array() );
$idrivee2_delete_data = is_array( $idrivee2_settings ) && isset( $idrivee2_settings['delete_on_uninstall'] ) && '1' === $idrivee2_settings['delete_on_uninstall'];
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( $idrivee2_delete_data ) {
// Delete all plugin post meta via the WordPress API.
delete_post_meta_by_key( '_idrivee2_last_upload' );
delete_post_meta_by_key( '_idrivee2_s3_base_url' );
// Delete all _idrivee2_last_upload post meta.
$wpdb->query(
"DELETE FROM {$wpdb->postmeta}
WHERE meta_key = '_idrivee2_last_upload'"
);
// Delete all _idrivee2_s3_base_url post meta.
$wpdb->query(
"DELETE FROM {$wpdb->postmeta}
WHERE meta_key = '_idrivee2_s3_base_url'"
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
// Delete the deletion queue option.
delete_option( 'idrivee2_deletion_queue' );
// Unschedule the cleanup cron event.
$idrivee2_next_scheduled = wp_next_scheduled( 'idrivee2_cleanup_local_files' );
if ( $idrivee2_next_scheduled ) {
wp_unschedule_event( $idrivee2_next_scheduled, 'idrivee2_cleanup_local_files' );
// Delete plugin options.
delete_option( 'idrivee2_deletion_queue' );
delete_option( 'idrivee2_media_settings' );
delete_option( 'idrivee2_s3_operations' );
}
// Clear all hooks for this action to prevent any remaining schedules.
// Always clear cron events to prevent orphaned scheduled tasks.
wp_clear_scheduled_hook( 'idrivee2_cleanup_local_files' );
/**