Community Support Forums — WordPress® ( Users Helping Users ) — 2010-07-22T23:44:03-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=288 2010-07-22T23:44:03-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1759#p1759 <![CDATA[Re: Question about current_user_can]]> Statistics: Posted by Jason Caldwell — July 22nd, 2010, 11:44 pm


]]>
2010-06-26T07:36:42-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1244#p1244 <![CDATA[Re: Question about current_user_can]]>
I figured I'd post this as sample code to play with for other noobs who want to customize the info displayed on their membership options page according to s2member levels+ccap.

Strange, but "else if" spat out parse errors. So, slight modifications to the code as below and it works like a charm. I tested by assigning various roles and custom capabilities to a test user account (through WPMU dashboard), and the correct upgrade info is displayed on the membership page for each level and ccap bundle.

The first part is the default page display seen by site visitors or not-logged-in members (shows options for all membership levels including free and paid). The 2nd part identifies users who are free members (no ccap access) and displays only options to upgrade to a paid subscription. The 3rd part identifies users who have access to only 1 ccap (Level 1 subscribers) and displays only options to add a 2nd ccap to their subscription (upgrade to Level 2). The 4th part identifies Level 2 subscribers and displays info to add which of the 3 available ccap they don't have access to (upgrade to Level 3). The 5th part identifies members who have subscribed to all 3 ccap options (Level 3) and offers an upgrade to Level 4 Lifetime membership. (This one's gonna be a bit tricky, 'cuz I'll need to figure out a way to get around PayPal's nasty 20% subscription modification limit. But that's a challenge for another day.) The last part simply identifies Level 4 subscribers and gives them a high-5 :)

Thanks again for a fantastic plugin! (Donation on it's way... :D )

Code:
<?php if (!S2MEMBER_CURRENT_USER_IS_LOGGED_IN){ ?>
Show all membership packages and options (free and paid)
<?php } ?>

<?php if (is_user_logged_in() && !current_user_can("access_s2member_level1")){ ?>
This is a free member, so display ALL paid subscription options
<?php } ?>

<?php if (is_user_logged_in() && !current_user_can("access_s2member_level2")){ ?>
    <?php if (current_user_can("access_s2member_ccap_blogs")){ ?>
Subscription modification buttons (Add Media to your Blogs package) OR (Add Groups to your Blogs package)
    <? } ?>
    <?php if (current_user_can("access_s2member_ccap_media")){ ?>
Subscription modification buttons (Add Blogs to your Media package) OR (Add Groups to your Media package)
    <? } ?>
    <?php if (current_user_can("access_s2member_ccap_groups")){ ?>
Subscription modification buttons (Add Blogs to your Groups package) OR (Add Media to your Groups package)
    <?php } ?>
<?php } ?>

<?php if (is_user_logged_in() && current_user_can("access_s2member_level2")){ ?>
    <?php if (!current_user_can("access_s2member_ccap_blogs")){ ?>
Subscription modification button (Add Blogs to your Media+Groups package)
    <? } ?>
    <?php if (!current_user_can("access_s2member_ccap_media")){ ?>
Subscription modification buttons (Add Media to your Blogs+Groups package)
    <? } ?>
    <?php if (!current_user_can("access_s2member_ccap_groups")){ ?>
Subscription modification buttons (Add Groups to your Blogs+Media package)
    <?php } ?>
<?php } ?>

<?php if (is_user_logged_in() && current_user_can("access_s2member_level3") && !current_user_can("access_s2member_level4")){ ?>
ALL options already included in subscription, so offer upgrade to Lev4 Lifetime membership
<?php } ?>

<?php if (is_user_logged_in() && current_user_can("access_s2member_level4")){ ?>
You are already a Lifetime member. Awesome, dude!
<?php } ?>


EDIT: Doh! Reading through the API constants, I just discovered: S2MEMBER_CURRENT_USER_ACCESS_LEVEL.
Could simplify things... :mrgreen:

Statistics: Posted by pcwriter — June 26th, 2010, 7:36 am


]]>
2010-06-26T05:08:27-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1241#p1241 <![CDATA[Re: Question about current_user_can]]>
I forgot about "else if". Makes the code a lot neater ;)

BTW, that second suggestion is a bit over my head as I'm still a novice at php... but I'm really good at copy/paste :D

Statistics: Posted by pcwriter — June 26th, 2010, 5:08 am


]]>
2010-06-26T01:19:43-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1226#p1226 <![CDATA[Re: Question about current_user_can]]> Using this method, you could pull information about someone that is not currently logged into your site. For instance, if you were writing some sort of CRON job, integrating s2Member into a theme, or writing another plugin perhaps.

Code:
<?php
        $user = new WP_User("johndoe22");

        if(!$user->has_cap("access_s2member_ccap_blogs"))
            echo 'They do NOT have the Blogs capability.';

        else if(!$user->has_cap("access_s2member_ccap_media"))
            echo 'They do NOT have the Media capability.';

        else if(!$user->has_cap("access_s2member_ccap_groups"))
            echo 'They do NOT have the Groups capability.';
?>

Note the call to:
Code:
$user = new WP_User("johndoe22");

That could also reference a Member by their WordPress® database ID.
Code:
$user = new WP_User(54);

Statistics: Posted by Jason Caldwell — June 26th, 2010, 1:19 am


]]>
2010-06-26T01:10:40-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1225#p1225 <![CDATA[Re: Question about current_user_can]]>
Here is how I would do that:

Code:
<?php if(is_user_logged_in() && current_user_can("access_s2member_level2")){ ?>

    <?php if(!current_user_can("access_s2member_ccap_blogs")){ ?>

        Upgrade now to Level #3, add the Blogs Capability to your Membership!

    <?php } else if(!current_user_can("access_s2member_ccap_media")){ ?>

        Upgrade now to Level #3, add the Media Capability to your Membership!

    <?php } else if(!current_user_can("access_s2member_ccap_groups")){ ?>

        Upgrade now to Level #3, add the Groups Capability to your Membership!

    <?php } ?>

<?php } ?>

Statistics: Posted by Jason Caldwell — June 26th, 2010, 1:10 am


]]>
2010-06-25T16:24:14-05:00 http://www.primothemes.com/forums/viewtopic.php?t=288&p=1204#p1204 <![CDATA[Question about current_user_can]]>

I've set up a number of subscription packages on my WP/Buddypress install which allow/restrict the type of content members can create/upload using custom capabilities (Blog creation package, Media upload package, Group creation package).

My subscription plan structure looks like this:
Lev 1 plans - Blogs package only, Media package only or Groups package only
Lev 2 plans - Blogs & Media, Blogs & Groups, Media & Groups
Lev 3 plan - Blogs, Media & Groups

For subscription modification/upgrades, I want to code the membership options page so that the current plan to which the member is subscribed is identified according to packages included in the plan, and display only modification buttons for those packages NOT included.

For Level 1 (single) plans, it's pretty straightforward... the code is right there in the documentation:

Code:
<?php if (is_user_logged_in() && current_user_can("access_s2member_level1")){ ?>
    <?php if (current_user_can("access_s2member_ccap_blogs")){ ?>
Show subscription modification buttons to add Media OR Group packages
    <?php } ?>
    <?php if (current_user_can("access_s2member_ccap_media")){ ?>
Show subscription modification buttons to add Blogs OR Group packages
    <?php } ?>
    <?php if (current_user_can("access_s2member_ccap_groups")){ ?>
Show subscription modification buttons to add Blogs OR Media packages
    <?php } ?>
<?php } ?>


For Level 2 (double) plans, I need to identify which of the 3 packages the member is currently NOT subscribed to. So, what would be the better way to accomplish this?

Code:
<?php if (is_user_logged_in() && current_user_can("access_s2member_level2")){ ?>
<?php if (!current_user_can("access_s2member_ccap_blogs")){ ?>
Show subscription modification buttons to add Blogs package
<?php } ?>
<?php } ?>


----OR----

Code:
<?php if (is_user_logged_in() && current_user_can("access_s2member_level2") && !current_user_can("access_s2member_ccap_blogs")){ ?>
Show subscription modification buttons to add Blogs package
<?php } ?>


----OR-----

Code:
<?php if (is_user_logged_in() && current_user_can("access_s2member_level2") && current_user_can("access_s2member_ccap_media") && current_user_can("access_s2member_ccap_groups")){ ?>
Show subscription modification buttons to add Blogs package
<?php } ?>


...etc...

So, there seem to be actually several ways I could do this. Which would be better?

Statistics: Posted by pcwriter — June 25th, 2010, 4:24 pm


]]>