isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } return true; } /** * Check if URL is mobile. */ function wp_recache_is_mobile() { if (!isset($_SERVER['HTTP_USER_AGENT'])) { return false; } $mobile_agents = [ 'android', 'iphone', 'ipad', 'ipod', 'blackberry', 'opera mini', 'opera mobi', ]; $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); foreach ($mobile_agents as $agent) { if (strpos($user_agent, $agent) !== false) { return true; } } return false; } /** * Get cache file path for URL with mobile detection. * * @param string $url URL to cache. */ function wp_recache_get_cache_path_with_device($url) { $path = wp_recache_get_cache_path($url); if (wp_recache_get_option('separate_mobile_cache', false)) { $device = wp_recache_is_mobile() ? 'mobile' : 'desktop'; $path = str_replace('.html', "-{$device}.html", $path); } return $path; } /** * Enqueue the admin-bar purge script (admin and front-end admin bar). */ function wp_recache_enqueue_admin_bar_script() { if (!is_admin_bar_showing() || !current_user_can('manage_options')) { return; } wp_enqueue_script('wp-recache-admin', WP_RECACHE_URL . 'assets/admin.js', ['jquery'], WP_RECACHE_VERSION, true); wp_localize_script('wp-recache-admin', 'wpRecache', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('wp_recache_nonce'), ]); }