Hi @dumagroup,

If you turn ON “Own data only” checkbox for role at “Edit Posts” then user with such role will see just his own media library items only at Media Library and his own posts/pages only at Posts/Pages list too.

So you don’t need to try code recipes from above in order to restrict users to only have access/manage their own media that they have uploaded.