How to hide ‘Download’ button based on current users abililty to view post
-
Which PHP Conditional Tag should I use in the ‘Display Widget logic’ field, to conditionally display a Button widget that links to an ACF field that holds an attachment URL from the Media Library?
This ‘Download’ button should only be displayed if the role of the user equals the role that is needed to view the current post. This may sound superfluous, but the trouble with attachment URLs of Media Library items (which link directly to a media file), is that they can not be fully ‘blocked’ by means of a role.
Even if a user has insufficient rights, one can still open the file if one has the direct link. Besides, with Role managers like Ultimate Member it is possible to limit access to the body text of the post that contains the download button, but UM does not hide other content, like buttons.
I tried to hide the button from within Elementor with the PHP code snippet ‘current_user_can(‘read_post’) in the ‘Display Widget logic’ field, but that does not do anything. Unfortunately, I do not know my way around with PHP, so I would really appreciate your help ??
The page I need help with: [log in to see the link]
- The topic ‘How to hide ‘Download’ button based on current users abililty to view post’ is closed to new replies.