Page 1 of 1

Style comments depending on the s2member custom role

PostPosted: June 4th, 2011, 3:42 am
by carblanco
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?

Re: Style comments depending on the s2member custom role

PostPosted: June 4th, 2011, 9:51 am
by Cristián Lávaque
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. :)

Re: Style comments depending on the s2member custom role

PostPosted: June 6th, 2011, 4:00 am
by carblanco
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?

Re: Style comments depending on the s2member custom role

PostPosted: June 6th, 2011, 4:55 am
by Cristián Lávaque
I see. Maybe this WordPress function will help http://codex.wordpress.org/Function_Ref ... t_userdata

Re: Style comments depending on the s2member custom role

PostPosted: June 6th, 2011, 5:26 am
by carblanco
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.

Re: Style comments depending on the s2member custom role

PostPosted: June 6th, 2011, 4:05 pm
by Cristián Lávaque
I'm glad you sorted it out. :)

Re: Style comments depending on the s2member custom role

PostPosted: June 7th, 2011, 3:29 pm
by carblanco
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?

Re: Style comments depending on the s2member custom role

PostPosted: June 8th, 2011, 3:25 am
by carblanco
Could I use something like
Code: Select all
<?php } else if ( $user_meta->wp_capabilities == 'a:1:\{s:15:\"s2member_level2\";s:1:\"1\";\}' ){ ?>
?

Re: Style comments depending on the s2member custom role

PostPosted: June 14th, 2011, 12:25 am
by Jason Caldwell
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

Re: Style comments depending on the s2member custom role

PostPosted: June 14th, 2011, 5:02 pm
by carblanco
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.