Helping you Build Your Own Social Network!

Faster, better and easier!

Need some help with setting up S2Member conditionals :)

(4 posts) (2 voices)

Tags:

No tags yet.


  1. Hi Brajesh,

    I've been looking into S2Member for my project, and what I want to do I protect certain Groups for regular users.

    I've got it all figured out how to set it up, I now just need a way to secure my BuddyPress Groups by adding some code to my functions.php.

    I've found a piece of code in a video on the S2Member site that shows how to achieve this with categories and tags. But what I would like to do is replace those conditionals with BP Specific ones. For example something like:

    bp_is_group() && ‘myGroupSlug’ == bp_current_item().

    So I need to combine the S2Member conditional tags with the BuddyPress ones, but I have no clue how to make it work.

    Here's the code from the S2Member video:

    <img src="http://dl.dropbox.com/u/1628201/S2Member.png" alt="" title="" />

    If you could help me out with this, that would be really great :)

    Thanks in advance,
    Bowe

    Posted 1 year ago #
  2. Hi Bowe,
    I will be glad to help.
    You will need to put following code (just append at the bottom of those else if)

    add_action("template_redirect","restrict_groups",15);
    function restrict_groups(){
    global $bp;
        $current_group=$bp->groups->current_group;
    $specific_groups=array("test","other-group-slug");//change it to group slug,as many groups as you want to allow
    
    if(bp_is_group()&&!empty($current_group)&&in_array($current_group->slug,$specific_groups)&&!current_user_can("access_s2member_ccap_groups")){
    header("Location: ".S@MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit(0);
    }
    }

    You will need to change current_user_can("access_s2member_ccap_groups") to the capability you have created.

    Please let me know if it works or not.

    Posted 1 year ago #
  3. Hi Brajesh,

    Thanks for the quick reply! It does not give me an error, but it also does not work :) I'll send you some details through PM, so you can check out the site :)

    Posted 1 year ago #
  4. Hi Brajesh,

    Do you have a few minutes to help me solve this problem in the next few days? It's basically the only thing I need to figure out :) I have one other question.. Is there a way to check if a Profile field is empty? I want to display the following code in my theme:

    <li>Occupation: <?php bp_profile_field_data( 'field=Title/Occupation' );?></li>

    But only show it when it's actually filled in :)

    Thanks in advance!

    Posted 1 year ago #

Reply

You must log in to post.