I added the below to Snippets plug-in to disable comments for all media attachments on my site.
Without it, I would be required to go to each media item at Discussion > Allow comments and uncheck the checkbox.
But it isn’t working.
The PHP snippet you added doesn’t alter the checkbox’s attributes, and I can’t see a filter to control this.
However, more importantly, the PHP you added effectively overrides the checkbox ‘Allow comments’. This means that checked or unchecked, because of the php snippet you added, the comments for attachment will be closed.
Hope this clarifies your inquiry! Feel free to reach out anytime if any further assistance is needed. 🙂