Menu

Configuration and Options System

Relevant source files

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.


Options Class Hierarchy

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.

Class Structure and Responsibilities

Sources: includes/MslsOptions.php1-431 includes/MslsOptionsPost.php1-57 includes/MslsOptionsTax.php1-133 includes/MslsOptionsQuery.php1-86 includes/MslsOptionsTaxTerm.php1-75

Option Name Construction

Each options class constructs its WordPress option name by combining the PREFIX, SEPARATOR, and constructor arguments:

ClassSeparatorExample Option NamePurpose
MslsOptions""mslsGlobal plugin settings
MslsOptionsPost"_"msls_123Post ID 123 translation links
MslsOptionsTax"_term_"msls_term_45Term ID 45 translation links
MslsOptionsQuery""mslsArchive page queries

The construction logic is implemented in includes/MslsOptions.php143-145:

Sources: includes/MslsOptions.php143-145 includes/MslsOptionsPost.php12 includes/MslsOptionsTax.php12


Factory Pattern and Context Detection

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.

Factory Logic Flow

Sources: includes/MslsOptions.php81-105 includes/MslsOptionsTax.php24-40 includes/MslsOptionsQuery.php44-64

Context Detection Methods

The factory uses static helper methods to determine the page context:

MethodWordPress Functions UsedReturns 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

Taxonomy Options Factory

The MslsOptionsTax::create() method further refines taxonomy option creation based on the specific taxonomy type:

Sources: includes/MslsOptionsTax.php24-61


Storage and Persistence

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).

Storage Patterns

Sources: includes/MslsOptions.php39-53 includes/MslsOptionsPost.php17 includes/MslsOptionsTax.php17

Save and Delete Operations

The MslsOptions class provides persistence methods that interact with the WordPress Options API:

MethodOperationsWordPress Functions Used
save($arr)Delete existing, set new data, add to databasedelete_option(), add_option()
delete()Reset internal state, remove from databasedelete_option()
set($arr)Validate and populate internal propertiesN/A (internal)

Implementation in includes/MslsOptions.php168-183:

Sources: includes/MslsOptions.php168-183

Autoload Configuration

The autoload property determines whether WordPress loads the option on every page load:

  • Global settings (MslsOptions): autoload = true - Loaded on every request for quick access
  • Post options (MslsOptionsPost): autoload = false - Only loaded when needed
  • Taxonomy options (MslsOptionsTax): autoload = false - Only loaded when needed

Sources: includes/MslsOptions.php53 includes/MslsOptionsPost.php17 includes/MslsOptionsTax.php17


Settings Configuration Interface

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.

Settings Page Registration

Sources: includes/MslsAdmin.php34-59 includes/MslsAdmin.php204-230

Settings Sections and Fields

The admin interface is divided into four main sections, each with specific configuration fields:

1. Language Section

Field IDLabelInput TypeDescription
blog_languageBlog LanguageSelectWordPress language (WPLANG option)

Implementation: includes/MslsAdmin.php239-243 includes/MslsAdmin.php336-342

2. Main Section

Field IDLabelInput TypeProperty TypeDescription
displayDisplaySelectintFlag/text display mode (see MslsLink types)
admin_displayAdmin DisplaySelectstringAdmin icon type: 'flag' or 'label'
sort_by_descriptionSort languagesCheckboxboolSort by description vs. language code
output_current_blogCurrent language linkCheckboxboolInclude current blog in output
only_with_translationTranslation linksCheckboxboolShow only languages with translations
descriptionDescriptionTextstringBlog description override
before_outputText/HTML before the listTextstringHTML/text prefix for output
after_outputText/HTML after the listTextstringHTML/text suffix for output
before_itemText/HTML before each itemTextstringHTML/text prefix per item
after_itemText/HTML after each itemTextstringHTML/text suffix per item
content_filterAvailable translations hintCheckboxboolAdd translation hints to content
content_priorityHint prioritySelectintFilter priority (1-100)

Implementation: includes/MslsAdmin.php252-269 includes/MslsAdmin.php87-121

3. Advanced Section

Field IDLabelInput TypeProperty TypeDescription
activate_autocompleteAutocompleteCheckboxboolEnable AJAX autocomplete inputs
image_urlCustom URL for flag-imagesTextstringCustom flag image directory URL
reference_userReference userSelectintUser whose blogs are included
exclude_current_blogExclude blogCheckboxboolHide this blog from output
activate_content_importContent importCheckboxboolEnable content import functionality

Implementation: includes/MslsAdmin.php278-288 includes/MslsAdmin.php371-393

4. Rewrites Section (Conditional)

This section appears only when permalinks are enabled ($wp_rewrite->using_permalinks()). It dynamically generates fields for all public post types:

Field PatternLabel PatternInput TypeDescription
rewrite_{post_type}{PostType} SlugTextCustom slug for post type URLs

Implementation: includes/MslsAdmin.php213-216 includes/MslsAdmin.php297-307 includes/MslsAdmin.php426-432

Sources: includes/MslsAdmin.php204-332

Settings Form Rendering Flow

Sources: includes/MslsAdmin.php156-176 includes/MslsAdmin.php87-121 includes/MslsAdmin.php336-432

Settings Validation and Persistence

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


Option Types and Their Usage

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.

Global Settings (MslsOptions)

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 preferences (display, admin_display)
  • Output formatting (before_output, after_output, before_item, after_item)
  • Feature toggles (activate_autocomplete, activate_content_import, content_filter)
  • Blog metadata (description, reference_user)
  • Behavior flags (exclude_current_blog, only_with_translation, sort_by_description)

Sources: includes/MslsOptions.php29-430

Post/Page Options (MslsOptionsPost)

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:

MethodReturnsDescription
get_postlink($language)stringPermalink to translated post (checks publish status)
get_current_link()stringPermalink to current post

Sources: includes/MslsOptionsPost.php1-57

Taxonomy Options (MslsOptionsTax)

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 rules
  • MslsOptionsTaxTermCategory: For categories, handles category_base rewrite rules

The subclasses ensure correct URL generation when WordPress has custom taxonomy base slugs configured.

Sources: includes/MslsOptionsTax.php1-133 includes/MslsOptionsTaxTerm.php1-75

Archive Options (MslsOptionsQuery)

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


Accessing Options Throughout the Plugin

The plugin provides several mechanisms for accessing options, depending on the context and what type of option is needed.

Helper Functions

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

Dependency Injection Pattern

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

Property Access via Magic Methods

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

Options in Rendering Context

During frontend rendering, MslsOutput uses options to determine display format and fetch translation links:

Sources: includes/MslsOutput.php34-90

Options in Admin Context

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

Blog Slug Handling

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

Rewrite Rule Integration

Taxonomy options handle WordPress rewrite base slugs through the with_front property and base checking:

PropertyTypePurpose
with_front?boolWhether taxonomy uses permalink front base
BASE_OPTIONstringWordPress option name for taxonomy base
BASE_DEFINEDstringDefault 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


Configuration Data Flow

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


System Integration Points

The Configuration and Options System integrates with several other plugin subsystems:

Integration with Blog Collection

MslsBlogCollection uses options to determine blog filtering and ordering:

Sources: includes/MslsBlogCollection.php50-95

Integration with Output Rendering

MslsOutput retrieves display configuration and formatting from global options:

Sources: includes/MslsOutput.php34-90 includes/MslsOutput.php152-172

Integration with Admin Icons

MslsAdminIcon uses the icon type setting to determine whether to show flags or labels:

Sources: includes/MslsAdminIcon.php107-111 includes/MslsOptions.php427-429

Integration with Content Import

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.