WordPress Multisite and Separate Domains

In some previous posts, I have talked about getting WordPress Multisite to work across separate domains instead of using subdomains as it was intended. It works with some manual wrangling, but the sites didn’t appear in the Super Admin section that multisite adds to the back end. I decided to try and fix that problem.

The main issue here comes from the table wp_blogs. In that table there are blog ids and site ids. This points to the intent to allow separate domains and separate subdomains in the same install. The problem is that functionality is intended more for a hosted site solution and the separate sites are protected from one another. To make separate domains works, the blogs need to have different site_ids. This is the crux of the problem as the admin takes the current site_id into account when making the blog list in the super admin. To fix the problem, I removed the reference to site_id from the queries.

in wp-admin/ms-sites.php there are several queries that populate the multisite admin and some code to protect sites from one another. Since my files are edited, I cannot give accurate line numbers, so please bare with me. Searching for site_id, you will find the following lines:

if ( $details->site_id != $wpdb->siteid )
  wp_die( __( 'You do not have permission to access this page.' ) );

These lines get commented out. Next, you should find:

$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";

I replace this with:

$query = "SELECT * FROM {$wpdb->blogs}";

Then comes:

$query = "SELECT *
FROM {$wpdb->blogs}, {$wpdb->registration_log}
WHERE site_id = '{$wpdb->siteid}'
AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
AND {$wpdb->registration_log}.IP LIKE ('%{$like_s}%')";

replaced by:

$query = "SELECT *
FROM {$wpdb->blogs}, {$wpdb->registration_log}
WHERE {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
AND {$wpdb->registration_log}.IP LIKE ('%{$like_s}%')";

After making these edits, all my sites appeared on the super admin list and so far I have not found any other issues. Use these changes at your own risk. This has not been heavily tested. As time goes on, if I find more issues, I will pass on the information. These modifications will be used on some rather large sites once all my conversion is done, so the testing will happen. I will keep you informed.

A very small bit of styling

I’ve taken some time to make some small updates to the scheme on this site. I this is the same base 2010 theme for WordPress with a few small adjustments. First thing was the addition of the ad at the top of the screen. The ad plugin I use does not support that placement directly. I had to edit the header.php template to add that placement.

Along with that placement, I made some minor tweeks to the page as a whole, making the site title white on black and changing margins to my liking. Perhaps the most interesting thing I did was change the title fonts on the page. I used a Google font for this.

Part of my motivation for this was to try it out. I have not used Google fonts before and wanted to see what it took to implement them and what other consideration might arise. I chose the font called Philosopher. Implementation was very easy, add a link tag to the header and then set the font-family in the CSS as usual. That was different was how the font presented itself. The font seemed to sit higher on the line that a “normal” font would. Since I haven’t played with other fonts, I don’t know if this is a universal issue with Google fonts, or specific to Philosopher. For the main site title, I added special margins to make the font sit on the line the way I wanted it to. Something to consider for certain if you plan on using Google fonts. It may be less of an issue if all your fonts are Google fonts, but when mixing, look for the different baselines.

Learning WordPress

With the data move complete, the next step will be theme creation. I am currently reading about WordPress in the book Smashing WordPress: Beyond the Blog from Smashing Magazine. I will post a full review later but so far the book has been good, though at times written a bit below my level (too simplistic). The information is good and that is what’s important.

Data move complete

All the lingering problems have been corrected and I have successfully brought all the data necessary from Article Manager (Artman) into WordPress. The date problem mentioned before was because Artman stored dates and Unix style timestamps and WordPress uses MySql datetime fields.

One odd point about the data move came from categories. First, I had issues as I was making the transition in improperly links category parents and children and linking categories to stories. The problem was I needed to use the term_id for the parent child relationships and the term_taxonomy_id for the post to category relationships. I had overlooked this initially.

The second odd thing with categories was sub-categories not showing up in the back end when inserted directly into the database. I could insert a top level category with no problem. Child categories wouldn’t show up till I saved a category. Didn’t matter which category and I didn’t need to change anything, but the act of saving a category made the system catch up.

Mission mostly accomplished

Well, today I was able to load users, categories and stories from my old system into WordPress. The conversion is not without issues, but great progress has been made. Dates have not transitioned correctly. I have not taken all the steps to properly reference images used in the articles so they will appear in the Media Library. Still, this is good progress and I will push on in the coming days.

Migrating from one system to another

My next project involves moving some sites from a now defunct application called Article Manager by Interactive Tools to WordPress. Since this also involves a redesign of the site, there is no need to translate the templates. This will be a data transition only.

Article manager creates flat files from its data. It is not a “live” system like WordPress is. The good part about that is the low database utilization and very quick serving site as all you need is a quick web server. The down side comes from the very limited template language the system uses. There are no variables you can create, very little branch control, very little state you can check. It was quick and relatively simple but in the end too simple for our needs. Interactive Tools has moved on from that product to one they call CMS Builder.

Article Manager (Artman) contains all its data in four tables, one for the articles, one for categories, one for users and one for what it called publish rules. The publish rules are instructions to the system on how the create the flat files. Since those are not needed in WordPress, I can ignore that table. That leaves three.

The first I will convert is the user table. I choose that one because it is referenced from the other two via creator ids and such. Second, I will move the categories and third will be the articles themselves. This will be the most interesting one and will take the most manipulation. I’ll need to update the user ids and category ids. I will also have to decode the way Artman stores image references for articles. Instead of keeping the original link to the images the way WordPress does, Artman had a code system for placing images into the article.

Since I will be doing this conversion more than once, I plan to build a tool to do the job. In the end, I will be combining many sites into one WordPress multisite install.

Changing hosts and WP-United

Just a quick note on an issue that popped up for me when moving a WordPress / WP-United site to a new host. The move was done by the hosting company without the knowledge of the site and its databases. The WP-United / WordPress combination is somewhat specific, so I wouldn\’t have expected them to have much knowledge of it anyhow.

After moving all the data and the databases, a message that it could not connect to the database kept showing on the site. Going directly to the forums however worked. Within the PHPBB control panel, I then emptied the cache. After that, WordPress was able to function again.

HTML 5 possibilities

There are lots of HTML 5 demos out there, but this one is really interesting and innovative. The band Arcade Fire has created a semi-interactive music video using HTML 5, multiple windows, and Google maps. You enter your address and it searches Google maps for that address and includes maps and street view into the presentation. Very creative and technical. I will have to dig and see how it was done.

WordPress Multisite

For a potential project I currently have with WordPress, I need to figure out the multisite feature. With WordPress 3, multisite was included with the base install. It only requires a little configuration to get up and running.

The problem is, multisite doesn’t function quite the way I need for this project. Multisite is designed for use in subdomains or subdirectories. In my case, I need it to work with separate domains. There are a couple of ways to make this work. One is to hack things a bit and the other is to use domain mapping. Domain mapping can be expensive in terms of processor, and since these sites I need to implement are somewhat high volume I deceided to focus on the hacking option instead.

There are some directions here for getting multisite running on separate domains. These directions work, but pay careful attention and follow them completely. If you miss a step you may get unexpected results. I missed the step of inserting the new row into the wp_site table and this resulted with me being unable to log into the second site. Any attempt to log in would just throw you back to the login screen. Inserting that row fixed that problem for me.

There are some caveats to this solution. Under a normal subdomain install, you get a list of sites in the Super Admin panel at the top. With separate domains this list only includes the first site. Something similar happened with a plugin I needed too. I needed the ability to post from one site to another in the multisite install. ThreeWP Broadcast works for this, but under its panel there were no sites listed.

The solution lies in that new row added to wp_site. In that table, there is a blog id and a site id. I guessed that the lists were showing blogs within one certain site id. For the separate domains to work, they needed to have different site ids. I edited the plugin to remove its reference to site id and the other site showed up in its panel. Since that worked, I looked for references to site_id within WordPress files and adjusted them similarly.

Now it all works, mostly. The only thing that does not work as I wish is the Super Admin panel does not show in the admin of the second site. I keep referencing the second site, I only have two sites in multisite currently but I believe all subsequent sites will work the same way. I’d like the super admin panel to show for all super admins no matter which site they are logged in on. I haven’t looked into this too much yet as it would be nice but is not needed for the sites to function.

Now that multisite is working with domains, I have two other issues to work through for this project. The first will be bringing in data from a legacy system into WordPress. The second is integrating VBulletin into WordPress with multisite. Good times ahead!

Future project

With PHPBB integrated into WordPress and looking pretty good, then next challenge will be doing a similar integration with VBulletin. This plugin is supposed to do the job, but does not work with WordPress Multisite, which will likely be a requirement. This is just the initial investigation. Much more to look at.