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.

Brett Adcock


My Latest Replies (From Various Topics)

Viewing 7 replies - 26 through 32 (of 32 total)
Author Replies
Author Replies
Posted: Sunday Mar 18th, 2012 at 9:24 am #8485

Huh. I’m going to try your version, but let me clarify one thing. Your code blocks students, right? I think I need to reverse it to allow students by setting $excluded to FALSE. Thanks for your help.
EDIT: No, your code works as it was written. I guess I need to revisit the source to better understand what’s going on.
EDIT: Right. I got confused by the variable name “excluded”. It doesn’t determine whether or not the user IS (=true) or IS NOT (= false) excluded from accessing the specific post/page. Rather the opposite. It determines whether the user is excluded from the sp post/page access requirements.

  • This reply was modified 4 years, 9 months ago by  Brett Adcock.
  • This reply was modified 4 years, 9 months ago by  Brett Adcock.
Posted: Wednesday Mar 14th, 2012 at 8:16 pm #8187

I just realized that my question was a little bit strange. I was thinking in terms of do_action (which would need to get called in the right order) but this hack is using a filter, so it doesn’t need to be wrapped in another hook…

Good news:
It looks like the filter strategy is going to work. I couldn’t get it to work with “ws_plugin__s2member_sp_access_excluded” but I AM having luck with “ws_plugin__s2member_sp_access” (same link as above, just a couple lines lower in the code).

For anyone else who stumbles upon this thread, my code looks something like this:

//my custom capability is named "student"
add_filter("ws_plugin__s2member_sp_access", "special_access",1, 3 );

function special_access() {
		
		global $post;
		$current_id = $post->ID;
		$post_type = get_post_type($current_id);
		
		//add conditional test for whether stop-student is true/false
		if ( current_user_can("access_s2member_ccap_student") ) {
			return true;
		} else {
			//tough luck buddy
		}
}
Posted: Wednesday Mar 14th, 2012 at 2:55 pm #8146

I’m going to give this a try. Do you have any idea where this happens in the execution order? More to the poin, I’m wondering if I can add an action to the “template_redirect” hook in which I add this filter. Obviously, “template_redirect” has to happen BEFORE the filter gets applied for this to work.

Posted: Wednesday Mar 14th, 2012 at 2:47 pm #8144

The cloning idea occurred to me, but it’s not practical because there are many different specific post/pages. I’m sure I could get it working initially, but then the client would be left with a bunch of duplicate posts that would inevitably get confused.

Posted: Tuesday Mar 13th, 2012 at 3:50 pm #8040

I think this can work, but there’s just one thing I’m not sure how to do. It’s #3 below.

Here’s the steps:
1. I need to “sell” a custom capability with a form.
2. I need to write a function in my theme to test whether the curent user has that capability or not…
3. IF the user CAN view the post… I need to STOP s2Member from redirecting them to the member options page

In the video, Jason’s function redirects users if they CAN’T view the post/page but I can’t do this because the posts in question are already protected by specific post/page restrictions (with no level requirement). If I protect them all by adding them to level 1 (like Jason does in the video), then the people I’ve already sold specific posts/page access to won’t be able to view their purchases anymore. Right? (Because they are still level 0)

So somehow my function that’s called at the “template_redirect” hook needs to PERMIT access to the intended post/page… somehow overriding the redirect.

Please tell me if I’m making sense, and if you have any advice on how to achieve what I’m looking for.

  • This reply was modified 4 years, 10 months ago by  Brett Adcock.
Posted: Monday Mar 12th, 2012 at 8:24 pm #7935

I reread your suggestion and I think it might work for what I’m doing if I can combine it with a free membership form. For example, if I could add the id=”##, ###, ###” attribute to the free form this would work. Or maybe there’s another way to achieve this same behavior. Thanks for any suggestions you might have.

Posted: Monday Mar 12th, 2012 at 2:56 pm #7912

That would work, but the plan is to grant this action automatically to certain approved email addresses. I may not be up to date with all of s2Member’s new features, but I thought the best way to do this was to use the registration notifications api to grant access to new registrants with certain email addresses. The notification would run a custom script to sniff the email address and then (if it passes) upgrade that user to the all-access level automatically.

My concern with writing a script to grant specific post/page access is that it would have to be updated (by me) every time the site owner adds a new restricted post/page.

Viewing 7 replies - 26 through 32 (of 32 total)

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.