Problem with Links after switch_to_blog()

Hello,

it looks like the Domain Mapping Plugin does not load when there are no mappings set up for the current blog.
The problem with this behaviour is that you get wrong permalinks after switching with switch_to_blog() to a blog with mappings set up.

Example:
Blog ID: 1, Main URL: http://www.example.com, Mapping: none
Blog ID: 2, Main URL: another.example.com, Mapping: http://www.another-example.com
If you now open http://www.example.com and you use the following code get_permalink() returns the URL with another.example.com instead of http://www.another-example.com.

switch_to_blog(2);
echo get_permalink();
restore_current_blog();

I temporary fixed this issue by inserting a row into the wp_domain_mapping table manually via phpMyAdmin and mapping the domain onto itself. (see screenshot)
This forces the Domain Mapping plugin to load and the above code works correctly.

Please fix this issue by hooking into switch_to_blog() and loading the plugin if needed. Another solution would be to give the user a option to force loading the plugin also if there is no mapping for the current blog.

Best regards,
Stefan Reisinger <stefan.reisinger@loremipsum.at>
Lorem Ipsum web.solutions GmbH