62 lines
1.2 KiB
PHP
62 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Maple Icons Uninstall
|
|
*
|
|
* Runs when the plugin is uninstalled (deleted).
|
|
* Cleans up all plugin data including downloaded icons and settings.
|
|
*
|
|
* @package MapleIcons
|
|
*/
|
|
|
|
// Exit if not called by WordPress.
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Remove plugin options.
|
|
*/
|
|
delete_option( 'maple_icons_settings' );
|
|
|
|
/**
|
|
* Remove transients.
|
|
*/
|
|
global $wpdb;
|
|
$wpdb->query(
|
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_mi_%' OR option_name LIKE '_transient_timeout_mi_%'"
|
|
);
|
|
|
|
/**
|
|
* Remove downloaded icons directory.
|
|
*/
|
|
$icons_dir = WP_CONTENT_DIR . '/maple-icons/';
|
|
|
|
if ( is_dir( $icons_dir ) ) {
|
|
/**
|
|
* Recursively delete a directory and its contents.
|
|
*
|
|
* @param string $dir Directory path.
|
|
* @return bool True on success, false on failure.
|
|
*/
|
|
function mi_delete_directory( $dir ) {
|
|
if ( ! is_dir( $dir ) ) {
|
|
return false;
|
|
}
|
|
|
|
$files = array_diff( scandir( $dir ), array( '.', '..' ) );
|
|
|
|
foreach ( $files as $file ) {
|
|
$path = $dir . '/' . $file;
|
|
|
|
if ( is_dir( $path ) ) {
|
|
mi_delete_directory( $path );
|
|
} else {
|
|
unlink( $path );
|
|
}
|
|
}
|
|
|
|
return rmdir( $dir );
|
|
}
|
|
|
|
mi_delete_directory( $icons_dir );
|
|
}
|