add_filter( 'dlm_file_path', 'dlm_bypass_rocket_local_copy', 10, 3 ); function dlm_bypass_rocket_local_copy( $file_path, $download, $version ) { if ( ! is_object( $download ) || ! is_object( $version ) ) return $file_path; $new_filename = sanitize_title( $download->get_title() ) . '.' . (pathinfo( $file_path, PATHINFO_EXTENSION ) ?: 'pdf'); $temp_dir = wp_upload_dir()['basedir'] . '/dlm_tmp'; if ( ! file_exists( $temp_dir ) ) wp_mkdir_p( $temp_dir ); $local_target = $temp_dir . '/' . $new_filename; if ( ! file_exists( $local_target ) ) { @copy( $file_path, $local_target ); } return file_exists( $local_target ) ? $local_target : $file_path; } // Fail-safe: Force headers over AJAX if local copy fails add_filter( 'dlm_download_headers', 'dlm_force_headers_past_cache', 9999, 4 ); function dlm_force_headers_past_cache( $headers, $file_path, $download, $version ) { if ( is_object( $download ) ) { $clean_title = sanitize_title( $download->get_title() ) . '.' . (pathinfo( $file_path, PATHINFO_EXTENSION ) ?: 'pdf'); $encoded = rawurlencode( $clean_title ); $headers['Content-Disposition'] = "attachment; filename*=UTF-8''{$encoded};"; header("Content-Disposition: attachment; filename=\"{$clean_title}\""); } return $headers; }