From 9f9ce969202101be8c7bdd5d03fa971d558f07ba Mon Sep 17 00:00:00 2001 From: Yonathan Randolph Date: Tue, 2 Sep 2025 08:59:41 -0700 Subject: [PATCH 1/3] fix: PSR-4 error Fix error running composer dump-autoload --optimize --classmap-authoritative --strict-psr --strict-ambiguous. I wish to add --classmap-authoritative to my wordpress app for performance reasons but headstartwp is preventing me from being able to do so. --- wp/headless-wp/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp/headless-wp/composer.json b/wp/headless-wp/composer.json index 4d0de431f..e78328744 100644 --- a/wp/headless-wp/composer.json +++ b/wp/headless-wp/composer.json @@ -45,7 +45,8 @@ }, "autoload": { "psr-4": { - "HeadlessWP\\": "includes/classes/" + "HeadlessWP\\": "includes/classes/", + "HeadlessWP\\JWT\\": "includes/classes/php-jwt/" } }, "scripts": { From 04ad204a41eacc6e6567fc17efa6fbfed5dd6621 Mon Sep 17 00:00:00 2001 From: Yonathan Randolph Date: Tue, 2 Sep 2025 09:02:00 -0700 Subject: [PATCH 2/3] Remove workaround; use PSR-4 autoloader for php-jwt --- wp/headless-wp/plugin.php | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/wp/headless-wp/plugin.php b/wp/headless-wp/plugin.php index 1608504a4..9349f3ddd 100644 --- a/wp/headless-wp/plugin.php +++ b/wp/headless-wp/plugin.php @@ -22,39 +22,29 @@ define( 'HEADLESS_WP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); define( 'HEADLESS_WP_PLUGIN_INC', HEADLESS_WP_PLUGIN_PATH . 'includes/' ); -// Load php-jwt classes. -$jwt_files = [ - 'BeforeValidException.php', - 'ExpiredException.php', - 'JWK.php', - 'JWT.php', - 'SignatureInvalidException.php', -]; - -foreach ( $jwt_files as $filename ) { - require_once HEADLESS_WP_PLUGIN_PATH . '/includes/classes/php-jwt/' . $filename; -} - // Require Composer autoloader if it exists. if ( file_exists( HEADLESS_WP_PLUGIN_PATH . '/vendor/autoload.php' ) ) { require_once HEADLESS_WP_PLUGIN_PATH . 'vendor/autoload.php'; } else { + // PSR-4 map (longest/more-specific prefixes should come first) + $psr4 = [ + 'HeadlessWP\\JWT\\' => __DIR__ . '/includes/classes/php-jwt/', + 'HeadlessWP\\' => __DIR__ . '/includes/classes/', + ]; spl_autoload_register( - function ( $the_class ) { - // Project-specific namespace prefix. - $prefix = 'HeadlessWP\\'; - // Base directory for the namespace prefix. - $base_dir = __DIR__ . '/includes/classes/'; - // Does the class use the namespace prefix? + function ( $the_class ) use ( $psr4 ) { + foreach ( $psr4 as $prefix => $base_dir ) { $len = strlen( $prefix ); - if ( strncmp( $prefix, $the_class, $len ) !== 0 ) { - return; - } + if ( strncmp( $prefix, $the_class, $len ) !== 0 ) { + continue; + } $relative_class = substr( $the_class, $len ); $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php'; // If the file exists, require it. - if ( file_exists( $file ) ) { - require $file; + if ( file_exists( $file ) ) { + require $file; + return; + } } } ); From da25fa885d354abda5385fb16fd33844b3c33c60 Mon Sep 17 00:00:00 2001 From: Yonathan Randolph Date: Tue, 2 Sep 2025 11:36:05 -0700 Subject: [PATCH 3/3] add changeset --- .changeset/huge-hornets-tan.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/huge-hornets-tan.md diff --git a/.changeset/huge-hornets-tan.md b/.changeset/huge-hornets-tan.md new file mode 100644 index 000000000..2753d4e3a --- /dev/null +++ b/.changeset/huge-hornets-tan.md @@ -0,0 +1,5 @@ +--- +"@headstartwp/headstartwp": patch +--- + +Make headstartwp PSR-4 compliant: add autoload.psr-4 mapping for php-jwt, remove require_once of php-jwt files