Code Style: Add braces and tidy whitespace.
Swap function into conditional.

This way, a bad $attachment_id won’t break things.

Fixes #1143