Use Membership to control visibility of Events Manager or Calendar Widgets

Is there a way to use the Membership Module to control whether Events Manager or some other calender or events plugs actually displays on the web site?

I only have two membership levels so I could probably get away with hard coding something, but I don't want it to break if I update a plugin.

Even if I can't get the widget to hide from non members, if I could hide the data that would be enough.

I'd like to use the shortcodes from the Membership module or some other obvious mechanism if possible.

thanks,
Battle

  • DavidM
    • DEV MAN’s Mascot

    Hi Battle and first off, welcome to WPMU DEV!

    Yes, there are a few ways I can think to accomplish that, likely the easiest being to use the Widget Logic plugin, which would let you display widgets, depending on conditional functions you specify.

    With that, you could then use any of Membership's conditional functions to display them conditionally:
    https://premium.wpmudev.org/forums/topic/conditionals-for-member-levels

    Besides that, you could use those conditional functions in your theme to display conditional widgets as well.

    Or if you enable the use of shortcodes in text widgets, you could wrap shortcodes from those other plugins (if they use shortcodes), with Membership shortcodes.

    Here's the quick snippet to add shortcode capabilities to widgets:
    add_filter('widget_text', 'do_shortcode');

    There's a number of ways to go about it!

    Hope that helps!

    -David

  • battle
    • WPMU DEV Initiate

    Hi David,
    Just what I was hoping for, an elegant solution. But I can't quite seem to get it to work.
    I already have Membership plugin installed, so I installed Widget Logic and indeed the Widget Logic field is there on the widgets on the Dashboard/Appearance/Widgets page when I try to edit a widget.

    So I pasted the code from the page you referenced and edited it where level1 is the level name used in the Membership Level. So it reads...
    current_user_on_level(level1)

    The only problem is it seems to hide the widget from everyone nonmembers, members at level, and even the admin user.

    So I switched to the code in the field to
    current_user_is_member()
    and it worked for members and hides the widget from nonmembers, but also from the admin user.

    Is there something I'm missing here?

  • Mason
    • DEV MAN’s Sidekick

    Hiya,

    Just checking if it was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

    If so, no need to reply, that's great news.

    If not, could you let us know by re-opening this topic, and we'll get onto it and helping you out asap!
    Otherwise, happy days, glad you got it sorted :slight_smile:

    Thanks!

  • Mason
    • DEV MAN’s Sidekick

    Hiya battle,

    Thanks for letting me know. Feel free to chime in her or open a new thread when you're ready to take another look. We are working on an update to the membership plugin that will make setting it up quite a bit easier.

    Thanks again.

  • DavidM
    • DEV MAN’s Mascot

    Hi @cvma12_1,

    If you're using the Widget Logic plugin I mentioned above, you can use Membership functions such as the following, to display widgets conditionally.

    current_user_is_member()
    current_user_on_level($level_id)
    current_user_on_subscription($sub_id)

    If you're using some other plugin, I'm not sure that would work since you'd need to be able to use conditional code like those mentioned.

    Were you using that plugin or could you provide a link to the plugin you're using?

    Thanks,
    David

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.