automattic/jetpack-autoloader
A Composer-compatible autoloader for Jetpack and other Automattic PHP packages. It helps load classes across multiple plugins/projects without conflicts, supporting shared dependencies and smoother upgrades in WordPress environments.
Jetpack_*). High risk of breakage if used outside its intended context without abstraction.automattic/jetpack-autoloader), but conflicts with Laravel’s native autoloader unless explicitly excluded or namespaced.jetpack_autoload() logic. Workaround required to bridge with Laravel’s ClassLoader.register_autoload() in WordPress’s mu-plugins or Laravel’s bootstrap/app.php). Race conditions possible if not sequenced correctly.Jetpack_Admin) may clash with Laravel’s or third-party packages.SplClassLoader merge or a wrapper class?Cache instead of Jetpack_Cache).// app/Providers/JetpackAutoloaderServiceProvider.php
public function register()
{
if (!class_exists('Jetpack_Autoloader')) {
require __DIR__ . '/../../vendor/automattic/jetpack-autoloader/jetpack-autoloader.php';
Jetpack_Autoloader::init();
}
}
ClassLoader.register_autoload() is available.composer require automattic/jetpack-autoloader (no dev dependencies).wp-settings.php or Laravel’s bootstrap/app.php):
// bootstrap/app.php (before Laravel bootstraps)
if (defined('WPINC') && !class_exists('Jetpack_Autoloader')) {
require __DIR__ . '/../vendor/automattic/jetpack-autoloader/jetpack-autoloader.php';
Jetpack_Autoloader::init();
}
ClassLoader runs after Jetpack’s to avoid override issues.Jetpack_* vs. Laravel classes).laravel-wordpress or wp-php may arise.spl_autoload_register overhead).FileCache for repeated requests.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Jetpack autoloader conflicts | Laravel classes fail to load | Use class_alias() or namespace prefixes. |
| Missing Jetpack dependency | Autoloader throws fatal error | Graceful fallback (e.g., lazy-load Jetpack). |
| WordPress/Laravel bootstrap race | Autoloader initializes too late | Explicit defined('WPINC') checks. |
| Autoloader memory leaks | High memory usage on long requests | Monitor with memory_get_usage(). |
| Jetpack updates break compatibility | Autoloader fails silently | Test against Jetpack’s CI pipeline. |
spl_autoload_functions()).How can I help you explore Laravel packages today?