• Resolved renevlak

    (@renevlak)


    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 ??

    • This topic was modified 6 years ago by renevlak.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter renevlak

    (@renevlak)

    A moment ago, when I tested on a different computer, the button was no longer showing. Perhaps it was due to caching. The only question that remains is that if a non-authorised user stumbles across a hyperlink that directly links to the attachment URL, the attachment can be opened by that user, even if he/she is not logged in. This is a general problem with WordPress Media Library and has nothing to do with Elementor.

Viewing 1 replies (of 1 total)
  • The topic ‘How to hide ‘Download’ button based on current users abililty to view post’ is closed to new replies.