Page 1 of 1

How to show Level membership to all members

PostPosted: November 2nd, 2010, 9:01 am
by pericard
Hi,
I'm using s2member pro version with buddypress. I'd like to be able to show to all members what level membership has each member. Using that :
Code: Select all
<?php echo S2MEMBER_CURRENT_USER_ACCESS_LABEL; ?>
it will show the membership level only to the current user logged, but i want to find a code which show the membership level to all the members. It's important for my project to make a difference between members who paid and those who didn't pay.
Thanks in advance for your help and sorry for my approximative english.

Cedric

Re: How to show Level membership to all members

PostPosted: November 3rd, 2010, 7:54 am
by akingston
I need to do something very similar. I'm also using s2Member with buddypress and I want to be able to check each member's level and then display some additional information depending on their level.

Can anyone please tell us what we need to use to do this.

Thanks,
Andrew.

Re: How to show Level membership to all members

PostPosted: November 4th, 2010, 10:24 am
by pericard
Hi,I allow myself this small message again because the feature i asked about is very important to me, I would appreciate a lot to be able to implement it on my website.

Thank you in advance for your help please,

Cedric

Re: How to show Level membership to all members

PostPosted: November 4th, 2010, 10:55 am
by KirkWard
I think you can get what you want with the Wordpress built in function "wp_get_current_user"

http://codex.wordpress.org/Function_Ref ... rrent_user

Re: How to show Level membership to all members

PostPosted: November 4th, 2010, 11:29 am
by pericard
Hi KirkWard and thanks for your answer.

What i need is not to load informations about a user currently logged in, but informations (especially the s2member level membership) about all the members in the buddypress members directory. This member si level 0, level 1, level 2... ?

Does the variable $current_user can provide that ? It appears to me that it will show informations only about a user currently logged in. Am i wrong ?

If you could explain a little more, i would be very glad.

Thanks
Cedric

Re: How to show Level membership to all members

PostPosted: November 4th, 2010, 12:53 pm
by pericard
I test thoses variables but in vain : <?php get_userdata(userid); ?> and <?php get_currentuserinfo(); ?>
I'm lost to do what i want.

Any idea or solution ?
Cedric

Re: How to show Level membership to all members

PostPosted: November 5th, 2010, 10:16 pm
by KirkWard
Install exec_php plugin
Open new post or page in HTML tab

Try this

Code: Select all
<?php
    $current_user = wp_get_current_user() ;
    echo 'User level: ' . $current_user->user_level ;
?>


There is another example that will show the level of a user who is not logged in. You will have to search for it in Wordpress or in Google. The current user info is the only one I have used, although I have seen how to get the other, and it is very similar.

Re: How to show Level membership to all members

