Page 1 of 1

Multisite: getting sub-blog member level by main site

PostPosted: June 15th, 2011, 9:11 am
by groucho75
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.

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

PostPosted: June 15th, 2011, 7:56 pm
by Cristián Lávaque
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. :)

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

PostPosted: June 20th, 2011, 4:47 am
by groucho75
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.