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™

Custom Capabilities

s2Member Plugin. A Membership plugin for WordPress®.

Custom Capabilities

Postby Lonaldo » August 26th, 2011, 5:55 pm

Hi:

I LOVE the idea of custom capabilities, and I get the concept of the required PHP code entirely. However, I am relatively new to Wordpress, and don't know how to provide either tags or categories to pages (I can see how to add them to posts, but not pages). Is there an easy way to do this, or is there a plugin you would recommend? Thanks!

Lonnie
User avatar
Lonaldo
Registered User
Registered User
 
Posts: 5
Joined: August 26, 2011

Re: Custom Capabilities

Postby cassel » August 26th, 2011, 10:25 pm

Lonnie, i was exactly in the same situation. IN s2Member, when you add a new page, you will see on the top right corner of the dashboard page, a little pull-down menu called s2Member, and inside it you will have Page Level Restriction? and Require Custom Capabilities? . It is the Custom Capabilities that you will use to give it the "tag" you want to use to limit the access.

So, if you want a category of pages about Music, you can enter Music in the Custom Capabilities field, so when you create the conditional code, you will then be able to use it to give access only to those pages to certain people.

I am sure Cristian will come with the link to the correct video but i remember that this top right box was not mentioned in the video! Hope it helps.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom Capabilities

Postby Cristián Lávaque » August 27th, 2011, 2:23 am

I believe you mention tags because of the code Jason suggested for the functions.php file in his Custom Capabilities video, am I correct? That was a hack was to apply a custom capability requirement to a whole category or tag, but as you say, pages don't have tags or are categorized.

The meta box in the edit page is probably what you want to use, as Cassel suggested. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities

Postby Lonaldo » August 27th, 2011, 8:05 pm

Cassel/Cristian:

Thank you both for getting back to me so quickly! This should work out great. If you don't mind, I'd like to ask a couple of follow-up questions:

1) Can you use the technique you described to assign more than one tag to the same page? For example, I might want a general "Music" tag that I would use to assign the page to a deluxe membership, and another specialized tag for "Jazz" that I would assign to a less all-inclusive membership. (I realize there are other ways to accomplish this with single page tags, but this would be the most convenient for the application I have in mind).

2) Does this use the same "tagging" technique as some of the other Page tagging applications, like "Page Tagger"? The reason I ask is because it would be convenient for me to see the tags on the Page List screen at a glance, rather than to have to open up every individual page to see the tag (I have many pages on my site).

Thanks Again!

Lonnie
User avatar
Lonaldo
Registered User
Registered User
 
Posts: 5
Joined: August 26, 2011

Re: Custom Capabilities

Postby cassel » August 27th, 2011, 8:26 pm

Here is what i can contribute.
1) Can you use the technique you described to assign more than one tag to the same page? For example, I might want a general "Music" tag that I would use to assign the page to a deluxe membership, and another specialized tag for "Jazz" that I would assign to a less all-inclusive membership. (I realize there are other ways to accomplish this with single page tags, but this would be the most convenient for the application I have in mind).

From what i gathered from similar question, if you assign two "custom tags" to a page, it will require the user to have BOTH access. So, if you want page to be accessible through a package called "Jazz-singers", and a package called "Jazz-musicians", then, you might need to set pageA with the "tags" for jazz and singer, and the pageB with jazz and musician. However, you would have to be sure to include, in the paypal button creation, BOTH tags (either JAZZ and SINGER or JAZZ and MUSICIAN), otherwise, if you have only JAZZ, then the user will not meet both criterias for tag access. I think it is possible, but it will depend on the structure you want to set up.

Another example, i will have 2 different packages sooon and i have pages set with three tags but only one per page. I have some pages with BASIC, some pages with ELEMENT and one page with FORUM so when user buys access to package A, they get access to all the pages with BASIC, and the FORUM, and if user buys package B, i will give access to pages ELEMENTS and FORUM (yes, FORUM is part of both packages), yet each page has only one tag.

2) Does this use the same "tagging" technique as some of the other Page tagging applications, like "Page Tagger"? The reason I ask is because it would be convenient for me to see the tags on the Page List screen at a glance, rather than to have to open up every individual page to see the tag (I have many pages on my site).

If you are talking about showing the ccaps like it shows the page ID, i dont think it is done yet, but it is a darn good idea! Suggest that to Jason! I would love that too.

Hope it helps.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom Capabilities

Postby Cristián Lávaque » August 28th, 2011, 2:23 am

Using the word "tags" when talking about "custom capabilities" may lead to confusion. Tags are another thing that is used for labeling posts (or pages if using a plugin like Page Tagger). s2Member has a levels access restriction that works with tags. WP Admin -> s2Member -> Restriction Options -> Tag

So let's stick to "custom capabilities" or "ccaps" to avoid misunderstandings. :)

Cassel is right, the way s2Member handles multiple ccaps in for a page/post is requiring all of them to show the page, not one or the other. If you need to require one ccap or the other in a page, instead of the meta box, you'd use conditionals in the body of the page. WP Admin -> s2Member -> API / Scripting -> Simple/Shortcode Conditionals

In your case, though, you don't need to add the "music" ccap in the meta box of a page that's just for "jazz" users, you can just add the "jazz" one that'd only show it ot users with the "jazz" ccap, which would be a portion of the "music" ones. I hope that makes sense.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities

