I am trying out WordPress multisite and have set it up so that the main site on the network allows users to register.
From my (beginner level) understanding of how WordPress multisite works: a user registered on the main site is allowed to view all network content unless it is protected. There is only one user table in the database shared by the network. But users don't have a "role" in sub-sites unless it is explicitly given to them in admin area or by registration or plugins that synchronize users.
So then I set up another few sub-sites, and for them I made the users sync automatically via a plugin, because I want to have some content on them that is restricted to certain user roles. This works fine, no issues here.
But then I tried creating a private sub-site that is viewable only to subscribers. Setting that up was easy. However, what I want to do now is allow users to "manually" join this private sub-site if they want to - instead of me doing that in the admin area.
To clarify, I don't want to sync all users to this sub-site or other private ones. I want to make it entirely optional by putting a list of the network sub-sites on the main site, with "Join" links next to each one. So if logged in users click "Join" they become subscribers in that sub-site and can view its content (and if they click "Leave" they are no longer counted as subscribers and retain only their other roles).
The plugins and a lot of the sample code I found on the internet usually address automatically adding users to sub-sites, or things like allowing registration per individual sub-sites. They don't cover allowing users themselves to manually join/leave multisite blogs.
Only one, long abandoned plugin addressed exactly what I am looking for (called Join My Multisite), but I think the PHP code is outdated it does not function very smoothly. It is not available in the WP repository, but the author kept it on Github.
The WordPress codex mentions an add_user_to_blog
function, but I need help understanding how to use it in this context. What I want is simple, but I don't know how to accomplish it.
Can I create a "Join" link that permits my main site users to Join the sub-sites they want to join, or a "Leave" link for them to remove their user role from only that sub-site? If yes, can you show me how, please?
Thank you.
I am trying out WordPress multisite and have set it up so that the main site on the network allows users to register.
From my (beginner level) understanding of how WordPress multisite works: a user registered on the main site is allowed to view all network content unless it is protected. There is only one user table in the database shared by the network. But users don't have a "role" in sub-sites unless it is explicitly given to them in admin area or by registration or plugins that synchronize users.
So then I set up another few sub-sites, and for them I made the users sync automatically via a plugin, because I want to have some content on them that is restricted to certain user roles. This works fine, no issues here.
But then I tried creating a private sub-site that is viewable only to subscribers. Setting that up was easy. However, what I want to do now is allow users to "manually" join this private sub-site if they want to - instead of me doing that in the admin area.
To clarify, I don't want to sync all users to this sub-site or other private ones. I want to make it entirely optional by putting a list of the network sub-sites on the main site, with "Join" links next to each one. So if logged in users click "Join" they become subscribers in that sub-site and can view its content (and if they click "Leave" they are no longer counted as subscribers and retain only their other roles).
The plugins and a lot of the sample code I found on the internet usually address automatically adding users to sub-sites, or things like allowing registration per individual sub-sites. They don't cover allowing users themselves to manually join/leave multisite blogs.
Only one, long abandoned plugin addressed exactly what I am looking for (called Join My Multisite), but I think the PHP code is outdated it does not function very smoothly. It is not available in the WP repository, but the author kept it on Github.
The WordPress codex mentions an add_user_to_blog
function, but I need help understanding how to use it in this context. What I want is simple, but I don't know how to accomplish it.
Can I create a "Join" link that permits my main site users to Join the sub-sites they want to join, or a "Leave" link for them to remove their user role from only that sub-site? If yes, can you show me how, please?
Thank you.
Share Improve this question edited Oct 26, 2020 at 13:25 jsmod asked Oct 26, 2020 at 11:29 jsmodjsmod 5013 silver badges18 bronze badges 2 |1 Answer
Reset to default 0I did it, and it works just as I want it to, but I don't really understand how it worked
add_user_to_blog
function (if possible) to give users the choice. – jsmod Commented Oct 26, 2020 at 12:23