Multisite

Overview

WordPress Multisite is a feature built into WordPress that allows us to run multiple websites from a single WordPress installation. Here’s a breakdown of how it works under the hood:

1. Single Codebase, Multiple Sites

  • Only one set of WordPress core files.
  • All sites share plugins and themes (though individual sites can enable/disable them).

2. Database Structure

  • All sites share a single database, but WordPress creates separate tables per site.
  • Table structure:
    • Main site: wp_options, wp_posts, etc.
    • Sub-sites: wp_2_options, wp_2_posts, wp_3_options, etc.
  • Global/shared tables include:
    • wp_users and wp_usermeta (users are shared across the network)
    • wp_site, wp_blogs, wp_sitemeta for network management

3. Domain Mapping

  • Sites can be:
    • Subdomains: site1.example.com
    • Subdirectories: example.com/site1
  • With a plugin or custom configuration, you can map custom domains (e.g., site1.com, site2.net).

4. .htaccess and wp-config.php

  • Multisite modifies both:
    • wp-config.php: defines MULTISITE, SUBDOMAIN_INSTALL, and other constants.
    • .htaccess: rewrites URLs to route traffic correctly to each site.

5. Admin Interface

  • Two admin layers:
    • Network Admin (/wp-admin/network): For managing the entire network (users, themes, plugins, sites).
    • Site Admin: Each site has its own admin dashboard (/wp-admin) with scoped permissions.

6. Security and Isolation

  • Sites are not fully isolated like containerized apps.
  • Plugins and themes are network-wide, so a faulty plugin can affect all sites.
  • User roles and capabilities can be restricted per site, but full sandboxing is not native.

7. Performance and Caching

  • Because of shared resources and a single DB, high-traffic multisites often need:
    • Advanced object caching (e.g., Redis)
    • CDN and page caching
    • DB scaling (e.g., using HyperDB or shard-based plugins)