Postby Lonaldo » August 28th, 2011, 12:10 pm

Cassel/Cristian:

I can't thank you both enough for getting back to me so quickly with your informative replies! If I understand what's going on, I think that the reason you would need both is because of the way Jason formulated the code in functions.php, and not something that is fundamental to the S2Member product. I have an idea for a solution that would work great for my application:

1) Bypass the "ccaps" tagging altogether, download page tagger, and use it to tag my pages. This will allow me to see the tags in Page list view and give me the ability to apply multiple tags. (Not essential, but it sounds like it will work, so why not?)
2) Modify the PHP code which Jason suggested in his video (functions.php) to enable permissions to pages as I see fit (I am not a PHP expert, and I haven't tested the code yet, but this should give you an idea of where I'm going):

Code: Select all
//==================================================================================
//Start out assuming the user does NOT have permissions...
$Permissions_Flag = "N";

//First, check for a simple tag of "R" which I will add to ALL pages I want to restrict, in addition to one
//or more specific tags.  If the "R" tag does not exist, by my definition I do not want to restrict this 
//page, so no need to check further...
if !has_tag("R")
    $Permissions_Flag = "Y";
//Specific permissions tests based on specific tags follow...
else if ((has_tag("music") && current_user_can("access_s2member_ccap_music"))
    $Permissions_Flag = "Y";
else if ((has_tag("jazz") && current_user_can("access_s2member_ccap_jazz"))
    $Permissions_Flag = "Y";
endif;

//If the permission checks failed to remove the restriction, user will be sent to the
// membership options page...
if $Permissions_Flag == "N" {
   header ("Location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
   exit (); }
endif;
//===============================================================================
 

To oversimplify, Jason's strategy is to assume the user has permissions until proven otherwise, whereas my strategy is to assume the user doesn't have permissions until proven otherwise. This way I can test my tags individually, verify my pessimistic assumption once at the very end of all my permission checks, and redirect if necessary. Can you think of any reason why this wouldn't work? Sorry to keep bothering you, but I'd like to make sure I have the correct strategy before applying it to all the pages on my site.

Thanks!

Lonnie
Last edited by Cristián Lávaque on August 29th, 2011, 1:33 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
Lonaldo
Registered User
Registered User
 
Posts: 5
Joined: August 26, 2011

Re: Custom Capabilities

Postby Cristián Lávaque » August 29th, 2011, 1:43 pm

It looks like it should work. Let us know how it goes. :)

In my opinion, if you already have the tags in place, you know there are restrictions being used, so no need to have another tag that to say it's restricted. This would probably be a shorter version of your code:

Code: Select all
if ((has_tag('music') && !current_user_can('access_s2member_ccap_music')) || (has_tag('jazz') && !current_user_can('access_s2member_ccap_jazz'))) {
        header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
        exit;
}
 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities

Postby peeld » August 29th, 2011, 2:04 pm

I'm trying to accomplish almost exactly the same thing, but instead of tags I'm trying to restrict access to buddypress groups. This OR statement doesn't work - test users with EITHER capability do not have access to the group:

Code: Select all
       if (( bp_is_groups_component() && 'goal-setting-and-mental-management' == bp_current_item() && !current_user_can('access_s2member_ccap_goalsettingworking')) || (bp_is_groups_component() && 'goal-setting-and-mental-management' == bp_current_item() && !current_user_can('access_s2member_ccap_goalsettingauditing')))
     {
           header ('Location: '. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
            exit ();
      }


I added in a ')' in a couple places because I think your code snippet was missing them?
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Custom Capabilities

Postby Cristián Lávaque » August 29th, 2011, 4:26 pm

Yeah, it had a parenthesis missing, thanks for spotting it. I edited my post to correct it.

About your code, your user should have access if he has either one of the ccaps, right? Then using the OR is the problem, because one of those ccaps missing will cause the redirection. You should use AND so that happens only if both ccaps are missing.

Try this version:

Code: Select all
if (bp_is_groups_component() && bp_current_item() == 'goal-setting-and-mental-management' && !current_user_can('access_s2member_ccap_goalsettingworking') && !current_user_can('access_s2member_ccap_goalsettingauditing')) {
    header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit;
}
 


I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities

Postby peeld » August 29th, 2011, 4:29 pm

I've been hitting redirect all morning waiting for this answer. I'm going to test it as soon as I get a minute and will report back!

I must say, just browsing through this forum, the support is EXCELLENT, and I've loved watching you populate the list of help requests all morning with your responses. I'm super happy with S2Member and my site isn't even LIVE yet... I think it's a testament to the product that most of the help requests are regarding *extending* the product rather than basic functionality. THANKS!!!

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

Re: Custom Capabilities

Postby Cristián Lávaque » August 29th, 2011, 5:52 pm

Daisy, that's really nice of you! Thanks for the kudos, I really appreciate what you said. :)

I look forward to your results, I hope the code works the way you want it. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities

Postby peeld » August 29th, 2011, 10:59 pm

It WORKS! Woot! Happy dance here ;)

THANKS!

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

Re: Custom Capabilities

Postby Cristián Lávaque » August 30th, 2011, 4:41 pm

Awesome! Thanks for the update. I'm glad that solved it. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron