The Multisite Language Switcher is a WordPress plugin that provides multilingual content management for WordPress multisite networks. This documentation covers the plugin's architecture, core components, administrative interfaces, content management systems, and frontend display mechanisms. The plugin enables site administrators to link content across different language versions of sites within a multisite network and provides various methods for displaying language switching options to end users.
For information about installation and basic setup, see Getting Started. For detailed development workflows and extending the plugin, see Development.
The plugin follows a layered architecture with clear separation of concerns. The system is organized into five primary layers:
The importance scores indicate the centrality and activity level of each component based on code change frequency and interconnections. The Core Layer handles plugin initialization and fundamental infrastructure. The Public API Layer provides developer-friendly interfaces. The Content Management Layer enables admin workflows. The URL Generation Layer creates correct cross-blog links. The Content Import Layer facilitates content duplication across language sites.
Sources: MultisiteLanguageSwitcher.php43-245 includes/MslsPlugin.php34-100 includes/MslsOptions.php29-145 includes/MslsBlogCollection.php10-96 includes/MslsOutput.php1-12
The plugin's core components interact through a registry pattern and factory methods for context-specific object creation:
The registry pattern (MslsRegistry
and MslsRegistryInstance
) provides singleton instances for major components. The factory pattern (MslsOptions::create()
) automatically selects the correct subclass based on context (post, taxonomy, or archive page). This architecture enables the plugin to handle different content types with specialized logic while maintaining a consistent API.
Sources: includes/MslsBlogCollection.php10-96 includes/MslsOptions.php81-105 includes/MslsOutput.php14-90 includes/MslsBlog.php40-144
The plugin discovers and manages blogs across the multisite network through MslsBlogCollection
, which filters blogs by language configuration and plugin activation status:
The collection filters blogs based on: (1) plugin activation status via is_plugin_active()
, (2) configuration status via get_blog_option(blog_id, 'msls')
, and (3) exclusion settings via the exclude_current_blog
option. The reference user pattern (configured in MslsAdmin
) determines which blogs are visible to the current user.
Sources: includes/MslsBlogCollection.php50-96 includes/MslsBlogCollection.php128-142 includes/MslsBlogCollection.php243-256 includes/MslsBlog.php40-47
The system provides two pathways for linking content across language sites: manual linking via the admin interface and automated linking via content import:
Both pathways converge on MslsOptionsPost::save()
, which stores language-to-post-ID mappings in the WordPress options table with the key pattern msls_{post_id}
. The manual linking path uses AJAX autocomplete (registered at wp_ajax_suggest_posts
) to search for existing posts. The import path uses ImportCoordinates
to define the source and destination, then creates bidirectional links via Relations::set()
.
Sources: includes/MslsMetaBox.php79-80 includes/ContentImport/Service.php includes/ContentImport/Relations.php includes/MslsOptionsPost.php includes/MslsMain.php
The plugin exposes several global functions for theme and plugin developers:
Function | Purpose | Return Type |
---|---|---|
get_the_msls($attr) | Get language switcher HTML | string |
the_msls($arr) | Output language switcher | void |
get_msls_flag_url($locale) | Get flag icon URL | string |
get_msls_blog_description($locale, $preset) | Get blog description | string |
get_msls_permalink($locale, $preset) | Get translation permalink | string |
msls_blog_collection() | Get blog collection instance | MslsBlogCollection |
msls_options() | Get options instance | MslsOptions |
Sources: MultisiteLanguageSwitcher.php57-183
The plugin bootstraps from MultisiteLanguageSwitcher.php1-246 which defines constants and triggers initialization:
Constants Defined:
Constant | Purpose | Example Value |
---|---|---|
MSLS_PLUGIN_VERSION | Version string for cache busting | '2.9.6' |
MSLS_PLUGIN_PATH | Plugin basename for WordPress | 'multisite-language-switcher/MultisiteLanguageSwitcher.php' |
MSLS_PLUGIN__FILE__ | Absolute file path | __FILE__ |
Global Functions Registered:
The plugin registers 16 global helper functions including the_msls()
, get_the_msls()
, msls_blog()
, msls_options()
, msls_blog_collection()
, and utility functions for retrieving permalinks, flag URLs, and blog descriptions. These functions provide the public API for theme and plugin developers.
Sources: MultisiteLanguageSwitcher.php43-245
A fundamental pattern in the plugin is multisite context switching, which enables the plugin to read and write data across different blogs in the network. This pattern is used throughout the codebase when generating URLs or accessing blog-specific data:
The pattern follows this sequence: (1) switch_to_blog($blog_id)
changes the global WordPress context, (2) operations execute in the remote blog's context, and (3) restore_current_blog()
returns to the original context. This is critical for accessing remote blog data while maintaining data isolation. Every use of switch_to_blog()
must be paired with restore_current_blog()
to prevent context corruption.
Sources: includes/MslsOutput.php42-64 includes/MslsBlog.php135-141
The plugin requires WordPress multisite functionality and performs validation during initialization:
If multisite is not active, the plugin displays an admin notice with setup instructions and does not initialize. The activation sequence is defined in MslsPlugin::init()
at includes/MslsPlugin.php34-100 which registers hooks conditionally based on is_multisite()
and is_admin()
checks.
Sources: includes/MslsPlugin.php34-100 MultisiteLanguageSwitcher.php43-245
The plugin architecture emphasizes modularity, performance through caching, and extensibility through WordPress hooks and filters. Each major subsystem operates independently while coordinating through the central registry and options systems.
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.