Support and knowledge base site for subsite admins

I want to create a support site (similar to the Edublogs Help site) or membership area on my main site that can be accessed by subsite admins only. Rather than force them to create a separate login for this site I'd like them to have access to it as soon as they create their site. Also I'd like them to have a subscriber role for this site. I could do this easily if the content is unprotected but I don't want it available to the general public.

I've been trying to figure out how to do this with Membership 2 Pro and User Synchronization but haven't been able to make it work the way I want.

I've been using your search to find ans answer but haven't found anything that fits.

Is this possible and if so do you already have a post or how-to article on how to set it up? Or am I just missing something.

Thanks for your help.

Bob

  • Adam Czajczyk

    Hello Bob,

    I hope you're well today and thank you for your question!

    Assuming that you protect your content (e.g. your support pages) with Membership 2 Pro you'll want to achieve two goals here:

    1. Automatically make admins of sub-site subscribers of your main site
    2. Automatically assign them selected membership on the main site.

    This could be accomplished with a little bit of additional code. Take a look below please:

    <?php
    add_action( 'user_register', 'assign_membership_on_register', 10, 1 );
    function assign_membership_on_register( $user_id ) {
        add_user_to_blog( 1, $user_id, 'subscriber');
        switch_to_blog( 1 );
        $membership_id = 1343;
        $member = MS_Factory::load( 'MS_Model_Member', $user_id );
        $subscription = $member->add_membership( $membership_id );
    
        if ( $member->has_membership() ) {
            $member->is_member = true;
        } else {
            $member->is_member = false;
        }
        $member->save();
        restore_current_blog();
    }

    When somebody creates his/her own site in your network, that person will be automatically added as a subscriber user to your main site and assigned selected membership on your main site. Thus, will have access to content protected on you main site with Membership 2.

    To apply the code to your setup please follow these steps:

    - On your main site's dashboard "Membership -> Memberships" page check an ID of the membership you'd like to grant to those users
    - replace "1343" value with that ID in this line of the code:

    $membership_id = 1343;

    - create an empty file with .php extension
    - paste the code there and save file
    - access your site via FTP and go to "/wp-content" folder
    - if there's no "mu-plugins" folder inside, please create it
    - upload the file to "/wp-content/mu-plugins" folder

    That's it. The plugin will be automatically enabled and it should handle the scenario "in background" so from now on every admin of any new sub-site on your network will automatically become subscriber user of main site and a member of selected membership.

    I hope that helps!
    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.