post_type || 'publish' !== $post->post_status ) { status_header( 404 ); exit; } // Check if download is allowed. $meta_download = (bool) get_post_meta( $post_id, '_breznflow_show_download', true ); $global_settings = get_option( 'breznflow_settings', array() ); $global_download = ! empty( $global_settings['allow_download'] ); if ( ! $meta_download || ! $global_download ) { status_header( 403 ); exit; } // Read the already-sanitized JSON (NEVER raw). $json = get_post_meta( $post_id, '_breznflow_raw_json', true ); if ( ! $json ) { status_header( 404 ); exit; } $filename = 'workflow-' . $post_id . '.json'; header( 'Content-Type: application/json; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . rawurlencode( $filename ) . '"' ); header( 'X-Content-Type-Options: nosniff' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Content-Length: ' . strlen( $json ) ); echo $json; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON output for download, not HTML exit; } }