[SOLVED] I want to add a shortcode to set visibility depending on user role in WP

AlanVernet

Active member
May 4, 2022
54
103
33
Hi all,


It has been a week of trying to come up with a workaround for this. I have zero knowledge in coding and bootstrapping my own site. Figured I should ask experts around to solve this faster.

  • Title for your fault: I want to add a shortcode for setting visibility of button depending on user role
  • Fault Description: I'm using Vex 1.2.3 theme by Rascals. They have a shortcode for adding a Download button on a track but I want that button to be hidden if user is not logged in. I have no experience in coding whatsoever.
  • What have you done to try to fix the issue: I've tried adding If-So plugin, I've read this article which I think would solve my issue but I don't know where to add it within the php files. I think I found which php file to edit but I'm clueless as to how to implement this.

If it would help, here are a few more details:

1. The section I'm working on is in Beatsunlmtd.com
2. Right side of the track "Work Hard" is a download button
3. The shortcode to make that visible is [player_button title="Download" link="http://link_here" target="_self"]
4. The theme file can be found here: https://babiato.tech/resources/vex-creative-music-wordpress-theme.20324/


Thanks so much! Long live Babiato.


Alan
 

tradesman

Well-known member
Mar 9, 2020
367
225
63
Cold North
Try this CSS. Make sure to clear the website cache after.
CSS:
.audio-player__buttons a {
    display: none!important;
}
.logged-in .audio-player__buttons a {
    display: inline-block!important;
}
Easy fix, but not safe.

Someone could just play around with the .logged-in class and taddaaah!

He/she needs the validation to be done in the code.
 

AlanVernet

Active member
May 4, 2022
54
103
33
Hey there!

This actually worked! You're a life saver. Though @tradesman mentioned that it is unsafe. It'll do for now until I find a more solid solution.

Now that the inspect element part was mentioned, I can see that the link to the S3 bucket where the mp3 files can be downloaded are also exposed.

A bit worried about that but I don't have the bandwidth do deal with that right now.

If you can offer another expert advice on this. I'll take note and execute when I can.

Thanks again!


Try this CSS. Make sure to clear the website cache after.
CSS:
.audio-player__buttons a {
    display: none!important;
}
.logged-in .audio-player__buttons a {
    display: inline-block!important;
}
 
  • Like
Reactions: xsz

AlanVernet

Active member
May 4, 2022
54
103
33
Easy fix, but not safe.

Someone could just play around with the .logged-in class and taddaaah!

He/she needs the validation to be done in the code.

Hey there!

Thanks for your suggestion! It actually made me realize that there's another vulnerability that exposes the S3 bucket that stores the files I'll be sharing only to logged in users.

I went with the quick fix for now until I find a better solution like the validation being done in the code which I don't know how to do. If you can shed some light on how to do this, It'd be very much appreciated!


Thanks again!
 

Latest posts

Forum statistics

Threads
69,228
Messages
908,447
Members
237,063
Latest member
skydev

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu