最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Allowing users to manually add or remove themselves tofrom WordPress multisite blogs

programmeradmin3浏览0评论

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
  • How are you automatically syncing users? You mention a plugin, but to do what you want some modifications or filtering of that plugin will be necessary. Any answer you get here can't account for that plugin as that would be off-topic, and it wouldn't be standard WordPress – Tom J Nowell Commented Oct 26, 2020 at 12:15
  • I used the Multisite User Management plugin for those particular sub-sites, but this automatic syncing is only for them and I only mentioned it to explain my process and what I have been experimenting with. The sub-sites I made private and want to give an opt-in or opt-out option are not controlled by that plugin and they are the ones I want to control independently without a plugin, but by utilizing the add_user_to_blog function (if possible) to give users the choice. – jsmod Commented Oct 26, 2020 at 12:23
Add a comment  | 

1 Answer 1

Reset to default 0

I did it, and it works just as I want it to, but I don't really understand how it worked

发布评论

评论列表(0)

  1. 暂无评论