latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom Capabilities Can't restrict the access

Home Forums Community Forum Custom Capabilities Can't restrict the access

This topic contains 5 replies, has 2 voices. Last updated by  Bruce 3 years, 7 months ago.

Topic Author Topic
Posted: Sunday May 5th, 2013 at 9:56 pm #49250

Hi, I’ve been trying to apply the Custom Capabilities since my website is starting to grow and become a little complex to handdle.

I have a “section” in my page (which is a group of pages and posts) that I need to be accessed by only a group of customers. The Customers that will access this section have already paid, so I have 2 questions, first because of my lack of deep knowledge of technical aspects:

1) I’ve added a few lines to the functions.php file of my theme (Dynamix) so I can Start testing the new changes, but this doesn’t work. The users can still access the pages I try to block:

add_action ("template_redirect","my_custom_capabilities");

function my_custom_capabilities ()
    {

        if(has_tag("test_ccap") && !current_user_can ("access_s2member_ccap_test_ccap"))
            {
                            header ("location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                            exit();
            }
    }

Printscreen: http://screencast.com/t/s3SK4VkutK
What am I doing wrong? :)

I’ve added the tag in the test post: http://screencast.com/t/3QScwhk1EAv
Also I created a test user profile and left the “Custom Capabilities:” field empty: http://screencast.com/t/dfbPGgQb
But this user still can access to the post I’m trying to protect.

2) Once I can make this work, since a group of current clients should be able to access this new section, how should I modify their profiles so they can access? This way?: http://screencast.com/t/vltGq5BV is that correct?

Finally, this “adding capabilities to users” work, must be done by hand? Or can I use some automated way to add custom capabilities to a group of users at once?

Thank you very much for your answer and help!

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Monday May 6th, 2013 at 10:16 am #49262

Hi! Good morning (at least here! :)) I’m working on the site, creating the new section untill I can protect it so I can publish it.

But I’d like to add a question to this topic:

I’ll need that one page when is accessed redirects some customers (that doesn’t have the necessary capabilities) to other.

I mean: I’ll have a page called “music”, in that page I’ll upload music from some artists (lets say 10 albums), and I need another “music” page whith just 5 albums. So when a customer with ccap; “music10” access the link everything works normally, and when a customer that has the ccap; “music5” access the page would redirect him/her to the other page. (In this case I don’t want to take them to the S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL, just to the correct page, without “warning” the customer about any error, or trying to sell a high level suscription.

I believe I can do it by adding some code to the especific page “music” right? (if I undestood correctly a part of the video of custom capabilities) But just wanted to be sure and ask for some guide about where should I insert the code.

Thanks again!

Posted: Monday May 6th, 2013 at 11:11 pm #49331
Bruce
Username: Bruce
Staff Member

1) I’ve added a few lines to the functions.php file of my theme (Dynamix) so I can Start testing the new changes, but this doesn’t work. The users can still access the pages I try to block:

I think a more reliable way of accomplishing what you need here would be to do something like this:

<?php
add_action ('init','my_custom_capabilities');
function my_custom_capabilities ()
    {
        if(has_tag('test_ccap') && !current_user_can ('access_s2member_ccap_test_ccap'))
            {
                            wp_redirect(S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                            exit();
            }
    }
&#91;/hilite&#93;

<blockquote>
2) Once I can make this work, since a group of current clients should be able to access this new section, how should I modify their profiles so they can access? This way?: http://screencast.com/t/vltGq5BV is that correct?
</blockquote>

This is correct.

<blockquote>
I believe I can do it by adding some code to the especific page “music” right? (if I undestood correctly a part of the video of custom capabilities) But just wanted to be sure and ask for some guide about where should I insert the code.
</blockquote>

You could do this, or you can wait for the redirect and redirect from your Membership Options Page to the correct page. You can use the Membership Options Page variables to do this.

See: Dashboard -› s2Member® -› API / Scripting -› Membership Options Page Variables (MOP Vars)
Posted: Friday May 10th, 2013 at 11:01 am #49692

Thank you very much for the answer! I’ll try to set all this right now.

Let me ask you something, so I can be sure of using correctly the plugin :):
I could just clasify all post inside the “sections” of the web site right? For example: post 1,2,3 & 4 belong to section (ccap) “special_videos”. The posts 5,6,7 & 8 belong to the section “special_albums”, by adding the tag “special_videos” and “special_albums” in each post and being sure of adding those ccap to each user. I undestand that would be all.

Now, How can I clasify the pages of the site? In posts I can add a tag to each new post, but in pages what can I use to clasify them?

thank you very much (again!) nice friday!

Posted: Friday May 10th, 2013 at 11:31 am #49694

I’m trying to configure the ccaps and test them on one post but it doesn’t block the page access. I did it this way:

http://screencast.com/t/OEN90ZmL

I really can’t undestand what’s wrong.
Please! help!

thank you again & sorry for the dumb questions…

Posted: Monday May 13th, 2013 at 3:24 pm #49845
Bruce
Username: Bruce
Staff Member

I’m sorry for the confusion.

Jason went over the way to accomplish this here:

https://www.s2member.com/forums/topic/custom-capabilities-assistance-please/#post-37272

Viewing 5 replies - 1 through 5 (of 5 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.