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™

Protect Custom Post Types

s2Member Plugin. A Membership plugin for WordPress®.

Protect Custom Post Types

Postby dev9833 » August 23rd, 2011, 12:09 am

Is there a way to protect all posts under specified custom post types? I'm using categories to protect the posts now which is working fine, but I'm worried down the road that my client could possibly uncheck the appropriate category or otherwise change the category hierarchy to cause a problem. Setting up the s2member restrictions based on custom post types would be so much easier.

Seems like something that would be a good core integration into the plugin anyway. If I'm missing something please let me know! Cheers.

Thanks in advance.
User avatar
dev9833
Registered User
Registered User
 
Posts: 13
Joined: April 5, 2011

Re: Protect Custom Post Types

Postby Jason Caldwell » August 23rd, 2011, 8:12 pm

Thanks for the excellent question
Hmm, I'll see what we can do about this in a future release.

That being said, s2Member's Post Level Access Protection is fully compatible with Custom Post Types. So if you want to, you can protect individual Posts this way, by ID, and it's OK if they're Custom Post Types.

The Category and/or Tag-based Restrictions are probably better though, so I think you're already on the right track. As far as the nesting goes, s2Member associates it's protection based on Category ID, and that does not change if/when the nesting order changes. So just make sure that you protect all any sub-categories inside the main category as well. That way if they're moved around and/or re-ordered, the client won't lose the protections applied by s2Member.

Again, I'll see what we can do to improve on this in a future release. We have some more work to do in this area already, related to bbPress Forum Topics, so perhaps we can look at this again at that time.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Protect Custom Post Types

Postby dev9833 » August 23rd, 2011, 9:37 pm

Thanks for the reply Jason, I appreciate the level of service you guys consistently provide. Looking forward to future updates.

For others reading this post, I've implemented s2member protection on all instances of a specific custom post type by using URI restrictions in conjuction with CPT archive permalinks. I set up archives for custom post types, and then just used the slug of the CPT archive to protect any posts using that slug. So anything at example.com/custom-post-type-name/post-name would be protected because /custom-post-name/ is in the URI restrictions in s2membet options. Seems to work great and I don't have to worry about client deselecting a category.
User avatar
dev9833
Registered User
Registered User
 
Posts: 13
Joined: April 5, 2011

Re: Protect Custom Post Types

Postby Cristián Lávaque » August 23rd, 2011, 11:50 pm

Sounds like a great solution. Thanks for sharing it. :)

Another thing you may want to try is the customization Jason explains in the 2nd segment of the Custom Capabilities video, only instead of checking for a tag or category in the condition, it'd be a custom post type (if that's possible). http://youtu.be/h7zBH938VbA

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: Protect Custom Post Types

Postby dhempy » October 6th, 2011, 2:50 pm

Same needs here - Need to protect all Custom Post Type of type "Labs". No direct way to do this in s2member, and I don't trust my client to always tag or categorize new posts.

I tried using URI restrictions, but that had a problem: I DO want the whole world to see archive-labs.php, listing all the Labs with their teaser text, but you must be a member to actually open the Labs. I could probably work around the URL issue for the archive page, but the ultimately it would still not protect the labs when accessed other ways. (feeds, post ID, etc.)

I used the approach described in the video, but a little differently. My site uses a single-labs.php template. I added the following code to the top of that template:

Code: Select all
<?php
   if (! current_user_can("access_s2member_level2")) {
      wp_redirect( home_url('/sign-up/') );
      exit();
   }
?>


This meets all my needs. I may change that to custom capabilities after I get some other things nailed down.

Having said that, missing Custom Post Types in s2member's restrictions seems like a big oversight to me. I hope you add that feature in the future.

Keep up the good work, guys!
-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Protect Custom Post Types

Postby Cristián Lávaque » October 7th, 2011, 12:39 am

I'm glad the tip Jason explains helped you work out a solution. :)

Thanks for the suggestion to include custom post types in the access restrictions!
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: Protect Custom Post Types

Postby Jason Caldwell » October 11th, 2011, 7:11 pm

Thanks for the heads-up on this thread.

