latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

display/output current user's level in a page

Home Forums Community Forum display/output current user's level in a page

This topic contains 5 replies, has 2 voices. Last updated by  Cristián Lávaque 4 years, 8 months ago.

Topic Author Topic
Posted: Friday Apr 27th, 2012 at 3:13 am #12018
Joseph K
Username: taekcool

Hi, I just bought s2members pro and so far it’s been okay.

Just like my titles says, how do I display/output the level of the logged-in user, membership time left, etc?

I am really interesting in outputting user’s information in a page like in “my account” type of thing.

Thanks,
Joseph

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Friday Apr 27th, 2012 at 4:30 am #12025

Joseph, you can use the S2MEMBER_CURRENT_USER_ACCESS_LEVEL constant. [hilite path]Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants[/hilite] :)

Posted: Friday Apr 27th, 2012 at 8:40 pm #12106
Joseph K
Username: taekcool

Thanks! It works great. I have a follow up question.

When I put the following php code instead of the WP shortcode into a page (in html mode), it doesn’t seem to be working. It outputs everything (please see below). Is there something In need to do? I sort of newbie into web-coding.. I might be doing something wrong.

<?php if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 4){ ?>
    A Member has an Access Level of 4.
<?php } else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 3){ ?>
    A Member has an Access Level of 3.
<?php } else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 2){ ?>
    A Member has an Access Level of 2.
<?php } else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 1){ ?>
    A Member has an Access Level of 1.
<?php } else if(S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
    A User is logged in as a Free Subscriber.
<?php } else if(S2MEMBER_CURRENT_USER_ACCESS_LEVEL === -1){ ?>
    A User is not logged in at all.
<?php } ?>

It outputs everything… :

A Member has an Access Level of 4.

A Member has an Access Level of 3.

A Member has an Access Level of 2.

A Member has an Access Level of 1.

A User is logged in as a Free Subscriber.

A User is not logged in at all.

Posted: Friday Apr 27th, 2012 at 11:12 pm #12112

I see. I’m not sure why that’s happening.

Are you logged in when you try it? Do you have a PHP execution plugin installed?

Posted: Sunday May 6th, 2012 at 11:18 pm #12785
Joseph K
Username: taekcool

I didn’t know we needed an execution plugin separately. Thanks for the information.
I have one more question on the same topic. How can we output the logged-in-user’s membership expiration date (i.e EOT)?
I couldn’t find it in Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants.. I am pretty sure it’s somewhere I just can’t find it..

Posted: Monday May 7th, 2012 at 3:47 pm #12821

There isn’t a constant for that one, or a shortcode, this is the PHP you need:
[hilite pre_code]
// Auto EOT-Time for the current User (when applicable).
$s2member_auto_eot_time = get_user_option ("s2member_auto_eot_time");
[/hilite]

Notice that not all users have an EOT time set, so your code will have to account for that too.

I hope that helps. :)

Viewing 5 replies - 1 through 5 (of 5 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.