Search code examples
phpwordpressuser-roles

Wordpress capability to edit only uploaded files


I need to assign to an user role the capabilities for the user to only edit his own uploaded files (instead of edit all files like happen for the capability upload_files). Considering that there is not a native capability for that, how can I achieve the desired result?


Solution

  • I believe you could:

    1. Define your role and add a custom capability (eg. edit_own_files) via Roles and Capabilities guidelines
    2. Use the user_has_cap filter to modify whether the user has the "upload_files" capability - depending on which file they are trying to edit, and if they are the author.

    That approach depends on the "upload_files" check passing what you need via the "$args" parameter.

    So, you'll have to do some testing - and if it doesn't do what you need, you might need to hunt for a different filter.