PostPosted: November 6th, 2010, 11:55 pm
by arwyl
The object $bp->displayed_user contains the data for the user whose profile is being displayed (see http://codex.buddypress.org/developer-docs/the-bp-global/). So if you want to get, say, the user ID, you can use the function bp_displayed_user_id().

Then you could use something like this:

Code: Select all
<?php

$id = bp_displayed_user_id();
$user = new WP_User( $id );

if ( $user->has_cap( 's2member_level4') ) :
    $membership = 'Platinum';
elseif ( $user->has_cap( 's2member_level3') ) :
    $membership = 'Gold';


And so on, until you've listed all your membership levels and their corresponding names. Then you'd round up with something like this:

Code: Select all
else :
    $membership = 'Free Membership';
endif ?>


Then you could add a div to display the info:

Code: Select all
<div class="membership-info">
    Current membership level: <?php echo $membership ?>
</div>


There's probably a better way of doing this, but this works! :mrgreen:

Re: How to show Level membership to all members

PostPosted: November 7th, 2010, 3:52 am
by pericard
Hi,
Thanks all of you for your answer.
Anyway, i can't fix this. I modify the member-loop.php file in buddypress. Any code i try, show information about the current user log in.

See my code
Code: Select all
   <ul id="members-list" class="item-list">
   <?php while ( bp_members() ) : bp_the_member(); ?>

      <li>
         <div class="item-avatar">
            <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
         </div>

         <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink() ?>"><?php bp_member_name() ?></a>

               <?php if ( bp_get_member_latest_update() ) : ?>

                  <span class="update"> - <?php bp_member_latest_update( 'length=10' ) ?></span>

               <?php endif; ?>

            </div>

            <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
            <div class="item-meta">
                <span class="activity">
               
            <?php
               
                $id = bp_displayed_user_id();
                $user = new WP_User( $id );
               
                    if ( $user->has_cap( 's2member_level4') ) :
                    $membership = 'Adh&eacute;rent VIP';
                elseif ( $user->has_cap( 's2member_level3') ) :
                    $membership = 'Adh&eacute;rent';
                elseif ( $user->has_cap( 's2member_level0') ) :
                    $membership = 'Sympathisant';
                endif ?>
               
                    Current membership level: <?php echo $membership ?>
               
   
                </span>
                </div>

            <?php do_action( 'bp_directory_members_item' ) ?>

            <?php
             /***
              * If you want to show specific profile fields here you can,
              * but it'll add an extra query for each member in the loop
              * (only one regardless of the number of fields you show):
              *
              * bp_member_profile_data( 'field=the field name' );
              */
            ?>
         </div>

         <div class="action">

            <?php do_action( 'bp_directory_members_actions' ); ?>

         </div>

         <div class="clear"></div>
      </li>

   <?php endwhile; ?>
   </ul>


Did i mystake somewhere ? Well that's not that easy to fix that...
Thanks again for you help

Cedric

Re: How to show Level membership to all members

PostPosted: November 7th, 2010, 4:11 pm
by ndavidson
I'm still learning the plug-in myself, but I'm thinking you all may be trying to take a more complicated approach then is neccessary.

I would try something like:

Code: Select all
$query = "SELECT DISTINCT(meta_value) FROM wp_usermeta WHERE meta_key='wp_capabilities'";
$resultx = $wpdb->get_col($query);


This is very similar to the concept I am working on for s2Member for custom fields. Getting the information yuo seek from the fields can also be found in the sample code in the s2members forums post located at

http://www.primothemes.com/forums/viewtopic.php?f=4&t=627

Re: How to show Level membership to all members

PostPosted: November 7th, 2010, 5:18 pm
by arwyl
Hi Cedric,

I think all it takes for it to work inside the members loop is a little tweak: try $id = bp_member_user_id() instead of bp_displayed_user_id(). This last function only works on member profile pages, but the first one should get you what you want inside the loop.

So the code would be simply:

Code: Select all
<div class="item-meta">
   <span class="activity">
      <?php
         $id = bp_member_user_id();
         $user = new WP_User( $id );
                     
         if ( $user->has_cap( 's2member_level4') ) :
            $membership = 'Adh&eacute;rent VIP';
         elseif ( $user->has_cap( 's2member_level3') ) :
            $membership = 'Adh&eacute;rent';
         elseif ( $user->has_cap( 's2member_level0') ) :
            $membership = 'Sympathisant';
         endif
      ?>
      Current membership level: <?php echo $membership ?>
   </span>
</div>

Re: How to show Level membership to all members

PostPosted: June 26th, 2011, 12:11 pm
by y2gabs
Has anyone been able to get this code to work inside of the members loop? I've tried in vain using both s2member levels and native wp user roles. I'm trying to filter the list for only those users with s2member_level1.

Please let me know.

<div class="item-meta">
<span class="activity">
<?php
$id = bp_member_user_id();
$user = new WP_User( $id );

if ( $user->has_cap( 's2member_level4') ) :
$membership = 'Adh&eacute;rent VIP';
elseif ( $user->has_cap( 's2member_level3') ) :
$membership = 'Adh&eacute;rent';
elseif ( $user->has_cap( 's2member_level0') ) :
$membership = 'Sympathisant';
endif
?>
Current membership level: <?php echo $membership ?>
</span>
</div>

Re: How to show Level membership to all members

PostPosted: June 26th, 2011, 7:19 pm
by Cristián Lávaque
You can try this:

Code: Select all
<?php echo get_user_field('s2member_access_label'$user_id); ?>

Re: How to show Level membership to all members

PostPosted: June 27th, 2011, 10:15 am
by y2gabs
Unfortunately not because one of my member levels is 'editor' outside of the s2member signup so I need to do if/then for s2member_level0, s2member_level1, and 'editor'. Any thoughts?

Thanks for your reply!

Re: How to show Level membership to all members

PostPosted: June 27th, 2011, 12:11 pm
by Cristián Lávaque
Got it. You could try this then viewtopic.php?f=40&t=9477&src_doc_v=110605#src_doc_user_access_role%28%29

Code: Select all
<?php echo c_ws_plugin__s2member_user_access::user_access_role(new WP_User($user_id)); ?>