3

Pardon my ignorance but is what I'm trying to do even possible?

I have a WordPress network and have domain mapping setup. So the original was domainA.com/map and the new is domainB.com. Is there a way for me to keep both the old sub directory and new domain without redirects.

If not oh well.

Comments
  • 1
    redirect from old to new
  • 2
    @JohanO I did ask for methods outside of redirects. I know redirects would work fine but I'm just honoring there is another way
  • 4
    *Not a best practice*, but a workable option:

    1) Create a new site on the network with the domain that's replacing the old subdirectory.

    2) Create a custom plugin that looks like the following:

    if (get_current_blog_id() == $domain_site_id) {

    switch_to_blog($subdir_site_id);

    }

    You probably don't need to hook it to anything; just let it run immediately as the plugin loads. Otherwise, you can hook it to 'plugins_loaded' to be safe.

    3) Make sure that both sites have all the same plugins active, so that any required functions will be available (*very important*).

    Based on my experience, that should get what you're looking for.

    ...Yes, I've spent *far* too much time hacking around in WP Multisite...
  • 1
    @ThatDannyBoy Ouch didnt read the specs good enough... well I guess you just have to resort to good old redirecting hhen ;-)
  • 3
    @Kaji Extending on this, you could actually probably also add another line inside the if that looks up $subdir_site_id's 'active_plugins' options and copies it over to $domain_site_id's 'active_plugins' option. It may fall out of sync for one load cycle, but if you refresh the site yourself after a plugin change, it should right the ship.

    Naturally, you can also switch the positions of the two site IDs if you prefer the domain to be the primary instead of the subdirectory.

    One drawback that I just realized is that permalinks would be generated based on the primary site using this method, but you can add a filter to 'the_permalink' and other functions to work around that. Or better, filter the 'url' and 'home' options so that they return the right site's information. Just restore_current_blog(), retrieve the *proper* information, then switch_to_blog() again. And unhook/restore the action in the middle so you don't get an endless loop.
  • 2
    @Kaji you're hurting my brain so I'm just gonna stick with subdomains and cname records instead. Fuck of sub directories.
  • 2
    @ThatDannyBoy Decided to take a stab at working it out since I'm self-employed and have nothing better to do at the moment. The current version is creating an infinite loop, unfortunately, however it is grabbing the data properly from the target site. Still need to see about adding a permalink filter to ensure the proper URL gets echoed, but getting options to work right takes priority.

    Here's the link, if you're curious: https://github.com/Kaji01/...

    If nothing else, hopefully it'll cure a bit of the head spinning...
Add Comment