Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Jetpack Autoloader Laravel Package

automattic/jetpack-autoloader

Composer autoloader drop-in for WordPress and PHP projects that avoids class conflicts across bundled plugins/themes. Provides a custom autoloader to isolate vendor libraries, improve compatibility, and reduce “cannot redeclare class” errors in complex installs.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer in your Laravel project:

    composer require automattic/jetpack-autoloader
    

    Register the autoloader in composer.json under autoload:

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Jetpack\\": "vendor/automattic/jetpack-autoloader/src/"
        }
    }
    

    Run composer dump-autoload.

  2. First Use Case Use Jetpack’s core classes directly in Laravel:

    use Jetpack\Modules\Module;
    use Jetpack\Modules\ModuleLoader;
    
    // Load a Jetpack module (e.g., "stats")
    $moduleLoader = new ModuleLoader();
    $moduleLoader->load('stats');
    

Implementation Patterns

1. Module Integration

  • Lazy Loading: Load Jetpack modules on-demand to avoid performance overhead:

    if (ModuleLoader::isModuleActive('stats')) {
        $stats = new \Jetpack\Modules\Stats\Module();
        $stats->init();
    }
    
  • Dependency Injection: Bind Jetpack services to Laravel’s container:

    $this->app->singleton(\Jetpack\Modules\ModuleLoader::class, function ($app) {
        return new ModuleLoader($app['config']);
    });
    

2. Configuration

  • Override Jetpack defaults via Laravel’s config/jetpack.php:
    return [
        'modules' => [
            'stats' => [
                'enabled' => env('JETPACK_STATS_ENABLED', false),
            ],
        ],
    ];
    

3. Event Listeners

  • Hook into Jetpack events (e.g., module activation/deactivation):
    use Jetpack\Modules\ModuleEvent;
    
    event(new ModuleEvent('stats', 'activated'));
    

4. API Integration

  • Use Jetpack’s REST API endpoints in Laravel routes:
    Route::get('/jetpack/stats', function () {
        return \Jetpack\Modules\Stats\API::getStats();
    });
    

Gotchas and Tips

Pitfalls

  • Namespace Conflicts: Jetpack uses Jetpack\ namespace; ensure no collisions with your app.
  • Module Dependencies: Some Jetpack modules require WordPress core. Test in a WordPress environment first.
  • Caching: Jetpack’s autoloader may bypass Laravel’s OPcache. Use composer dump-autoload --optimize for production.

Debugging

  • Class Not Found: Verify composer dump-autoload was run and PSR-4 paths are correct.
  • Module Errors: Check Jetpack’s logs (/wp-content/jetpack/logs/ if WordPress is installed).

Extension Points

  • Custom Modules: Extend Jetpack’s module system by creating a subclass of Jetpack\Modules\Module.
  • Hooks: Use Jetpack’s filter/action system (e.g., jetpack_module_loaded) for custom logic.

Performance

  • Disable Unused Modules: Set enabled: false in config/jetpack.php for unused modules.
  • Autoload Excludes: Exclude Jetpack classes from PSR-4 if unused:
    "autoload-dev": {
        "psr-4": {
            "Jetpack\\": "vendor/automattic/jetpack-autoloader/src/"
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai