protecting blogs in multisite mode not working

just converted an existing site with membership and bp installed to multi-site and I'm trying to make a sub-blog protected, but I'm not managing. Main site restrictions still work fine.

i have membership activated on the root blog, activating it elsewhere doesn't work as it treats it as a new membership installation. the blog in question is created via the network admin area by me.

the blogs do appear under Buddypress > Blogs in levels. I tried only selecting the main blog in positive, or the other blogs in negative, no difference, even logged out users can see the blog (limited to a visitor level, which guests also are assigned to).

not sure if there's an issue with adding multisite after membership, or if I'm doing something wrong, as there's not much documentation about multisite with membership. good chance it could be my installation (if you remember, there's been a few issues due to my migrating forums etc.), but just don't know!

  • Jonathan


    Following on from your previous question...
    .... I think I have an idea what you are trying to do... If not, sorry, just disregard what follows :slight_smile:
    What you are missing is you need to activate global tables. That is shared tables across your network, this is done by adding this to your config file

    define( 'MEMBERSHIP_GLOBAL_TABLES', true);

    This will allow your main membership site's (root blog) subscriptions, levels to be "global" across your entire network. Like phil said, will need to activate the membership plugin on those sites you want to protect (network activate).

    Now that you have global tables set up as true, you can use those conditional statements,
    to protect that sub-blog based on the main sites subscription/levels.

    WARNING: It is either one or the other - either you have a network of single separate membership sites, or you have one global membership site. The global membership site at the moment looses a lot of the plugin features - you'll see some things just don't work like single membership sites. that is why I use the conditionals to restrict access and leave the positive/negitive rules completely empty across the network. Anyways, the documentation surrounding the membership plugin is very very limited. Hoping that changes soon. laugh.

    I'm sure one of the support staff will better explain this than me, also try searching for membership global tables :wink:


  • Marcus

    hey Jonathan, you posted just as i did, you're saving a lot of time for me today. thanks!

    so... reading other posts I can see that I lost my membership info. That's not acceptable (unless I can re-import the settings somehow). My other solution would be to just use switch_blog and do the above suggested by Jonathan against the main blog. Would appreciate some dev input here if there's a more elegant way.

    All I want to do is restrict a small number (currently 1) number of sub-blogs and doing it via PHP is fine with me. All other membership stuff is limited to the main blog (at least for now)

    I agree that the documentation is pretty limited. Speaking from recent experience I'm betting wpmu supporters would cut their time spent supporting this plugin significantly if you added more docs (worth the hassle).

  • qubedinc

    Hi Barry can you have look on my post

    and also integration of membership with new blog template as i mention in post below

    so in next version we can have more options

    this will really help full

  • Marcus

    ok, so those functions probably won't work even with switch_blog if you're trying to verify on a blog where membership isn't installed, as the functions don't exist. I don't want to use global tables as they're experimental and losing users is not an option anymore.

    However, thankfully I can code so I just whipped something up myself. Basically you can move the first line to your wp-config.php file and use a comma seperated list of blog ids if you want to protect > 1. The function can go into a random file in mu-plugins or your functions.php theme file:

    my set up is MS mode, with membership on the root blog and all other blogs (in my case one) are to be blocked to users without this ID level.

    function my_faultpress_check_membership_sites(){
    	global $wpdb, $current_site;
    	if( is_super_admin() ) return;
    	$membership_options = get_blog_option($current_site->blog_id, 'membership_options');
    	if( !empty($membership_options['nocontent_page']) ){
    		$levels = (defined('M_SITE_ACCESS_LEVELS')) ? M_SITE_ACCESS_LEVELS:'';
    		$levels = explode(',',$levels);
    		if( !is_main_site() && count($levels) > 0 ){
    			$var = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->base_prefix}m_membership_relationships WHERE user_id='".get_current_user_id()."' AND level_id IN (".implode(',',$levels).")");
    			if( !($var > 0) ){
    				$url = get_blog_permalink($current_site->blog_id, $membership_options['nocontent_page']);

    can a dev confirm that there'll be a level id there for every user, even if they're on a sub with multiple levels?