"Sorry, you are not allowed to attach files to this post" when adding media to a post

Created by Phil Kurth, Modified on Tue, 19 Jul 2022 at 03:30 PM by Phil Kurth

When uploading media via a form, you may encounter the following error: 


"Sorry, you are not allowed to attach files to this post"


This error comes up when the user filling in the form doesn't have the right capability to edit the given post type. The error is found in wp-admin/includes/ajax-actions.php



The fix for this is to modify the capabilities of the user role/s allowed to edit the post. You may consider using the User Role Editor plugin or something similar to do so.


The capability you need in this case is either going to be edit_post or a more specific variant of it depending on how the post type is registered. If we take a look at how WordPress handles post type capabilities, we can see that it maps a variation to edit_post:



When registering a custom post type, if the post type has a capability_type of page, the capability to use should be edit_page. The default in WordPress is post so if capability_type hasn't been specified on the post type, edit_post should be sufficient. 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article