83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Uninstall script for iDrivee2 Media Upload.
|
|
*
|
|
* 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).
|
|
*
|
|
* On Multisite every site is visited: options, post meta, and cron events
|
|
* are site-scoped, so cleaning only the current site would leave subsite
|
|
* data behind.
|
|
*
|
|
* @package iDrivee2Media
|
|
* @since 0.3.0
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Prevent direct access to this file.
|
|
*/
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
exit;
|
|
}
|
|
|
|
// On Multisite, clean up every site; otherwise just the current one.
|
|
// get_sites() defaults to 100 results, so 'number' => 0 (no limit) is
|
|
// required to reach every site on large networks.
|
|
$idrivee2_site_ids = array( get_current_blog_id() );
|
|
|
|
if ( is_multisite() ) {
|
|
$idrivee2_network_sites = get_sites(
|
|
array(
|
|
'fields' => 'ids',
|
|
'number' => 0,
|
|
)
|
|
);
|
|
|
|
if ( ! empty( $idrivee2_network_sites ) ) {
|
|
$idrivee2_site_ids = array_map( 'intval', $idrivee2_network_sites );
|
|
}
|
|
}
|
|
|
|
// switch_to_blog() only exists on Multisite (ms-blogs.php is not loaded on
|
|
// single-site installs), so switch only when running Multisite.
|
|
$idrivee2_is_multisite = is_multisite();
|
|
|
|
foreach ( $idrivee2_site_ids as $idrivee2_site_id ) {
|
|
if ( $idrivee2_is_multisite ) {
|
|
switch_to_blog( $idrivee2_site_id );
|
|
}
|
|
|
|
$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'];
|
|
|
|
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 plugin options.
|
|
delete_option( 'idrivee2_deletion_queue' );
|
|
delete_option( 'idrivee2_media_settings' );
|
|
delete_option( 'idrivee2_s3_operations' );
|
|
}
|
|
|
|
// Always clear cron events to prevent orphaned scheduled tasks.
|
|
wp_clear_scheduled_hook( 'idrivee2_cleanup_local_files' );
|
|
|
|
if ( $idrivee2_is_multisite ) {
|
|
restore_current_blog();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Note: Files uploaded to S3 are NOT deleted by this uninstall script.
|
|
* If you want to delete files from S3, you must do so manually using
|
|
* your S3 management console or AWS CLI.
|
|
*
|
|
* Local files in wp-content/uploads/ are also NOT deleted, as they are
|
|
* part of WordPress's standard media library structure.
|
|
*/
|