Display content for specific user

Hi there,
I’m using the free version of S2 member, I have one issu so far :

  • I would like to be able to display specific content for specific user based on their ID.
    I’ve tried a few shortcodes [s2 If] and php queries ; but I had no luck so far…

Does anyone know if it’s possible ( maybe only in the pro version?) and if possible, would have the proper shortcode or php query to share with me ?

Best regards;

Sure, it’s possible, but you’d need to write some custom code, because this really has nothing to do with s2Member’s functionality.

I suggest you Google for some suggestions.

thanks Tim,
Maybe I can achieve that by setting up a unique custom capability to each user, what do you think ?

Yes, that would work.

Are you looking for a full client portal or just providing a few unique pages?

It’s a client portal, not very complex but some content must be accessible to only specific user. I’ve been reading the doc and found this :


Simple Conditionals (via WordPress Shortcodes)

In an effort to give you even more control over access restrictions, s2Member makes Simple Conditionals available to you from within WordPress, using Shortcodes that are fully compatible with both the Visual Editor, and also the HTML Tab in WordPress. In this section, we’ll demonstrate several functions that are possible using Shortcodes:

is_user_logged_in(), is_user_not_logged_in(), user_is(user_id, role), user_is_not(user_id, role), user_can(user_id, capability), user_cannot(user_id, capability), current_user_is(role), current_user_is_not(role), current_user_can(capability), current_user_cannot(capability), current_user_is_for_blog(blog_id,role), current_user_is_not_for_blog(blog_id,role), current_user_can_for_blog(blog_id,capability), current_user_cannot_for_blog(blog_id,capability). To make use of these functions, please follow our code samples below. Using Shortcodes, it’s easy to build Simple Conditionals within your content; based on a Member’s Level, or even based on Custom Capabilities. s2Member’s Shortcodes can be used inside a Post/Page, and also inside Text Widgets.

There are two different Shortcodes being demonstrated here:

  1. s2If (for testing simple conditional expressions).
  2. s2Get (to get an API Constant value, a Custom Field, or meta key)

But I did try to use this : [s2If user_is(5, member)]My content for user number 5 [/s2If]
but this functions does not work. Maybe I’m missing something or misunderstanding ?

If it’s a portal, I wouldn’t do it with shortcodes at all. It will get very messy and be difficult to maintain. I would do it programmatically with PHP (and I’d probably use custom post types too).

I appreciate the advice,
it’s just a simple restricted access for suppliers, where they can access some generic document and download few personnal ones… I think a restriction using shortcode would work just fine, I just don’t understand why it does not work one a user id base.

I suspect you need to change “member” to the actual s2Member role, e.g. s2member_level1

Yes I tried, actually the “member” was just an example I wrote on the fly…

I have just checked the WP Codex, and I can’t find user_is, so that might be the problem. You need to use user_can, current_user_is, or current_user_can.

Thanks a lot ; the documentation was misleading… I’ll try the other options !

I found a solution. I installed the “Custom Content Shortcode” plugin. It gives me the option to configure the content in this way:

[is user = john] You are John. [/ is]
[is user = marie] You are Marie. [/ is]

Worked perfectly. Good luck.

Google actually brought me here.

I’m trying to protect a section of an article, based on membership level.

Is this possible?

Hi,
Yes it’s possible and it’s easy to do this, you just must use shortcode or PHP conditionals as describe in this section: S2Member -> API / Scripting.
Thanks.