Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Check for attachments presence
Stayen
New
Vanilla 2.2.1
Task: detect whether a discussion has attachments (Advanced Editor enabled) and prevent saving/editing discussion if no attachment(s) found.
Could you please direct me to how does one check programmatically the presence of attachments?
Thanks.
Tagged:
0
Comments
Your task can be interpreted in multiple ways.
I'll assume it is purely created with the advanced editor and no other plugin.
I'll assume prevent saving/ editing if no attachment found in the specific post.
I'll assume you mean creating new discussions require attachments, and any discussions created with attachments cannot be saved if you edit them and try to remove an attachment.
I'll assume that if you edit a discussion or comment that previously did not have an attachment then you don't have the restriction to require an attachment until you add an attachment (since this would require more work).
The simplest way that I found is checking form values.
use this event in a plugin for the initial Discussion post
use this event in a plugin if you want to do the same for comments.
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
@River, thanks for the detailed response with code samples, that's exactly what I was looking for, to start with.