Site and User Registration on a Subdomain

I'm wanting my users for the entire network to register and create new sites from a subdomain, as opposed to, the root.

I should note, BuddyPress is only installed on the subdomain, which is part of why I'm directing network wide user registration and site creation to that specific domain.

The issue I'm experiencing in using this setup, is that the new sites that are created, become a subdomain of the subdomain "usersite.subdomain.mysite.com," when what I want is "usersite.mysite.com."

Does anyone have any insight as to how I might achieve this desired result? I'd greatly appreciate it.

I thought the multi-domains plugin might do the trick, but at the same time, it seems redundant adding a wildcard to the wildcard that already exists, and I'm not even sure if that would work.

Also, in the BuddyPress register.php file I thought I might find some insight there, but it seems to treat the home_url as the subdomain where it is installed.

<?php echo home_url( '/' ); ?> <input type="text" name="signup_blog_url" id="signup_blog_url" value="<?php bp_signup_blog_url_value(); ?>" />
							<?php endif; ?>

Thanks in advance for anyone that has anything to share.

  • Adam Czajczyk

    Hello Stephen,

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

    I believe we might be able to find some solution to this but I'd like to find out a bit more about your setup.

    The default scenario is that there's a main site and site creation is conducted from the main site. WordPress builds a sub-site address (regardless whether it's a sub-domain or a sub-folder) based on a "main domain" which, again by default, is the address of the main site.

    Then, if the "main site" is switched to sub-site - so the main site of the network becomes e.g. subsite.maindomain.com - WP treats its address as a base and will create sub-domains/sub-folders of it.

    I think that could be changed by hooking up to the "wpmu_new_blog" action:

    https://codex.wordpress.org/Plugin_API/Action_Reference/wpmu_new_blog

    That action could be used to alter the domain for a new blog, probably with some additional code.

    However, I'm not sure if this is exactly the case here so could you please shed some light on how did you move site registration to the sub-site? Are there any additional plugins handling user registration/site creation? Is there any custom code added to the site related to this?

    Let me know please.

    Best regards,
    Adam

  • Stephen

    Hi Adam,

    I really appreciate the quick response. You've identified exactly what's going on.

    There isn't anything special going on behind the scenes. I have Pro Sites setup, which is the only thing that might be unusual about this setup, apart from that, I've simply setup the user registration process through the subdomain because it's where BuddyPress is installed and I'd like my members to not only be able to be registered through BP, but also, be able to create their own site.

    The only additional code I'm running that has anything to do with registration was a little custom force https during sign up:

    <?php
    	function wpmu_5433_update_blog_url( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
    		update_blog_option($blog_id = $blog_id, $key = 'siteurl', $value = 'https://' . $domain);
    		update_blog_option($blog_id = $blog_id, $key = 'home', $value = 'https://' . $domain);
    	}
    	add_action( 'wpmu_new_blog', 'wpmu_5433_update_blog_url', 10, 6);

    In looking at that now, it's likely redundant since the entire network is forced https now anyway.

    If you had a solution here, I couldn't begin to express my gratitude. I suspected the behaviour you mentioned above, but I still find it a bit perplexing to sidestep.

    If it's of any help:

    Main Site: https://noyearslost.com

    Registration Site: https://tribe.noyearslost.com

    Registration Form: https://tribe.noyearslost.com/register/

    Thanks,

    Stephen

  • Predrag Dubajic

    Hi Stephen,

    Thanks for the additional info however I'm afraid that Pro Sites doesn't have an option to use registration form on a subsite.

    Change like this would require code editing in plugin files directly and some extensive testing to confirm everything works with such modifications.
    Unfortunately we currently don't have enough manpower to assist with such complex code changes and if you need to customize this then you can post a job in our job board where you can hire a developer to assist further:
    http://premium.wpmudev.org/wpmu-jobs/
    Please note that, no WPMU official staff members are allowed to work in the job board.

    Best regards,
    Predrag

  • Stephen

    Hi Predrag,

    Thanks for jumping in.

    I'm not using Pro Sites for the registration process. At the time of registering, if they choose to have a site, they have a free trial period. As you know, the ability to upgrade is on their dashboard, and if they choose to do so, they are then sent to the main site to finish that process.

    This flow currently works, the only thing is that new sites created on the network are "usersite.subdomain.mysite.com" and this isn't what I'm after.

    With regards to Pro Sites, the only thing I'm unhappy with and probably will have someone clean up a bit or do myself is the checkout form. It isn't exactly responsive, nor modern looking enough in my humble opinion.

    What I'd like altered in the current setup is for new users signing up from the subdomain to get a new subdomain on the main site and not the subdomain, so "usersite.mysite.com." If it is in fact Pro Sites that causes this, it would be great to know, but I don't believe that's the case.

    I think as Adam noted, it has more to do with WP treating the subdomain as the base, and so, how can we overcome or sidestep that?

    I appreciate your feedback. Please let me know if any of that is wrong or if you have further thoughts on the matter.

    Thanks,

    Stephen

  • Adam Czajczyk

    Hello Stephen!

    It seems like in this particular case that'd be indeed more of a WP issue rather then Pro Sites. My colleague Predrag's got a point about Pro Sites not being designed for working anywhere outside the main domain so that's something that should be taken into account but if you're not using it for a registration but only for upgrade - that should be fine.

    Therefore, the way to go would be the "wpmu_new_blog" action hook that I mentioned before. At the bottom of the page there's an example of how to use it. I think that shows the idea well. A "pseudo-code" that could work would be like

    <?php 
    
    function my_fix_new_blog_domain($blog_id, $user_id, $domain, $path, $site_id, $meta) {
    $domain = "mynewsite.maindomain.com";
    }
    add_action( 'wpmu_new_blog', 'my_fix_new_blog_domain', 10, 6);

    Hopefully that will help you get in a right direction. It's a bit outside of the scope of this forum to provide custom solution so you might need to ask on "Jobs&Pros" job board in case you needed an "end-solution" developed tho:

    https://premium.wpmudev.org/wordpress-development/

    Best regards,
    Adam

  • Stephen

    Hi guys,

    So a bit of an update. Multi-Domains worked for me in the manner I had hoped, all new sites created through the registration on my subdomain are now usersite.mysite.com.

    That being said, it resulted in another unique issue as might be expected by pushing these plugins to their limit...

    I also use New Blog Templates during sign up, and under this new configuration, newly created sites, fail to properly bring some of the media over with it. Initially I had thought it might be a database error, but the more I look at it, I can still add new media and so it might be a multiple redirect issue.

    Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404)

    Any thoughts on this? Should I open a new thread pertaining to New Blog Templates? As always, greatly appreciate your help, especially since I'm not exactly using these plugins in the manner they were built to be used.

  • Adam Czajczyk

    Hello Stephen!

    I suppose New Blog Templates might also be a bit "fooled" by that non-standard setup and the way new blogs are created, resulting in paths/URLs being broken. That would need to be investigated though so yes, it would be great if you could start a separate thread about it:

    https://premium.wpmudev.org/forums/#question

    I think it would be helpful if you could also mention this thread and changed made to your configuration in that new ticket, so the support person that picks it up would be aware of customization made to the site

    Best regards,
    Adam