How to check main site user level from subsite in a multisite network

I'm using wordpress multisite. I installed s2member plugin.

s2member plugin creates 4 extra level. I mean like level1,level2,....

I'm displaying content using this code

if (current_user_can("access_s2member_level1")){ 
     the_content();
 }

Here level1 member is premium member. If the user is not a premium member then the content will be hidden.

My problem

I created separate site for each niche. I'm the only admin for all sites.

My goal is user buys the premium account in my main site and access all my site network without paying extra money.

But s2member work for only for that individual site. Its not working globally.

So i was thinking like activate s2member only in main site and check the user level from subsite. If the user level is 1 then display the content

So can anyone help me how to check main site user level from sub site?

I mean like this

if (current_user_can("access_mainsite_s2member_level1")){ 
         the_content();
     }

Thanks

Topic s2member user-access multisite Wordpress

Category Web


The function current_user_can_for_blog() seems to be what you are looking for. With your example above, this solution should work:

 $blog_id = 1; //set the blog id to the main site id    
 if (current_user_can_for_blog($blog_id, "access_mainsite_s2member_level1")){ 
     the_content();
 }

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.