0 ) { // Trust the attachment id over client-saved values. $resolvedUrl = wp_get_attachment_url( $fileId ); if ( is_string( $resolvedUrl ) && '' !== $resolvedUrl ) { $fileUrl = esc_url_raw( $resolvedUrl ); } $resolvedMime = get_post_mime_type( $fileId ); if ( is_string( $resolvedMime ) && '' !== $resolvedMime ) { $fileMime = $resolvedMime; } if ( '' === trim( $fileName ) ) { $attTitle = get_the_title( $fileId ); if ( is_string( $attTitle ) && '' !== $attTitle ) { $fileName = $attTitle; } } // Resolve a real, human-readable size from the file on disk. $attPath = get_attached_file( $fileId ); if ( is_string( $attPath ) && '' !== $attPath && file_exists( $attPath ) ) { $bytes = filesize( $attPath ); if ( false !== $bytes && $bytes > 0 ) { $fileSize = size_format( $bytes, 1 ); } } } // Nothing usable to download — render nothing. if ( '' === $fileUrl ) { return; } // Merge the resolved file fields back into the attributes handed to React. $attributes['file'] = array_merge( $file, [ 'url' => $fileUrl, 'name' => $fileName, 'type' => $fileMime, 'size' => $fileSize, ] ); ?>