Menu

Package Structure

Relevant source files

This document describes the directory layout, file organization, and namespace structure of the Multisite Language Switcher plugin codebase. For information about the plugin initialization and lifecycle, see Plugin Initialization and Lifecycle. For details on the build process, see Build System and Asset Processing.

Overview

The plugin follows WordPress plugin conventions with a single entry point file at the root and organized subdirectories for different asset types. PHP classes use PSR-4 autoloading under the lloc\Msls namespace, with all class files located in the includes/ directory. The build system compiles source assets from src/ into production-ready files in js/ and css/.

Root Directory Structure

The repository is organized with the following top-level structure:

Sources: .gitignore1-21 package.json2-7 composer.json25-33

Plugin Entry Point

The main plugin file defines the plugin header and establishes the global environment:

FilePurposeKey Elements
MultisiteLanguageSwitcher.phpPlugin entry pointPlugin headers (lines 1-32), autoloader (lines 34-36), constants (lines 43-46), public API functions (lines 57-245)

Constants Defined:

  • MSLS_PLUGIN_VERSION - Plugin version string
  • MSLS_PLUGIN_PATH - Plugin basename for WordPress
  • MSLS_PLUGIN__FILE__ - Absolute file path

Sources: MultisiteLanguageSwitcher.php1-246

PHP Namespace Organization

All PHP classes reside in the includes/ directory and use PSR-4 autoloading:

Namespace Mapping:

  • lloc\Msls\includes/
  • lloc\Msls\Component\includes/Component/
  • lloc\Msls\ContentImport\includes/ContentImport/
  • lloc\Msls\Query\includes/Query/
  • lloc\Msls\Map\includes/Map/

Sources: composer.json25-28 MultisiteLanguageSwitcher.php34-36

Asset Directory Structure

The plugin separates source assets from built artifacts:

Build Commands:

ScriptCommandInputOutput
uglifyuglifyjs src/msls.js > js/msls.jssrc/msls.jsjs/msls.js
lesslessc css/msls.less css/msls.css --clean-csscss/msls.lesscss/msls.css
build-msls-blockwp-scripts build --webpack-src-dir=src/msls-widget-block --output-path=js/msls-widget-blocksrc/msls-widget-block/js/msls-widget-block/
buildRuns all three build commandsAll sourcesAll outputs

Sources: package.json2-7 .gitignore9-10

Icon and Flag Resources

The plugin maintains two separate flag icon systems:

Generation Commands:

  • composer prepare - Downloads translations.json from WordPress.org API
  • composer flags-png - Generates flags/flags.php mapping file
  • composer flags-svg - Generates css/flags.php mapping file

Sources: composer.json43-45 MslsPlugin.php117-118

Testing Structure

Tests are organized by type with separate configurations:

DirectoryPurposeNamespace
tests/phpunit/PHPUnit unit testslloc\MslsTests\
tests/playwright/End-to-end browser testsN/A (JavaScript)
tests/coverage/Code coverage reportsN/A (generated)

Test Execution:

  • PHPUnit: composer test or vendor/bin/phpunit
  • Coverage: composer coverage (requires Xdebug)
  • Playwright: composer playwright or npm run playwright

Sources: composer.json30-33 composer.json36-52 .gitignore16-19

Dependency Management

The plugin uses two package managers:

Composer Dependencies (Production):

  • composer/installers - WordPress plugin installer
  • ext-json - JSON extension requirement

Composer Dependencies (Development):

  • phpunit/phpunit - Testing framework
  • phpstan/phpstan - Static analysis
  • squizlabs/php_codesniffer - Code style checking
  • brain/monkey - WordPress function mocking

NPM Dependencies (Production):

  • uglify-js - JavaScript minification
  • less - LESS compilation
  • less-plugin-clean-css - CSS minification

NPM Dependencies (Development):

  • @wordpress/scripts - WordPress block build tools
  • @playwright/test - End-to-end testing

Sources: composer.json7-24 package.json9-20 MultisiteLanguageSwitcher.php34-36 .gitignore13-20

Language Files

Translation files follow WordPress internationalization standards:

DirectoryPurposeFiles
languages/Translation templates and MO filesdefault.pot (template), *.po (translations), *.mo (compiled)

Text Domain: multisite-language-switcher (defined in plugin header)

Translation Loading: WordPress automatically loads translations from this directory based on the site locale.

Sources: languages/default.pot1-409 MultisiteLanguageSwitcher.php12

Configuration Files

The repository root contains several configuration files:

FilePurposeRelated Command
composer.jsonPHP dependencies, autoloading, scriptscomposer install
package.jsonJavaScript dependencies, build scriptsnpm install
package-lock.jsonLocked NPM dependency versionsAuto-generated
phpunit.xmlPHPUnit configurationcomposer test
.gitignoreGit exclusionsN/A
readme.txtWordPress.org plugin readmeDisplayed on plugin page
README.mdGitHub repository readmeDisplayed on GitHub

Sources: composer.json1-94 package.json1-22 readme.txt1-132 README.md1-106

File Naming Conventions

The codebase follows consistent naming patterns:

PHP Classes:

  • Pattern: Msls{Name}.php in includes/ directory
  • Namespace: lloc\Msls\{Name} class
  • Examples: MslsPlugin.php, MslsOptions.php, MslsBlogCollection.php

Subnamespace Classes:

  • Pattern: includes/{Subnamespace}/{Name}.php
  • Namespace: lloc\Msls\{Subnamespace}\{Name}
  • Examples: includes/Component/Input/Text.phplloc\Msls\Component\Input\Text

Test Classes:

  • Pattern: tests/phpunit/{Name}Test.php
  • Namespace: lloc\MslsTests\{Name}Test
  • Naming: Mirrors source class name with Test suffix

Sources: composer.json25-33 includes/MslsPlugin.php1-3 includes/MslsAdmin.php1-3