monorepo/native/wordpress/maple-performance-wp/uninstall.php
2026-02-02 12:35:28 -05:00

68 lines
1.9 KiB
PHP

<?php
/**
* Uninstall Maple Performance WP
*
* Removes all plugin data when uninstalled.
*
* @package MaplePerformance
*/
// Exit if not called by WordPress
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Delete options
delete_option( 'maple_performance_settings' );
// Delete cache directory
$cache_dir = WP_CONTENT_DIR . '/cache/maple-performance/';
// Verify path is valid and within wp-content
$real_cache_dir = realpath( $cache_dir );
$real_content_dir = realpath( WP_CONTENT_DIR );
if ( $real_cache_dir && $real_content_dir && strpos( $real_cache_dir, $real_content_dir ) === 0 ) {
if ( is_dir( $cache_dir ) ) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $cache_dir, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ( $files as $file ) {
$file_path = $file->getRealPath();
// Verify each file is within cache directory
if ( strpos( $file_path, $real_cache_dir ) !== 0 ) {
continue;
}
if ( $file->isDir() ) {
@rmdir( $file_path );
} else {
@unlink( $file_path );
}
}
@rmdir( $cache_dir );
}
}
// Clear any transients using proper LIKE escaping
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_maple_perf_' ) . '%'
)
);
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_timeout_maple_perf_' ) . '%'
)
);