OK, just to clarify for the benefit of other readers. s2Member DOES support Custom Post Types. You can protect Custom Post Types with s2Member's Post Level Access Restrictions in your Dashboard, under: s2Member -> Restriction Options -> Post Level Access Restrictions.

That being said, it is true there is no way to protect Custom Taxonomies ( i.e. Custom Categories that contain Custom Post Types ), other than with URI Restrictions; and we will try to improve upon this in a future release, definitely. @dhempy Just to confirm, this IS what you're referring to, correct?
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Protect Custom Post Types

Postby dhempy » October 12th, 2011, 4:00 pm

I'm glad to hear that, Jason! I must have overlooked that. I'll give it a shot tomorrow.

No, I need to protect the entire CPT, without regard to taxonomies.

Thanks,
-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Protect Custom Post Types

Postby dhempy » October 14th, 2011, 1:51 pm

Ok, now I'm confused. I looked at "Post Level Access Restrictions ( optional )" and I see that I can protect individual posts, including posts that are of a Custom Post Type. However, I don't see the part where I can protect everything of a given CPT.

If I don't trust my client to tag or categorize each new "Lab" post to ensure it is protected, I certainly would not expect them to add each post ID to a list of protected posts on this page.

I hope I'm missing something and that you'll point me in the right direction. I really want to tell my users to simply create new Labs, and they will be protected without any more work from them. (And to be confident there's no way for them to accidentally screw it up!) I've pretty well reached that point by adding custom code to templates, but I'd readily abandon that if there was a turn-key solution to protecting an entire CPT.

Thanks,
-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Protect Custom Post Types

Postby dhempy » October 26th, 2011, 2:34 pm

Jason Caldwell wrote:OK, just to clarify for the benefit of other readers. s2Member DOES support Custom Post Types. You can protect Custom Post Types with s2Member's Post Level Access Restrictions in your Dashboard, under: s2Member -> Restriction Options -> Post Level Access Restrictions.


Jason - Can you expand on this? I don't see any way to protect a CPT on that page.

Do you mean that an individual post (e.g. id=124) can be protected, even if it is of a CPT? That's not what I'm looking for. I want *all* posts of a given CPT to be protected. Is there any way to do that?

Thanks, as always, for your great support, Jason!
-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Protect Custom Post Types

Postby Jason Caldwell » October 26th, 2011, 4:36 pm

Thanks for the follow-up.

Right, Post Level Restrictions allow you to protect "all" Posts, or specific Post IDs, but s2Member does not have a built-in way to protect "all" Posts of a specific type yet.

You CAN protect specific Post IDs with s2Member using Post Level Restrictions, even if they are Custom Post Types (that's fine to do that); but protecting "all" means that you're protecting "all" Posts (of any kind), regardless of Post Type. So this is where you're having a problem.

In your case, here is what I would do...

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php ( these are MUST USE plugins, that's what you want )
Reference article: http://codex.wordpress.org/Must_Use_Plugins
Code: Select all
<?php
add_action 
("wp", "my_custom_s2_security_gate");
function my_custom_s2_security_gate ()
    {
        if (!is_admin() && is_singular ("my_custom_post_type") && !current_user_can ("access_s2member_level1"))
            /* This protects "all" Posts of Post Type: `my_custom_post_type`. See: <http://codex.wordpress.org/Conditional_Tags#A_Single_Page.2C_Single_Post_or_Attachment>. */
            wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . exit ();
    }
?>

Reference articles:
http://codex.wordpress.org/Conditional_ ... Attachment
http://devpress.com/blog/conditional-ch ... ost-types/
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Protect Custom Post Types

Postby dhempy » October 27th, 2011, 1:44 pm

Looks good, Jason. I'll give that a try...

-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Protect Custom Post Types

Postby Jason Caldwell » November 1st, 2011, 7:39 pm

Protecting all Posts of a specific Post Type will become available in the next release.

( click to enlarge )
SNAG-0102.png
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Protect Custom Post Types

Postby dhempy » November 2nd, 2011, 9:44 am

Wo0T! :D
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 6 guests

cron