delete( $wpdb->postmeta, array( 'meta_key' => $mk ) ); } } // Clear QW-owned scheduled events so uninstall leaves no background jobs behind. foreach ( array( 'qwsc_refresh_dynamic_lists', 'qwsc_cache_stale_cleanup', 'qwsc_preload_batch', 'qwsc_mirror_ga_script', 'qwsc_mirror_gtm_script', 'qwsc_scheduled_db_cleanup', 'qwsc_uptime_ping', 'qwsc_missed_schedule_sweep', 'qwsc_unpublish_post', 'qwsc_weekly_digest', 'qwsc_daily_vitals_check', 'qwsc_broken_images_batch', 'qwsc_vuln_check', 'qwsc_il_scan_batch', 'qwsc_broken_scan_queue', ) as $hook ) { wp_clear_scheduled_hook( $hook ); } // Transients with qwsc_ prefix (best-effort). if ( isset( $wpdb ) && is_object( $wpdb ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_qwsc_%' OR option_name LIKE '_transient_timeout_qwsc_%'" ); } // Page cache directory. $cache_dir = ( defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : '' ) . '/cache/qw-speed-cache'; if ( $cache_dir && is_dir( $cache_dir ) ) { $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $cache_dir, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $it as $file ) { if ( $file->isDir() ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- Removing QW Optimize-owned empty cache directory after deleting files. @rmdir( $file->getPathname() ); } else { wp_delete_file( $file->getPathname() ); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- Removing QW Optimize-owned empty cache directory after deleting files. @rmdir( $cache_dir ); } // Drop-ins we own. $advanced = ( defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : '' ) . '/advanced-cache.php'; if ( file_exists( $advanced ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents,WordPress.PHP.NoSilencedErrors.Discouraged -- Bounded read of local drop-in header for ownership before uninstall cleanup. $head = (string) @file_get_contents( $advanced, false, null, 0, 120 ); if ( false !== strpos( $head, 'QW Optimize' ) ) { wp_delete_file( $advanced ); } } $object = ( defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : '' ) . '/object-cache.php'; if ( file_exists( $object ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents,WordPress.PHP.NoSilencedErrors.Discouraged -- Bounded read of local object-cache drop-in header for ownership. $head = (string) @file_get_contents( $object, false, null, 0, 200 ); if ( false !== strpos( $head, 'QW Optimize Object Cache' ) ) { wp_delete_file( $object ); } } // Remove only QW Optimize-owned .htaccess marker rules. if ( defined( 'ABSPATH' ) ) { if ( ! function_exists( 'insert_with_markers' ) && file_exists( ABSPATH . 'wp-admin/includes/misc.php' ) ) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } if ( ! function_exists( 'get_home_path' ) && file_exists( ABSPATH . 'wp-admin/includes/file.php' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $home_path = function_exists( 'get_home_path' ) ? get_home_path() : ''; $htaccess = is_string( $home_path ) && '' !== $home_path ? trailingslashit( $home_path ) . '.htaccess' : ''; if ( function_exists( 'insert_with_markers' ) && '' !== $htaccess && file_exists( $htaccess ) ) { insert_with_markers( $htaccess, 'QW Optimize', array() ); } }