Identifying needed membership levels

I'm looking for a way to display a blog page with some content protected. What I'd like to do is feature an icon next to the protected content that may need a higher level of access than what the current user has. This could also involve guest users that may need to log in to view the content. So picture a standard blog archive page with a list of posts and some posts have an icon indicating it is a "silver" level article. I've been looking through the documentation and have made some progress but only for logged in users.

If you could point me in the right direction in the documentation or provide a function that will get me moving in the right direction that would be great.

  • Rupok
    • Support Ninja

    Hi TLDCO,

    Thanks for asking. As you said " I've been looking through the documentation and have made some progress but only for logged in users", can you please provide us the code with which you are showing icons for different levels for logged in users?

    WordPress has a native function "is_user_logged_in()". This function checks if the current visitor is a logged in user. You can use this function as a condition for doing stuff for non-logged in users. You will get details about this function here: https://developer.wordpress.org/reference/functions/is_user_logged_in/

    However, I could tell you better about this if you told us what progress you have made for logged in users and how you are doing this. Please send us all these details. I'm looking forward to hearing from you and resolving this issue as soon as possible.

    Have a nice day. Cheers!
    Rupok

  • TLDCO
    • Site Builder, Child of Zeus

    I've tried different variations of the function below. The first if statement catches if I'm logged in as a admin or an existing member. Not for guests though. What I really need is a way of identifying the level of membership required for the resource. That could even just be saying Post 1 has access level of silver member ID. Sorry for the messy code, the code snippet doesn't seem to be working.

    if ( class_exists('MS_Model_Member') ) {
    if ( MS_Model_Member::is_admin_user() ) {
    _e( 'You are an admin user and have access to all memberships', MS_TEXT_DOMAIN );
    }else{
    $userId = get_current_user_id(); // Set the User ID here
    $subscriptions = MS_Model_Relationship::get_subscriptions( array( 'user_id' => $userId ));
    foreach ( $subscriptions as $subscription ) {
    $membership = $subscription->get_membership();
    echo $membership->name;
    }
    }
    }

  • TLDCO
    • Site Builder, Child of Zeus

    Well, I think I identified the problem. There are two methods of protecting posts. The first method involves marking it as a particular level i.e. silver, gold, platinum. If you do it that way then nothing about that post will show up because its protected from users that don't have the appropriate level including guest users. While this way does give me the membership level, it doesn't work because I can't even display a title to associate that level with.

    The 2nd method is to use the shortcodes in the content. This doesn't work because I now no longer have a way of marking the post as silver, gold, platinum and retrieving that programmatically.

    So what I'm left with is to use method two and add a custom field that allows the creator of the post to specify the membership level. I can then use that to output my icon. This makes it much more time consuming to administrate and also more prone to errors. Consider an approach where these membership levels are tiers. So I have to make sure my shortcode includes all the appropriate levels otherwise a silver member going to gold may no longer be able to see their previous silver content.

    I think this is a great piece of software but having the ability to merge methods one and two would make it the best. Right now I have to manufacture my own solution which won't make it as easy on the admin.

  • Rupok
    • Support Ninja

    Hi TLDCO,

    I think this is a great piece of software but having the ability to merge methods one and two would make it the best. Right now I have to manufacture my own solution which won't make it as easy on the admin.

    Wow! You did a great research there. Please share the workaround when you are done coding this custom thing. I believe, this will help other users having same requirement in the future.

    And thanks for your suggestion. I'm moving your thread to our Features and Feedback section. More people liking this idea, more chances our developers will work on this and will include this feature in our future releases.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.