The Configuration and Options System is responsible for managing all plugin settings and translation relationship data. It provides a hierarchical options architecture that adapts to different WordPress content types (posts, taxonomies, archives) using a factory pattern, and stores configuration both globally (per-blog settings) and per-content-item (translation links). This system encompasses the MslsOptions
base class and its specialized subclasses, the MslsAdmin
settings interface, and the underlying WordPress options API integration.
For information about how these options are used during frontend rendering, see Language Switcher Output. For details on content linking workflows that store translation relationships in these options, see Content Management.
The plugin uses an inheritance-based architecture where MslsOptions
serves as the abstract base class, with specialized subclasses handling different WordPress content types. Each subclass defines its own storage pattern through the SEPARATOR
constant and implements context-specific URL generation logic.
Sources: includes/MslsOptions.php1-431 includes/MslsOptionsPost.php1-57 includes/MslsOptionsTax.php1-133 includes/MslsOptionsQuery.php1-86 includes/MslsOptionsTaxTerm.php1-75
Each options class constructs its WordPress option name by combining the PREFIX
, SEPARATOR
, and constructor arguments:
Class | Separator | Example Option Name | Purpose |
---|---|---|---|
MslsOptions | "" | msls | Global plugin settings |
MslsOptionsPost | "_" | msls_123 | Post ID 123 translation links |
MslsOptionsTax | "_term_" | msls_term_45 | Term ID 45 translation links |
MslsOptionsQuery | "" | msls | Archive page queries |
The construction logic is implemented in includes/MslsOptions.php143-145:
Sources: includes/MslsOptions.php143-145 includes/MslsOptionsPost.php12 includes/MslsOptionsTax.php12
The plugin uses a factory pattern to instantiate the appropriate options class based on the current WordPress context. The MslsOptions::create()
method detects whether the request is for the admin interface or frontend, and which content type is being displayed.
Sources: includes/MslsOptions.php81-105 includes/MslsOptionsTax.php24-40 includes/MslsOptionsQuery.php44-64
The factory uses static helper methods to determine the page context:
Method | WordPress Functions Used | Returns True For |
---|---|---|
is_main_page() | is_front_page() , is_search() , is_404() | Homepage, search results, 404 pages |
is_tax_page() | is_category() , is_tag() , is_tax() | Category, tag, custom taxonomy archives |
is_query_page() | is_date() , is_author() , is_post_type_archive() | Date archives, author archives, CPT archives |
Sources: includes/MslsOptions.php112-132
The MslsOptionsTax::create()
method further refines taxonomy option creation based on the specific taxonomy type:
Sources: includes/MslsOptionsTax.php24-61
Options are stored in the WordPress wp_options
table using the WordPress Options API. The plugin uses two storage patterns: global settings (one record per blog) and per-content-item settings (one record per post/term).
Sources: includes/MslsOptions.php39-53 includes/MslsOptionsPost.php17 includes/MslsOptionsTax.php17
The MslsOptions
class provides persistence methods that interact with the WordPress Options API:
Method | Operations | WordPress Functions Used |
---|---|---|
save($arr) | Delete existing, set new data, add to database | delete_option() , add_option() |
delete() | Reset internal state, remove from database | delete_option() |
set($arr) | Validate and populate internal properties | N/A (internal) |
Implementation in includes/MslsOptions.php168-183:
Sources: includes/MslsOptions.php168-183
The autoload
property determines whether WordPress loads the option on every page load:
MslsOptions
): autoload = true
- Loaded on every request for quick accessMslsOptionsPost
): autoload = false
- Only loaded when neededMslsOptionsTax
): autoload = false
- Only loaded when neededSources: includes/MslsOptions.php53 includes/MslsOptionsPost.php17 includes/MslsOptionsTax.php17
The MslsAdmin
class provides the WordPress admin interface for configuring plugin settings. It organizes settings into four sections: Language Settings, Main Settings, Advanced Settings, and Rewrites Settings.
Sources: includes/MslsAdmin.php34-59 includes/MslsAdmin.php204-230
The admin interface is divided into four main sections, each with specific configuration fields:
Field ID | Label | Input Type | Description |
---|---|---|---|
blog_language | Blog Language | Select | WordPress language (WPLANG option) |
Implementation: includes/MslsAdmin.php239-243 includes/MslsAdmin.php336-342
Field ID | Label | Input Type | Property Type | Description |
---|---|---|---|---|
display | Display | Select | int | Flag/text display mode (see MslsLink types) |
admin_display | Admin Display | Select | string | Admin icon type: 'flag' or 'label' |
sort_by_description | Sort languages | Checkbox | bool | Sort by description vs. language code |
output_current_blog | Current language link | Checkbox | bool | Include current blog in output |
only_with_translation | Translation links | Checkbox | bool | Show only languages with translations |
description | Description | Text | string | Blog description override |
before_output | Text/HTML before the list | Text | string | HTML/text prefix for output |
after_output | Text/HTML after the list | Text | string | HTML/text suffix for output |
before_item | Text/HTML before each item | Text | string | HTML/text prefix per item |
after_item | Text/HTML after each item | Text | string | HTML/text suffix per item |
content_filter | Available translations hint | Checkbox | bool | Add translation hints to content |
content_priority | Hint priority | Select | int | Filter priority (1-100) |
Implementation: includes/MslsAdmin.php252-269 includes/MslsAdmin.php87-121
Field ID | Label | Input Type | Property Type | Description |
---|---|---|---|---|
activate_autocomplete | Autocomplete | Checkbox | bool | Enable AJAX autocomplete inputs |
image_url | Custom URL for flag-images | Text | string | Custom flag image directory URL |
reference_user | Reference user | Select | int | User whose blogs are included |
exclude_current_blog | Exclude blog | Checkbox | bool | Hide this blog from output |
activate_content_import | Content import | Checkbox | bool | Enable content import functionality |
Implementation: includes/MslsAdmin.php278-288 includes/MslsAdmin.php371-393
This section appears only when permalinks are enabled ($wp_rewrite->using_permalinks()
). It dynamically generates fields for all public post types:
Field Pattern | Label Pattern | Input Type | Description |
---|---|---|---|
rewrite_{post_type} | {PostType} Slug | Text | Custom slug for post type URLs |
Implementation: includes/MslsAdmin.php213-216 includes/MslsAdmin.php297-307 includes/MslsAdmin.php426-432
Sources: includes/MslsAdmin.php204-332
Sources: includes/MslsAdmin.php156-176 includes/MslsAdmin.php87-121 includes/MslsAdmin.php336-432
When the settings form is submitted, WordPress calls the validate()
method before saving:
Key validation logic in includes/MslsAdmin.php441-457:
The set_blog_language()
method handles the special case of updating the WordPress language setting in includes/MslsAdmin.php466-474:
Sources: includes/MslsAdmin.php441-474
Each options subclass serves a specific purpose in the plugin's architecture. Understanding when each type is used is crucial for working with the system.
The base MslsOptions
class stores global, per-blog configuration accessible throughout the plugin via the msls_options()
helper function.
Common Access Pattern:
Properties Stored:
display
, admin_display
)before_output
, after_output
, before_item
, after_item
)activate_autocomplete
, activate_content_import
, content_filter
)description
, reference_user
)exclude_current_blog
, only_with_translation
, sort_by_description
)Sources: includes/MslsOptions.php29-430
Stores translation relationships for individual posts and pages. Each post has its own option record mapping language codes to post IDs.
Storage Format:
Option Name: msls_123 Option Value: ['de_DE' => 456, 'fr_FR' => 789]
This indicates that post ID 123 (English) has German translation as post ID 456 and French translation as post ID 789.
Key Methods:
Method | Returns | Description |
---|---|---|
get_postlink($language) | string | Permalink to translated post (checks publish status) |
get_current_link() | string | Permalink to current post |
Sources: includes/MslsOptionsPost.php1-57
Stores translation relationships for taxonomy terms (categories, tags, custom taxonomies). Uses the _term_
separator to distinguish from post options.
Storage Format:
Option Name: msls_term_45 Option Value: ['de_DE' => 67, 'fr_FR' => 89]
Specialized Subclasses:
MslsOptionsTaxTerm
: For post tags, handles tag_base
rewrite rulesMslsOptionsTaxTermCategory
: For categories, handles category_base
rewrite rulesThe subclasses ensure correct URL generation when WordPress has custom taxonomy base slugs configured.
Sources: includes/MslsOptionsTax.php1-133 includes/MslsOptionsTaxTerm.php1-75
Handles date archives, author archives, and custom post type archives. Unlike post and taxonomy options, these don't store translation mappings—they dynamically determine if content exists in each language.
Subclass Hierarchy:
Each subclass implements get_params()
to return the relevant query variables:
The MslsSqlCacher
is injected to optimize database queries when checking for post existence in date ranges.
Sources: includes/MslsOptionsQuery.php1-86
The plugin provides several mechanisms for accessing options, depending on the context and what type of option is needed.
Two primary helper functions provide access to options:
1. msls_options()
- Returns global settings
Located in includes/msls-api.php this function returns the shared MslsOptions
instance containing per-blog configuration:
Used throughout the plugin for accessing display preferences, feature flags, and configuration.
2. MslsOptions::create($id)
- Factory for context-specific options
Creates the appropriate options subclass based on current WordPress context (frontend) or specified content ID (admin):
Sources: includes/MslsOptions.php81-105
Many plugin classes receive options via constructor injection, allowing for better testability and decoupling:
Example from includes/MslsAdmin.php34-39:
Sources: includes/MslsAdmin.php34-39 includes/MslsOutput.php12-18 includes/MslsPlugin.php27-29
Options classes extend MslsGetSet
, which provides magic __get()
and __set()
methods for property access. This allows clean, object-property-style access to configuration:
The MslsGetSet
base class in includes/MslsGetSet.php provides the implementation that handles type coercion and isset()
checks.
Sources: includes/MslsOptions.php29 includes/MslsGetSet.php
During frontend rendering, MslsOutput
uses options to determine display format and fetch translation links:
Sources: includes/MslsOutput.php34-90
In the admin interface, MslsMetaBox
and MslsPostTag
use options to display existing translation links and save new relationships:
Sources: includes/MslsMetaBox.php includes/MslsMain.php
The options system is responsible for generating correct permalinks to translated content across different blog contexts. This involves WordPress's multisite context-switching mechanism and custom rewrite rule handling.
Sources: includes/MslsOptions.php215-231 includes/MslsOptionsPost.php26-46 includes/MslsOptionsTax.php87-97
Subdomain multisite installations can have a "blog slug problem" where the main site's permalink structure includes a base path (e.g., /blog/
) that needs special handling. The check_for_blog_slug()
filter corrects URLs for this edge case:
Implementation in includes/MslsOptions.php395-420:
Sources: includes/MslsOptions.php395-420
Taxonomy options handle WordPress rewrite base slugs through the with_front
property and base checking:
Property | Type | Purpose |
---|---|---|
with_front | ?bool | Whether taxonomy uses permalink front base |
BASE_OPTION | string | WordPress option name for taxonomy base |
BASE_DEFINED | string | Default taxonomy base slug |
Example: Tag Base Handling in includes/MslsOptionsTaxTerm.php37-53:
This ensures that custom tag/category base slugs are correctly applied when generating links across blogs.
Sources: includes/MslsOptionsTaxTerm.php23-73 includes/MslsOptionsTax.php55-61
This diagram illustrates how configuration data flows from user input through validation, storage, and retrieval:
Sources: includes/MslsAdmin.php441-474 includes/MslsOptions.php137-141 includes/MslsOptions.php190-213
The Configuration and Options System integrates with several other plugin subsystems:
MslsBlogCollection
uses options to determine blog filtering and ordering:
Sources: includes/MslsBlogCollection.php50-95
MslsOutput
retrieves display configuration and formatting from global options:
Sources: includes/MslsOutput.php34-90 includes/MslsOutput.php152-172
MslsAdminIcon
uses the icon type setting to determine whether to show flags or labels:
Sources: includes/MslsAdminIcon.php107-111 includes/MslsOptions.php427-429
The content import system checks the activation flag before enabling import functionality:
Sources: includes/MslsAdmin.php99-101
This Configuration and Options System provides the foundation for the entire plugin, enabling per-blog customization while maintaining consistent behavior across the multisite network. The factory pattern ensures the correct option type is always used, while the persistence layer reliably stores both global settings and per-content translation mappings.
Refresh this wiki