WPCode Fatal Error During Modular DS OAuth on WordPress Multisite
-
I found a reproducible compatibility issue between WPCode and Modular DS on a WordPress multisite installation. Environment
- WordPress multisite
- PHP 8.2
- WPCode version 2.3.8
- WPCode network-activated
- Modular Connector version 3.0.2
- nginx
- Cloudflare
- Modular DS connects through a request to:
/wp-load.php?code=...&origin=mo&type=oauthProblem
When WPCode is network-active, the Modular DS OAuth request returns HTTP 500.
The exact fatal recorded by Modular Connector is:
production.ERROR: Class "WPCode_File_Cache" not found Error location: wp-content/plugins/insert-headers-and-footers/ihaf.php:436Stack trace:
#0 wp-includes/class-wp-hook.php(341): WPCode->load_components() #1 wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters() #2 wp-includes/plugin.php(522): WP_Hook->do_action() #3 wp-settings.php(622): do_action() #4 wp-config.php: require_once(...) #5 wp-load.php: require_once(...)After manually preloading that class, the fatal advances to other WPCode admin-only classes, including:
Class "WPCode_Library" not found Class "WPCode_Admin_Page_Loader_Lite" not found Class "WPCode_Smart_Tags_Lite" not foundApparent cause
In
ihaf.php, WPCode loads admin-only class files inside this condition:if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { require_once WPCODE_PLUGIN_PATH . 'includes/class-wpcode-file-cache.php'; require_once WPCODE_PLUGIN_PATH . 'includes/class-wpcode-library.php'; // Other admin classes... }Later,
WPCode::load_components()uses the same condition and instantiates those classes:if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { $this->file_cache = new WPCode_File_Cache(); $this->library = new WPCode_Library(); $this->library_auth = new WPCode_Library_Auth(); // Other admin components... }Modular DS initially enters through
wp-load.php, sois_admin()appears to be false when WPCode runs itsincludes()method.Modular Connector later defines
WP_ADMINduring its request pipeline. By the time WPCode’sload_components()callback runs onplugins_loaded,is_admin()is true, so WPCode tries to instantiate admin classes that were skipped earlier.This creates a state mismatch:
WPCode includes phase: is_admin() = false Admin files are not loaded WPCode load_components phase: is_admin() = true Admin classes are instantiated Fatal: class not foundReproduction
- Network-activate WPCode.
- Start a Modular DS OAuth connection.
- Modular requests:
/wp-load.php?code=...&origin=mo&type=oauth- The request returns HTTP 500.
- The WPCode class-not-found fatal is logged.
Confirmation
When WPCode is network-deactivated, Modular DS connects successfully immediately.
Reinstalling WPCode 2.3.8 did not resolve the issue. Suggested fix
WPCode should avoid evaluating
is_admin()independently during two different bootstrap stages.Possible fixes may include:
- loading all classes required by
load_components()unconditionally; - storing the initial admin-state decision and using the same value in both
includes()andload_components(); - checking that each class exists before instantiating it;
- moving the admin includes into
load_components()immediately before instantiation.
For example:
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { if ( ! class_exists( 'WPCode_File_Cache', false ) ) { require_once WPCODE_PLUGIN_PATH . 'includes/class-wpcode-file-cache.php'; } $this->file_cache = new WPCode_File_Cache(); }Please let me know if you need the full Modular Connector log or additional server details.
You must be logged in to reply to this topic.