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™

Multisite: getting sub-blog member level by main site

s2Member Plugin. A Membership plugin for WordPress®.

Multisite: getting sub-blog member level by main site

Postby groucho75 » June 15th, 2011, 9:11 am

Hi, I need help about a multisite environment I'm developing.
I have a multisite with a lot of blogs.
It's an association that has a national main site (the 1st blog) and a lot of regional sub-sites (the other blogs of the multisite).
S2Member is sitewide activated and properly setted up in each blog. The registration is free and we are using the Membership Only option, not Blog Farm.

I need that all the operations related to membership will be done on main site.
So I have already coded all redirects from blogs to main site: eg. registration, login, lost password, member option page... It seemes to be ok.
When an user subscribes, he will automatically subscribe the main site and (optionally) the referring regional blog.
Then on main site (but not in other blogs) the registered user can upgrade to level 1. No more level needed.

I'd like that an user "level-1-on-main-site" can be enter all "level-1" contents of all blogs.
So I need a filter that looks for the s2 level in main site when the plugin checks the s2 level in a blog.
I wrote the following function:

Code: Select all
function my_check_user_level_fallback ( $level, $vars=array() ) {
    if ( is_admin() ) return;
    global $blog_id, $user_ID;    
    if 
( $blog_id != 1 && $level == 0 ) {
        switch_to_blog ( 1 );
        if ( $level == 0 && current_user_is("s2member_level1") ) {            
           $level 
= 1;
        }
        restore_current_blog();
    }
    return $level;
}
     
add_filter 
("ws_plugin__s2member_user_access_level", "my_check_user_level_fallback", 10, 2 ); 


It works properly in a post when I get constant (eg. [s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LEVEL" /]), but it does not when use conditional (eg.[s2If current_user_is(s2member_level1)]You are Level 1[/s2If]). Why?

Then, the hard issue... I have a problem about the automatic redirect to membership option page when a not authorised member try to enter a restricted post: I'd like to have some help about the hooks/code in order make my own level check and follow or cancel the redirect.

Sorry for my bad English, I hope you can understand my problem.
Many thanks for your help.
Last edited by Cristián Lávaque on June 15th, 2011, 7:49 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
groucho75
Registered User
Registered User
 
Posts: 4
Joined: June 8, 2011

Re: Multisite: getting sub-blog member level by main site

Postby Cristián Lávaque » June 15th, 2011, 7:56 pm

Well, Jason knows more about multisite, but I'll answer from what I know:

WordPress, shares the members from the parent blog with the child ones in a very limited way. And s2Member in a child blog is in its own scope, separate from the parent blog's s2Member.

This may explain why the current_user_is('s2member_level1') check didn't work. But for some reason that may have been unintended, the label constant was set per the parent blog's setting.

You should use that constant to your advantage, then, and change your code to use that instead of the Level number.

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: Multisite: getting sub-blog member level by main site

Postby groucho75 » June 20th, 2011, 4:47 am

Hi Cristián, many thanks for your kindness and answer. I'll use that constant to check permission on main site.
About the not-member redirect to membership option page, can you or Jason or anybody help me to find the action/filter hooks (or the php file that includes this routine) in order to filter the redirect according to my needs?
Many thanks again.
User avatar
groucho75
Registered User
Registered User
 
Posts: 4
Joined: June 8, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron