Fatal errors when running WP-CLI commands
-
Problem.
When running WP-CLI commands with the gutenverse-form plugin enabled, two fatal errors occurred:
- Error 1:
Class "Gutenverse\Framework\Style_Generator" not found - Error 2:
Undefined constant "Gutenverse\Framework\GUTENVERSE_FRAMEWORK_URL_PATH"
Root Cause
The gutenverse-form plugin bundles its own copy of the Gutenverse Framework but was not properly initializing it before trying to use framework classes. The plugin’s main loader only registered the autoloader for
Gutenverse_Form\namespaced classes, leaving theGutenverse\Framework\classes inaccessible.Solution
File 1: autoload.php
Added framework bootstrap initialization at the beginning of the autoloader:
<?php
// Load framework bootstrap to ensure framework classes are available
require_once dirname( FILE ) . '/framework/bootstrap.php';File 2: bootstrap.php
Added the missing
GUTENVERSE_FRAMEWORK_URL_PATHconstant definition to the constants section:<?php
defined( 'GUTENVERSE_FRAMEWORK_URL_PATH' ) || define( 'GUTENVERSE_FRAMEWORK_URL_PATH', plugins_url( 'gutenverse-form' ) . '/lib/framework' );This constant was being used throughout the framework’s Asset class (and other classes) to build paths to CSS, JavaScript, and image assets.
Why This Works
- By requiring the framework’s bootstrap file early, we ensure the framework’s autoloader is registered before any code tries to instantiate framework classes
- By defining
GUTENVERSE_FRAMEWORK_URL_PATH, all framework classes that reference this constant will have a valid value, allowing assets to be properly located and loaded
These changes ensure the framework is fully initialized and all necessary constants are available before the gutenverse-form plugin’s initialization classes try to use them.
- Error 1:
You must be logged in to reply to this topic.