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™

Displaying User Role on the Site

s2Member Plugin. A Membership plugin for WordPress®.

Displaying User Role on the Site

Postby peeld » December 11th, 2011, 4:40 pm

Hi there. I have the following code as a plugin on my site:

Code: Select all
function pc_get_userrole ($user_id) {
   $user = new WP_User($user_id);
   $userclean = $user->roles[0];
   return $userclean;
}


Then, where I want the user's role to display, I put this:

Code: Select all
echo pc_get_userrole(bp_current_user_id());


Works like a charm - on the site, the user's role gets displayed like this:
Code: Select all
s2member_level1


I know nothing about code; is there a way I can make it so that when the value returned is s2member_level1, as above, the text returned is something like "Auditing Student", and if the value returned is s2member_level1 the text is "Working Student"?

Where to put these statements?
This I know is a pretty simple/dumb question, but I'm a PHP dum dum...

thanks,
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Eduan » December 11th, 2011, 5:24 pm

You can use this shortcode:
[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]

Or you can use this PHP:
Code: Select all
<?php echo S2MEMBER_CURRENT_USER_ACCESS_LABEL; ?>

Hope this helps. :)
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 5:48 pm

i want to know how to get user roles displayed on comment section for viewers/visitors to see regardless if they were logged in or logged out.

For example:
COMMENT 1:
username: Mike
member status: Premium Member (s2member level 2 <<-- example)

COMMENT 2:
username: John
member status: Standard Member (s2member level 1 <<-- example)

Which "Premium" and "Standard" status are seen on comments. Even if the viewer/visitor is logged in or logged out.

is this possible? if so, how? I tried the code

<?php echo get_user_field('s2member_access_label', $user_id); ?>

But it shows current logged in member's level status. And it shows on all comments. I want it like, the comment author's member level status to be seen.
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby Eduan » December 11th, 2011, 5:52 pm

I believe I answered that question in my post above, so you might wanna take a look at it.
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 6:01 pm

Actually, s2pidkaspr's questions is more what I meant to ask - implementation of that short code is ALMOST what I want - but it displays MY user status, not the user status of the member I'm looking at.

This is the closest I've gotten, your post sure has me excited!!! :)
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 6:04 pm

I actually tried that code you posted above. But it seems not working just the way I wanted it to be. So do you have any alternatives? Do you have Skype? please let's chat about it, i really need help on it. Thanks
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 6:09 pm

I've been digging in the buddypress site for ages trying to find a solution to this, at least I'm getting closer!
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Eduan » December 11th, 2011, 6:12 pm

@s2pidkaspr
Could you post a screenshot of how you want it? So I can have a clear idea of how you want it.

Thanks.
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 6:21 pm

@Eduan
I have PM'd you the screenshot. Please check it and tell me if you know how to do this.
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 6:37 pm

Image

Here you go.

Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 7:00 pm

@Eduan
you still there? have you seen my private message?
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby Eduan » December 11th, 2011, 7:03 pm

Thanks for the photos guys.
You might need to implement some PHP with HTML manually or hire someone to do it for you at: viewforum.php?f=37

@s2pidkaspr
Maybe something like:
Code: Select all
<font style="float: right;">[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]</font> 


@peeld
You could try something like:
Code: Select all
<font style="float: left;">[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]</font> 


@Both
Now I'm not sure this will accomplish what you want, but I think it's a start. Mainly what I did is make it so that it aligns to the side you want. I tried using the PHP in a test post and it didn't work for me, so I gave you the code with the shortcode.

Hope this helps. :)
Last edited by Eduan on December 11th, 2011, 9:13 pm, edited 1 time in total.
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 7:16 pm

can i try that code using php? what is it?

well, all i wanted to do is display the comment authors their member status, so that visitors can see what are their status are.
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 7:28 pm

You can put that into a post or page to view it.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 7:35 pm

That code just displays YOUR user label, not the label of the user you're viewing. :(

I'm too nervous to post for a job for hire :) Don't know who to trust :)
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 7:37 pm

One sec, I'll find the function to pass the ID into.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 7:48 pm

Super, and if it's kosher PM me your Paypal email for a donation :)
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 8:15 pm

You can put this into your s2hacks.php file (If you don't have it create it in wp-content/mu-plugins/s2hacks.php)

Code: Select all

<?php
function custom_get_user_role($id 1)
{
$user_role get_user_meta($id'wp_capabilities');
//You should customize the array values below to what you would like to show for each.
foreach ($user_role[0] as $key=>$value){
    if(
$value == 1){
        echo 
str_replace(array('access_s2member_','ccap_','level0''level1','basic','administrator'),array('','','Free Subscriber''Paid User','Basic User''Administrator'),$key);}
    }}
?>


Now, you can do this in a post with Exec-PHP installed.

Code: Select all
//This gives you the user role for the user with an ID of 110
<?php echo custom_get_user_role(110); ?>
Last edited by Bruce C on December 11th, 2011, 8:47 pm, edited 3 times in total.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby s2pidkaspr » December 11th, 2011, 8:21 pm

@Bruce C
where can i find mu-plugins?

is it possible for me to use this too?
User avatar
s2pidkaspr
Registered User
Registered User
 
Posts: 48
Joined: August 6, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 8:27 pm

You need to create the file/directory if you haven't already.

Yes, it's possible. BUT, you're going to need to make some custom code to get it to work correctly with your setup, unless you're already passing the user id into your system, in which case you can just pass that into the function. The function merely takes the ID and gets the role for the user.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 8:29 pm

@peeld

Are you running on BuddyPress? Because I believe there is a function to get the ID of the user that page belongs to.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 8:38 pm

Yes, I'm running buddypress. I was wondering where the ID was going to come from... :) I really know NOTHING about PHP, so if you know the code that would be helpful :) I know just enough to get in trouble :)

Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 8:41 pm

I would need to take a look at your setup, I only know what I can from reading the source code, my local server crashes every time I try to install BuddyPress.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Displaying User Role on the Site

Postby peeld » December 11th, 2011, 8:44 pm

Well, gettin' closer. The code you provided breaks the backend of the site when it's put in my s2hacks file.

Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Displaying User Role on the Site

Postby Bruce C » December 11th, 2011, 8:47 pm

Missing bracket. Sorry, it didn't show up in the post I had it in.

Try the edited code
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Next

Return to s2Member Plugin

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron