Multi-tenant WordPress solution with shared MySQL and domain-based routing.
GrabWP Tenancy provides the foundation for multi-tenant WordPress with essential isolation features. This plugin focuses on cost-effective multi-tenancy with shared resources and basic tenant separation.
- WordPress 5.0+
- PHP 7.4+
- Tested up to WordPress 6.8
- Upload
grabwp-tenancyto/wp-content/plugins/ - Activate the plugin
- Add to
wp-config.php:require_once __DIR__ . '/wp-content/plugins/grabwp-tenancy/load.php';
wp-content/
├── grabwp/
│ ├── tenants.php # Domain mappings
│ └── {tenant_id}/
│ └── uploads/ # Isolated uploads per tenant
└── plugins/
└── grabwp-tenancy/ # Base plugin
- Shared MySQL with tenant prefixes (
{tenant_id}_) - Cost-effective tenant isolation using unique table prefixes
- Shared themes and plugins
- Isolated uploads per tenant (
wp-content/grabwp/{tenant_id}/uploads)
$tenant = [
'id' => 'abc123', // 6-char alphanumeric
'domains' => [ // Array with primary first
0 => 'domain1.local',
1 => 'domain2.local'
],
'status' => 'active', // active/inactive
'created_date' => timestamp
];$tenant_mappings = [
'abc123' => [
0 => 'tenant1.grabwp.local',
],
'def456' => [
0 => 'tenant2-0.grabwp.local',
1 => 'tenant2-1.grabwp.local'
]
];flowchart TD
A[HTTP Request] --> B[Extract domain]
B --> C[Load tenants.php]
C --> D[Search tenant mappings]
D --> E{Found?}
E -->|Yes| F[Set tenant context]
E -->|No| G[Use default/main]
F --> H[Set database prefix]
F --> I[Set content paths]
G --> J[Continue with main site]
H --> K[Initialize WordPress]
I --> K
J --> K
K --> L[Process request]
- Functions:
grabwp_tenancy_prefix - Classes:
GrabWP_Tenancy_prefix - Constants:
GRABWP_TENANCY_prefix
GPLv2 or later