Multilingual WordPress Multisite Network

WordPress is hugely popular, powering over 23% of the entire internet today. As you can imagine, a good portion of these websites are not in English. Over the past few years I’ve had the opportunity to work on more multilingual sites in WordPress. One thing I have learned is that WordPress Multisite is a perfect fit for a network of multilingual sites. Each site in the network can be configured for a different language, making the administration much easier.

One of the big challenges I’ve faced is the relationship between the content across the language sites in a network. Imagine having an About page on your English site and an About page on your German site. Wouldn’t it be awesome if WordPress knew that these two pages were related? Well, now you can with an awesome plugin called Multilingual Press.

I had a chance to sit down with Caspar Hübinger at WordCamp London for a demo and I was blown away. Multilingual Press lets you create relationships between sites in your Multisite network, set a main language for each site, and start writing. When editing a piece of content connected to multiple languages, you can edit all of the language content on the same edit screen, as shown in the screenshot below. The content will then be updated in the appropriate language site in the network.

mlppro-edit-post

If you work with WordPress in different languages you need to check out Multilingual Press. It’s a multilingual game changer!

Detecting a Large Multisite Network in WordPress

If you have ever worked on a very large Multisite network in WordPress, you probably understand the challenges of working with large sets of data. WordPress contains a function to help you detect a large network, wp_is_large_network(). This function accepts a single parameter $using, which sets whether to count users or sites. If your network is either more than 10,000 users or more than 10,000 sites, the function will return true. Let’s look at an example:

<?php
if ( wp_is_large_network( 'users' ) ) {

    //this network has over 10,000 users

}elseif ( wp_is_large_network( 'sites' ) ) {

    //this network has over 10,000 sites

}
?>

This function is extremely handy if you are trying to work with large sets of data. When working with Multisite, and WordPress in general, you should always write code that can scale. You can also easily alter the large network criteria using the wp_is_large_network filter.

WordPress Multisite is an extremely powerful feature of WordPress. Understanding the tools available when working with Multisite will help you build amazing, and stable, WordPress networks.

How To: Create a Network Only Plugin in WordPress

If you’ve ever created a custom plugin in WordPress, you should be familiar with the standard plugin header code. The information set in your plugin header is displayed under the Plugins admin menu in WordPress shown below:

wordpress-plugin-header-example

There is a lesser known piece of information that can be defined in your plugin header that tells WordPress to only show your plugin on the WordPress Multisite Network Plugins page. This will hide your plugin from being displayed and activated at the site level in WordPress Multisite. To only allow your plugin to show at the Network Plugins level, simply add this one line to your plugin header code:

Network: true

Easy, right? Let’s look at an example comparing a standard plugin header with a network only plugin header.

Standard Plugin Header:

/*
Plugin Name: My Awesome Plugin
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: This is my extremely awesome WordPress plugin
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
*/

Network Only Plugin Header:

/*
Plugin Name: My Awesome Plugin
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: This is my extremely awesome WordPress plugin
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
Network: True
*/

Using this method you can be sure your WordPress plugin will only be network activated in Multisite.

How To: Add A Link to the WordPress Multisite Network Admin Sites List

The other day I was working on a plugin for a client when I needed to add a link to the WordPress Multisite Network Admin Sites list. This is the list of sites in your WordPress Multisite network. The links I am referring to are the action links that appear when you hover over a site in the list as shown below.

WordPress Multisite Network Sites ListTo add a link, or modify any of the existing action links, we’re going to use the manage_sites_action_links action filter in WordPress. This filter will allow us to modify the action links before they are displayed on the screen. This means you can add, or remove, any links you want.

Let’s look at the code:

add_filter( 'manage_sites_action_links', 'my_plugin_network_list_action', null, 2 );

function my_plugin_network_list_action( $actions, $blog_id ) {

    $actions = array_merge( $actions, array(
	'custom_link' => '<a href="'. network_admin_url( 'sites.php' ).'">My Custom Link</a>'
    ));

    return $actions;

}

First we call the manage_sites_action_links filter hook which executes our custom function my_plugin_network_list_action(). Our function accepts two parameters: The $actions array which contains all action links and the $blog_id which stores the site ID of the site we are hovering in the list.

To add a link we are going to use the PHP function array_merge() to merge our link into the array of existing links. In this example I added a link named “My Custom Link” which links to the Network Admin sites list. The final step is to return the $actions variable. Simple as that!

For more awesome WordPress plugin goodies check out my new book: Professional WordPress Plugin Development