1

I would like to create the following type of set up and wonder if anyone knows if it is possible on a subdomain and how it can be done.

I have a main site, "example.com", and a subdomain, "subdomain.example.com". The subdomain will also be built with Wordpress but the content on the two will be different. I will have 3 user roles, Role 1, Role 2 and Role 3. Roles 1 and 2 users will sign up on the main site. Role 3 users will sign up on the subdomain and post their content on the subdomain.

What I want to do is to restrict access to the things on the subdomain so only people with user Role 2 (and obviously Role 3 since they are the ones posting the content) can see the things on the subdomain, meanwhile user Role 1 cannot see it, and logged out people can't see it either.

Is there a way I can do this so the users only need to sign up once? All the methods I have thought of so far requires user Role 2 to sign up twice, once on the main site and once on the subdomain, or require me to manually assign users (not roles) to the subdomain and this would be very tedious if there are many users. I thought of sharing a user database in my hosting backend but they recommended against it. For the record I am not a developer.

2
  • My first suggestion is to not have the subdomain - I think you'd open yourself up to a much better user experience to work through achieving the same objectives on a single domain. The only solutions I can think of, to do what you want, would require users to go from domain.com to subdomain.domain.com so that it would be able to carry across their identity and permissions. And I don't think that's a stable way to do things. Even something as simple as putting the subdomain behind HTTP Authentication and then automatically logging them in would require them visiting the main domain. Commented Jun 28 at 20:11
  • Why do you want the second site under a sub-domain? Commented Jun 28 at 20:11

1 Answer 1

1

I've figured out a possible way to do this, so I want to post my answer here for future reference and anyone else that might find it useful.

There is a free plugin called "WP Remote Users Sync", here is the page for it, it is also on github.

This pluign only works on individual single sites (ie it won't work for Wordpress multisite since multisite uses a single installation of wordpress). Since a subdomain is essentially two separate sites where you can install two instances of Wordpress, one on the main site and one on the subdomain, I installed this plugin on both the main site and the subdomain (which also runs on Wordpress).

Setting up the plugin:
Access the plugin via Settings -> WP Remote Users Sync. In the plugin settings on the "Security" tab, add a passcode key (can be anything as long as it is the same for both sites) to the "Action Encryption Key" and the "Action Signature Key" and save.

Then in the "Remote Sites" tab, there is a place in the bottom right corner where you can add a remote site to sync with. I put the site that would be remote relative to the site I am in the settings for (ie if I am in the main site, the remote site is the subdomain, so in the settings on the "Remote Sites" tab, I put the URL of the subdomain, and vice versa). Save it to create a new remote site, it wll be listed in the Remote Sites tab.

Click the one you want to edit, ticked all the boxes you want to sync in the appropriate direction (eg Outgoing Actions for the main site would mean whatever happens on the main site, also happens on the subdmain). Do it in reverse on the subdomain site (ie instead of ticking the boxes in the outgoing actions column, I ticked them in the Incoming Actions). After saving, you can test it by clicking on "Test", a red cross means there is an error, it will tell you what the error is, a green tick means it has been set up correctly.

I tested this and when working properly and if the appropriate check boxes are ticked, any new user that signs up to the main site will also get signed up to the subdomain site automatically. It seems existing users have to be added manually using the import export function of the plugin. I have not figured out how to make their user roles sync, the users that get imported to the subdomain site gets whatever the default role on the subdomain is. When the users are synced properly in the right direction, users who log in to the main site are also automatically logged in to the subdomain. People who attempt to log in to the subdomain but have not registered on the main site will not be able to.

The next part is the restriction part: use user roles (you can choose which role to sync and export) and a restriction plugin to control what user role can see the content on the subdomain. You may need to manually approve new registrants on the subdomain, else anyone can log in and see the things there.

The issue I now have is how to hide pages of a website that is not a wordpress "Page", ie some pages are dynamic and generated by a plugin and not listed in the wordpress dashboard Pages section so I can't put a short code on that page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.