PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Style comments depending on the s2member custom role

s2Member Plugin. A Membership plugin for WordPress®.

Style comments depending on the s2member custom role

Postby carblanco » June 4th, 2011, 3:42 am

Hi all,

Basically I need to put in each comment the role of that user. I mean, if someone comments I'd like to put their custom s2member role (level0, level1) under the name. For commenting the user have to be registered.

And some more sophisticated, style the comment depending on the role.

Can you help me?
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011

Re: Style comments depending on the s2member custom role

Postby Cristián Lávaque » June 4th, 2011, 9:51 am

To require registration for comments change the setting WP Admin -> Settings -> Discussion -> Users must be registered and logged in to comment

For the other things you'd need to edit the comments template to add the role label and conditionals to change the style based on the role (you can add classes to use as selectors from the CSS file).

I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Style comments depending on the s2member custom role

Postby carblanco » June 6th, 2011, 4:00 am

Thanks Cristián.

My question is more like that: viewtopic.php?f=4&t=6692&p=20088#p20088

I'm using something like
Code: Select all
<?php echo S2MEMBER_CURRENT_USER_ACCESS_LABEL; ?>
just to put the role under the comment. But the problem is that with this code I'm showing the author post role instead of the commenter role.

How can I extract the s2member membership level of the commenter?
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011

Re: Style comments depending on the s2member custom role

Postby Cristián Lávaque » June 6th, 2011, 4:55 am

I see. Maybe this WordPress function will help http://codex.wordpress.org/Function_Ref ... t_userdata
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Style comments depending on the s2member custom role

Postby carblanco » June 6th, 2011, 5:26 am

So I can't pass the $comment->user_id to s2member to get the membership level?

Then I must to use something like
Code: Select all
<?php $user_meta get_userdata$comment->user_id ); ?>
                <?php if ( $user_meta->wp_user_level == 10 ){ ?>
                Level4
                <?php } else if ( $user_meta->wp_user_level == ){ ?>
                Level3
                <?php } else if ( $user_meta->wp_user_level == ){ ?>
                Level2
                <?php } else if ( $user_meta->wp_user_level == ){ ?>
                Level1
                <?php } else if ( $user_meta->wp_user_level == ){ ?>
                Level0
                <?php ?>

Which is actually working ;-)

Thanks again.
Last edited by Cristián Lávaque on June 6th, 2011, 5:35 am, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011

Re: Style comments depending on the s2member custom role

Postby Cristián Lávaque » June 6th, 2011, 4:05 pm

I'm glad you sorted it out. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Style comments depending on the s2member custom role

Postby carblanco » June 7th, 2011, 3:29 pm

Unfortunately since yesterday update it doesn't work anymore, all $user_meta->wp_user_level have been reseted to "0", no more level 9, 8, 7.

Before I had:
wp_capabilities->a:1:{s:15:"s2member_level3";s:1:"1";} and then wp_user_level->9
wp_capabilities->a:1:{s:15:"s2member_level2";s:1:"1";} and then wp_user_level->8
...
And instead of having "s2member_level3" I had the custom label "Enterprise". It seems like all the labels have been gone.

Why?
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011

Re: Style comments depending on the s2member custom role

Postby carblanco » June 8th, 2011, 3:25 am

Could I use something like
Code: Select all
<?php } else if ( $user_meta->wp_capabilities == 'a:1:\{s:15:\"s2member_level2\";s:1:\"1\";\}' ){ ?>
?
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011

Re: Style comments depending on the s2member custom role

Postby Jason Caldwell » June 14th, 2011, 12:25 am

Thanks for the excellent question.

You can use this API Constant to get the current User's Membership Level Label.
This code snippet can go into a Post/Page editor for WordPress.
Code: Select all
[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]

Also see this documentation:
viewtopic.php?f=40&t=9011&src_doc_v=110605#src_doc_S2MEMBER_CURRENT_USER_ACCESS_LABEL


Or use this API Constant to get the current User's Level #.
This code snippet can go into a Post/Page editor for WordPress.
Code: Select all
[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LEVEL" /]

Also see this documentation:
viewtopic.php?f=40&t=9011&src_doc_v=110605#src_doc_S2MEMBER_CURRENT_USER_ACCESS_LEVEL


Another VERY useful API function is: get_user_field()
viewtopic.php?f=40&t=9015&src_doc_v=110605#src_doc_get_user_field%28%29


Or, if you just need to map a specific User ID to a specific Membership Level #, you can do this.
Code: Select all
<?php
$user_id 
= 123;
$user = new WP_User($user_id);
echo c_ws_plugin__s2member_user_access::user_access_level($user);
?>
For further details, please take a look at the User Access Package:
viewtopic.php?f=40&t=9477&src_doc_v=110605
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Style comments depending on the s2member custom role

Postby carblanco » June 14th, 2011, 5:02 pm

WOW, it works. For example, to show the commenter access label:
Code: Select all
<?php echo(get_user_field ("s2member_access_label", $comment->user_id));?>

So now I can style comments depending on the role.
Thanks.
User avatar
carblanco
Registered User
Registered User
 
Posts: 39
Joined: May 4, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron