معمارية الإضافة الأساسية: التوزيع متعدد المستأجرين ومُحمّلات Must-Use

تحليل معماري بأثر رجعي ودليل تنفيذي حول سبب عدم توفر إضافة Modern WordPress Core الأساسية في موقع المستأجر NHTFS (Not Here To Fuck Spiders)، والأنماط الهندسية البرمجية الحديثة المطلوبة لتوزيع الإضافات الأساسية المشتركة بشكل موثوق عبر البيئات متعددة المستأجرين المعتمدة على الحاويات.

1. التشخيص: لماذا كانت إضافة Modern WordPress Core مفقودة

During deployment and content ingestion for the NHTFS story laboratory, the core plugin failed to appear in the WordPress administration panel and wp plugin list returned an empty table. Three architectural issues caused this failure:

  • نقطة ربط وحدة تخزين Docker المحذوفة (Bind Mount): The primary WordPress container and the NHTFS container run on separate named volumes (wp_data vs wp_notheretofuckspiders_data). While theme directories were shared across services, the host directory wp-content/plugins/modern-wordpress-core was mounted into the primary container but omitted from the NHTFS container definition.
  • مخلفات الأدلة الفارغة: قام حاوية NHTFS بتعيين فقط sites/notheretofuckspiders/wp-content/plugins/notheretofuckspiders-core, which was an empty directory without a main PHP file or plugin header. Inside the container filesystem, an empty modern-wordpress-core/ كان الدليل موجوداً دون ملفات. ونظراً لأن نواة WordPress تبحث فقط عن ملفات PHP ذات ترويسات Plugin Name: headers, empty stubs are completely ignored.
  • تفصيل التصنيفات في الصفحات: يقوم برنامج الإدخال النصي لـ NHTFS بتحويل مستندات Markdown إلى معيار WordPress الهرمي page الكائنات بالتصنيفات (الفئات والوسوم). في WordPress القياسي، لا تدعم الصفحات الهرمية الفئات أو الوسوم. إن ModernWordPress\Core\Plugin تسجل الفئة (Class) هذه العناصر صراحة عبر register_taxonomy_for_object_type(). بدون تفعيل الإضافة الأساسية، لا يمكن ربط البيانات الوصفية لتصنيفات الصفحات أو عرضها.

2. النمط المضاد: التفعيل اليدوي عبر لوحة التحكم في المواقع المتعددة

Relying on standard plugin activation in /wp-admin/plugins.php for critical infrastructure is an anti-pattern. If a plugin registers core schema, PSR-4 autoloading, Zero Trust security filters, or taxonomy bindings required by the theme, allowing an administrator to deactivate it can take down the frontend. Furthermore, manual activation does not scale across multi-tenant environments or automated CI/CD pipelines.

3. الحلول المعمارية الحديثة

3.1 معمارية مُحمّل الإضافات حتمية الاستخدام (MU Plugin)

The standard modern pattern in enterprise WordPress engineering (such as Bedrock and WordPress VIP) is loading platform infrastructure via wp-content/mu-plugins/. تعمل الإضافات حتمية الاستخدام (Must-Use plugins) تلقائياً قبل الإضافات القياسية، وتُنفذ مع كل طلب عبر الشبكة، ولا يمكن تعطيلها من لوحة تحكم الويب.

Because WordPress only scans the root of mu-plugins/ ولا تنزل إلى المجلدات الفرعية، فإننا ننشر برنامج تحميل نصياً خفيف الوزن في wp-content/mu-plugins/00-modern-wordpress-core-loader.php:

<?php
/**
 * Plugin Name: Modern WordPress Core MU Loader
 * Description: Automatically loads Modern WordPress Core infrastructure as a Must-Use plugin.
 * Version: 1.0.0
 * Author: Modern WordPress
 */

declare(strict_types=1);

$core_bootstrap = dirname( __DIR__ ) . '/plugins/modern-wordpress-core/modern-wordpress-core.php';

if ( file_exists( $core_bootstrap ) ) {
    require_once $core_bootstrap;
}

3.2 تنسيق وحدات تخزين Monorepo في Docker Compose

في البيئات القائمة على الحاويات، يجب ربط الإضافات المشتركة بشكل صريح داخل كل تعريف خدمة يتطلبها. ويجب أن تتلقى كل من خادم الويب وحاوية أدوات WP-CLI المقابلة نقاط ربط متطابقة:

  wordpress_notheretofuckspiders:
    image: wordpress:6.7-php8.2-apache
    volumes:
      - wp_notheretofuckspiders_data:/var/www/html
      - ../wp-content/themes/brutalist:/var/www/html/wp-content/themes/brutalist
      - ../wp-content/plugins/modern-wordpress-core:/var/www/html/wp-content/plugins/modern-wordpress-core:ro
      - ./mu-plugins/00-core-loader.php:/var/www/html/wp-content/mu-plugins/00-core-loader.php:ro

3.3 مستودعات مسارات Composer (إدارة حزم PSR-4)

For modular software engineering, shared plugins should be managed as local Composer packages. By defining a path repository in the root composer.json، يقوم Composer بإنشاء رابط رمزي أو نسخ لحزمة الإضافة أثناء إنشاء أداة التحميل التلقائي المعتمدة:

{
  "repositories": [
    {
      "type": "path",
      "url": "wp-content/plugins/modern-wordpress-core"
    }
  ],
  "require": {
    "modern-wordpress/core": "*"
  }
}

4. التنفيذ العملي خطوة بخطوة

لربط الإضافة الأساسية في NHTFS بصورة نظيفة وسليمة:

  1. ربط نقطة تثبيت الإضافة (Bind Mount): تأكد docker-compose.yml يجتاز ../wp-content/plugins/modern-wordpress-core في كلا wordpress_notheretofuckspiders و wp-cli-notheretofuckspiders at /var/www/html/wp-content/plugins/modern-wordpress-core.
  2. نشر مُحمّل MU: ربط أداة التحميل الإلزامية (Must-Use) في /var/www/html/wp-content/mu-plugins/00-core-loader.php to ensure zero-touch activation without manual database flags.
  3. تنشيط WP-CLI أحادي التأثير (Idempotent): إذا كنت تقوم بالنشر كإضافة قياسية بدلاً من إضافة إجبارية (MU plugin)، فقم بتضمين wp plugin activate modern-wordpress-core in the automated container entrypoint or Makefile provisioner.

5. التحقق الحتمي

التحقق من توفر الإضافة وتسجيل التصنيف باستخدام WP-CLI:

# Verify plugin status in tenant container
docker compose exec wp-cli-notheretofuckspiders wp plugin list

# Verify category and tag bindings on the page post type
docker compose exec wp-cli-notheretofuckspiders wp post-type get page --fields=taxonomies

Once verified, the output confirms that category و post_tag مرتبطة بـ page، مما يمكّن مستورد NHTFS من ملء البيانات الوصفية للقصة دون أخطاء.