How to protect sidebar data and widgets via membership site options

Some asked an excellent and reasonable question:

How to protect sidebar data for the membership site?

The problem is that premium content markers { +++ } does not work within sidebar content. But the task can easily be solved with the help of free, simple and powerful Widget Logic plugin.

The sequence of steps to create a premium-only sidebar widget would be like this:

  1. Install and activate Widget Logic plugin
  2. Go to Appearance->Widgets
  3. for the sake of this example let work with Text widget – drag and drop “Text” widget to the sidebar of choice.
  4. Title it “Premium sutff” of whatever you want.
  5. Inside of it put text: “This is my premium and very valuable text”
  6. Note “widget logic” field available at the end of this widget dialog. (It will be available for every widget as Widget Logic plugin is installed).
  7. Paste in this field the following code snippet:
    return (current_user_can ('edit_users') || current_user_can ('read_platinum'));

    Above snippet will show this widget only to administrators and “Platinum” premium members.
    Cool? Yes!

  8. Press button [Save] and link “Close”.
  9. Now reload your blog – and you’ll see your premium widget – because you’re admin. Logoff and create some “Platinum Member” user (that is if you’re using MemberWing). Then login as new platinum member – and you’ll see your widget. Logoff and login as gold member – and you’ll not see it.
  10. Here are variations of the code to paste into “widget logic” field to make the widget premium and be shown only to certain levels:
  • Bronze level: Visible to Bronze, Silver, Gold, Platinum  members only:
    return (current_user_can ('edit_users') || current_user_can ('read_bronze') || current_user_can ('read_silver') || current_user_can ('read_gold') || current_user_can ('read_platinum'));
  • Silver level: Visible to Silver, Gold, Platinum  members only:
    return (current_user_can ('edit_users') || current_user_can ('read_silver') || current_user_can ('read_gold') || current_user_can ('read_platinum')); 
  • Gold level: Visible to Gold, Platinum  members only:
    return (current_user_can ('edit_users') || current_user_can ('read_gold') || current_user_can ('read_platinum'));
  • Platinum level: Visible to Platinum  members only:
    return (current_user_can ('edit_users') || current_user_can ('read_platinum'));

You may also add another pieces of logic into the snippet, such as is_page() to show the widget only to premium users that are viewing pages, but not posts. Sky is the limit!

One thought on “How to protect sidebar data and widgets via membership site options

Leave a Reply

Your email address will not be published. Required fields are marked *


eight − 5 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>