Menu

Data Layer

Relevant source files

The Data Layer provides the foundation for storing, retrieving, and managing multilingual content relationships across WordPress multisite blogs. It consists of three primary subsystems:

  1. Options and URL Generation (8.1) - Hierarchy of MslsOptions subclasses that store language mappings and generate content-type-specific permalinks
  2. Content Type Management (8.2) - MslsContentTypes abstraction that handles WordPress post types and taxonomies with access control
  3. Data Utilities and Caching (8.3) - Helper classes (MslsLanguageArray, MslsGetSet, MslsJson) and the MslsSqlCacher performance layer

This page provides an architectural overview of how these systems interact. For admin configuration details, see Settings and Configuration Pages. For how data flows into frontend display, see Language Switcher Output.

Architecture Overview

The Data Layer coordinates three major subsystems that work together to manage multilingual content relationships:

Data Layer Component Diagram

Sources: includes/MslsContentTypes.php includes/MslsPostType.php includes/MslsTaxonomy.php includes/MslsOptions.php includes/MslsOptionsPost.php includes/MslsOptionsTax.php includes/MslsOptionsQuery.php includes/MslsRegistry.php includes/MslsGetSet.php includes/MslsLanguageArray.php includes/MslsJson.php includes/MslsSqlCacher.php

Key Design Patterns

The Data Layer employs several design patterns for extensibility and performance:

PatternImplementationPurpose
FactoryMslsOptions::create(), MslsOptionsQuery::create()Context-aware instantiation of correct options subclass
RegistryMslsRegistry singletonCentralized object storage avoiding multiple singletons
Template MethodMslsOptions abstract base with get_postlink()Standardized interface with content-type-specific implementations
Caching ProxyMslsSqlCacher wrapping WordPress cacheTransparent query result caching
Property OverloadingMslsGetSet magic methodsDynamic property access with automatic cleanup

Sources: includes/MslsOptions.php includes/MslsOptionsQuery.php44-64 includes/MslsRegistry.php52-58 includes/MslsSqlCacher.php includes/MslsGetSet.php20-64

Content Type Abstraction

The MslsContentTypes abstraction layer distinguishes between post types and taxonomies, providing unified access control and type detection. Detailed documentation is available in Content Type Management.

MslsContentTypes Factory Selection

Sources: includes/MslsContentTypes.php31-35 includes/MslsTaxonomy.php31-43 includes/MslsPostType.php24-36 includes/MslsTaxonomy.php77-88

Content Type Capabilities

ClassMethodReturnsPurpose
MslsPostTypeget()['post', 'page', ...]All public post types
MslsPostTypeget_request()'post' or 'page' etcCurrent post type from request
MslsPostTypeis_post_type()trueType identification
MslsTaxonomyget()['category', 'post_tag', ...]All public taxonomies
MslsTaxonomyget_request()'category' or 'post_tag' etcCurrent taxonomy from request
MslsTaxonomyget_post_type()'post' or customAssociated post type
MslsTaxonomyis_taxonomy()trueType identification

Sources: includes/MslsPostType.php24-56 includes/MslsTaxonomy.php31-98

Options Hierarchy and Factory Pattern

The MslsOptions class hierarchy provides specialized handlers for different WordPress content types. Each subclass stores language relationships and generates appropriate permalinks. Full details in Options and URL Generation.

Factory Method Decision Flow

Sources: includes/MslsOptionsTax.php24-40 includes/MslsOptionsTax.php47-53 includes/MslsOptionsQuery.php44-64

Options Classes and Storage Patterns

Options ClassSeparatorStorage KeyPermalink MethodSpecial Features
MslsOptionsPost_msls_{post_id}get_permalink()Checks post status
MslsOptionsTax_term_msls_{term_id}get_term_link()WooCommerce aware
MslsOptionsTaxTerm_term_msls_{term_id}get_term_link()Tag base rewriting
MslsOptionsTaxTermCategory_term_msls_{term_id}get_term_link()Category base rewriting
MslsOptionsQuery*N/AQuery paramsArchive linksSQL caching via MslsSqlCacher

Sources: includes/MslsOptionsPost.php12 includes/MslsOptionsTax.php12 includes/MslsOptionsTaxTerm.php includes/MslsOptionsQuery.php

Data Utilities

The plugin includes several utility classes that support data operations. Complete documentation is in Data Utilities and Caching.

MslsLanguageArray - Validated Storage

MslsLanguageArray stores language-to-ID mappings with automatic validation:

Validation Rules:

  • Key must be string with length ≥ 2 (language codes like 'en', 'de')
  • Value must be integer > 0 (post/term IDs)
  • Invalid entries are silently discarded

Sources: includes/MslsLanguageArray.php39-46 includes/MslsLanguageArray.php56-75

MslsGetSet - Property Overloading

MslsGetSet extends MslsRegistryInstance to provide dynamic property access with automatic cleanup:

Magic MethodBehaviorLine
__set($key, $value)Store value; unset if emptyincludes/MslsGetSet.php25-31
__get($key)Return value or nullincludes/MslsGetSet.php40-42
__isset($key)Check if property existsincludes/MslsGetSet.php51-53
__unset($key)Remove propertyincludes/MslsGetSet.php60-64
has_value($key)Check non-empty propertyincludes/MslsGetSet.php95-97
reset()Clear all propertiesincludes/MslsGetSet.php71-75

Sources: includes/MslsGetSet.php

MslsJson - AJAX Response Builder

MslsJson constructs sorted JSON arrays for AJAX autocomplete responses:

Usage Pattern:

Sources: includes/MslsJson.php26-33 includes/MslsJson.php43-45 includes/MslsJson.php52-58

MslsRegistry - Centralized Object Storage

MslsRegistry implements a singleton registry pattern to avoid multiple singleton instances:

Key Methods:

  • MslsRegistry::set_object($key, $instance) - Store object by key
  • MslsRegistry::get_object($key) - Retrieve object or null
  • MslsRegistry::instance() - Get singleton registry instance

Sources: includes/MslsRegistry.php52-79

Data Storage Patterns

The plugin uses WordPress's native storage mechanisms with specific naming conventions for organizing multilingual relationships:

Option Key Structure

  • Posts: msls_{post_id} stores language mappings as {language_code} => {target_post_id}
  • Taxonomies: msls_{term_id}_term_{taxonomy} for taxonomy relationships
  • Base configurations: Stored in standard WordPress options table

Separator Constants

  • MslsOptionsPost::SEPARATOR = '_' for post relationships
  • MslsOptionsTax::SEPARATOR = '_term_' for taxonomy relationships

Sources: includes/MslsOptionsPost.php12 includes/MslsOptionsTax.php12 includes/MslsOptions.php