0

I am creating a WordPress site in which I want to create mini-sites/sub-sites meaning each of them has their own separate user base. Alternatively, it's ok that all the users are in the same base, but that users that are not in the same role, group or those connected to a subsite are hidden. This could be done either with a plugin or that I create a PHP function.

I have looked through many plugins. WordPress multisite have a shared user base. My PHP skills are very limited, but I can understand it when I read it and modify simple things. I saw that it's possible to add_action('pre_user_query','xxxx');

I've tried the plugin "Members". However, if identifying the user's role through $current_user->roles[0] and I don't know how to create a code that hides users that do not have the same role.

TL;DR

Can anyone suggest a plugin or a PHP function that allows to either have separate user bases for subsites in one WordPress installation or which allows to hide users of another role or connected to another subsite when using the plugin Multisite? I'm also open to hear other solutions that I may not have thought about.

Thank you!!

6
  • So the problem with multisite is that users that don't belong to that site (i.e. that have no role on that site) still show up in user lists and the REST API? That feels solvable.
    – Rup
    Nov 2, 2020 at 13:20
  • What does REST API mean? The first part is correct. And yes, it looks very simple to do. I posted this the other day stackoverflow.com/questions/64635028/… My PHP skills are limited so I don't know how to code "if user has x role, then hide users of other roles".
    – jl001
    Nov 2, 2020 at 13:25
  • It's the modern web service API for WordPress. If you go to https://example.com/wp-json/wp/v2/users/ you'll see a user list too (although many security plugins disable this for unauthenticated access)
    – Rup
    Nov 2, 2020 at 13:27
  • Hmmm I don't see a list of users on that page.
    – jl001
    Nov 2, 2020 at 13:29
  • Apologies I meant your website not example.com if that wasn't clear. But if you don't, great, that's not something you'll then have to fix.
    – Rup
    Nov 2, 2020 at 13:30

1 Answer 1

0

You can use a subdomain for every site. Then it's easy to separate the users per wp-config.php:

$base = str_replace( '.', '_', filter_input( INPUT_SERVER, , 'SERVER_NAME' );

const CUSTOM_USER_TABLE $base . '_users';
const CUSTOM_USER_META_TABLE  . '_usermeta';

unset($base); // clean up
4
  • Thank you so much. I'll have a look at this solution and then I'll get back to you later.
    – jl001
    Nov 2, 2020 at 14:28
  • I'm not quite sure I understand what you mean. Do you mean to set up individual WordPress on different subdomains, so each WordPress system does not share the core files? Or is it possible to use .htaccess so the URL shows a subdomain for each subsite? Multisite already points towards a subfolder, and it creates some new tables in the database but not for the _users and _usermeta.
    – jl001
    Nov 2, 2020 at 16:18
  • You can use the same installation and set WP_SITEURL dynamically. Multisite will very likely not work with separated user tables.
    – fuxia
    Nov 2, 2020 at 16:20
  • Thank you! In fact, I am currently working on it on localhost so I can't test out with subdomains. Moreover, I think this exceeds my competence.
    – jl001
    Nov 2, 2020 at 18:38

Your Answer

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

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