From 8b6891fad813005e4a9d2b37498fe28fb5e1c568 Mon Sep 17 00:00:00 2001 From: Tom Macready-Bryan Date: Thu, 16 Jul 2026 14:34:56 +1000 Subject: [PATCH] fix: prevent activation fatal when installed without vendor/ The bootstrap loaded the PSR-4 AssetDrips\ namespace only through Composer's vendor/autoload.php, guarded by is_readable(). A distributed zip that shipped without a vendor/ directory therefore loaded no classes, and activation fataled: Uncaught Error: Class "AssetDrips\Db\Schema" not found in assetdrips.php:48 The plugin has no third-party runtime dependencies, so the autoloader's only runtime job is mapping AssetDrips\ -> src/. Register a minimal built-in PSR-4 autoloader as a fallback when vendor/autoload.php is absent, making the plugin self-contained regardless of how it is packaged. Fixes #1 --- CHANGELOG.md | 8 ++++++++ assetdrips.php | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c1ac3..dd72903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ is pre-1.0 and under active development. ## [Unreleased] +### Fixed +- **Activation fatal error when installed without Composer's `vendor/`:** the + bootstrap only loaded classes via `vendor/autoload.php`, so a distributed zip + that shipped without a `vendor/` directory fataled on activation with + `Uncaught Error: Class "AssetDrips\Db\Schema" not found`. The plugin now falls + back to a minimal built-in PSR-4 autoloader (it has no third-party runtime + dependencies), making it self-contained regardless of how it is packaged. + ## [1.0.0] - 2026-06-19 First public release of AssetDrips as an open-source (GPL-2.0-or-later) WordPress diff --git a/assetdrips.php b/assetdrips.php index 9e6c803..c33ddf8 100644 --- a/assetdrips.php +++ b/assetdrips.php @@ -26,10 +26,30 @@ define( 'ASSETDRIPS_DIR', plugin_dir_path( __FILE__ ) ); define( 'ASSETDRIPS_URL', plugin_dir_url( __FILE__ ) ); -// Composer autoloader. Required for the PSR-4 AssetDrips\ namespace. +// Load the PSR-4 AssetDrips\ namespace. Prefer Composer's autoloader when a +// vendor/ directory is present (dev checkouts, or a build that bundles it); fall +// back to a minimal self-contained autoloader otherwise. The plugin has no +// third-party runtime dependencies, so mapping AssetDrips\ -> src/ is all that +// is needed for a distributed zip that ships without vendor/. Without this +// fallback, activation fataled with "Class AssetDrips\Db\Schema not found". $assetdrips_autoload = __DIR__ . '/vendor/autoload.php'; if ( is_readable( $assetdrips_autoload ) ) { require $assetdrips_autoload; +} else { + spl_autoload_register( + static function ( string $class ): void { + $prefix = 'AssetDrips\\'; + $len = strlen( $prefix ); + if ( strncmp( $class, $prefix, $len ) !== 0 ) { + return; + } + $relative = str_replace( '\\', '/', substr( $class, $len ) ); + $file = __DIR__ . '/src/' . $relative . '.php'; + if ( is_readable( $file ) ) { + require $file; + } + } + ); } /**