open( $tmp_file, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) { wp_die( esc_html__( 'Could not open temporary engine file matrix layer safely.', 'af-translate' ) ); } // Add primary .po file $zip->addFile( $po_target, basename( $po_target ) ); // Add compiled binary .mo machine code pair if ( file_exists( $mo_target ) ) { $is_mo_safe = class_exists( 'AF_Translate_Path_Validator' ) ? AF_Translate_Path_Validator::validate_containment( $mo_target, false ) : true; if ( $is_mo_safe ) { $zip->addFile( $mo_target, basename( $mo_target ) ); } } // Add WP 6.5+ .l10n.php performance binary file if ( file_exists( $l10n_target ) ) { $is_l10n_safe = class_exists( 'AF_Translate_Path_Validator' ) ? AF_Translate_Path_Validator::validate_containment( $l10n_target, false ) : true; if ( $is_l10n_safe ) { $zip->addFile( $l10n_target, basename( $l10n_target ) ); } } // Add all matching Gutenberg/wp.i18n script translation .json files foreach ( $json_targets as $json_file ) { if ( file_exists( $json_file ) ) { $is_json_safe = class_exists( 'AF_Translate_Path_Validator' ) ? AF_Translate_Path_Validator::validate_containment( $json_file, false ) : true; if ( $is_json_safe ) { $zip->addFile( $json_file, basename( $json_file ) ); } } } $zip->close(); // 4. CRITICAL: Purge Active Output Buffer Layers to Secure ZIP Integrity while ( ob_get_level() ) { ob_end_clean(); } // 5. Emit Stream Transmission Payload Control Headers header( 'Content-Type: application/zip' ); header( 'Content-Disposition: attachment; filename="' . basename( $zip_name ) . '"' ); header( 'Authorization-Response: True' ); header( 'Content-Length: ' . filesize( $tmp_file ) ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Direct file stream passthru required for memory-efficient browser download proxying. readfile( $tmp_file ); wp_delete_file( $tmp_file ); exit; } }