Fix: Defer WP-CLI command registration to prevent textdomain warning#7488
Fix: Defer WP-CLI command registration to prevent textdomain warning#7488faisalahammad wants to merge 1 commit intopods-framework:mainfrom
Conversation
Fixes pods-framework#7458 Wrap WP_CLI::add_command() calls in after_wp_load hook callbacks to ensure translation functions are not called before the init hook fires. This prevents the _load_textdomain_just_in_time warning introduced in WordPress 6.7.0.
PR Summary
|
|
The Pods_CLI_Command and PodsAPI_CLI_Command classes are already loaded only if WP_CLI is defined via PodsInit around line 2438. I can't seem to reproduce the error for |
Summary
This PR fixes the
_load_textdomain_just_in_timewarning that appears on every WP-CLI command when Pods is activated.Fixes #7458
Problem
When I run any WP-CLI command on WordPress 6.7.0 or later with Pods activated, I see this warning:
Root Cause
I traced the issue to the legacy CLI command files. The problem is that both files call
WP_CLI::add_command()at file-level scope (outside any function or hook):File:
classes/cli/Pods_CLI_Command.php(line 388)File:
classes/cli/PodsAPI_CLI_Command.php(line 507)These files are loaded during the
plugins_loadedhook inPodsInit::run():When PHP executes
require_once, theWP_CLI::add_command()calls run immediately. WP-CLI then inspects the command class and finds__()translation function calls inside the class methods. This triggers WordPress to load thepodstextdomain before theinithook fires, which causes the warning.Solution
I wrapped the
WP_CLI::add_command()calls inside aWP_CLI::add_hook('after_wp_load', ...)callback. Theafter_wp_loadhook fires after WordPress completes initialization, so the textdomain is properly loaded before any translation functions run.This follows the same pattern already used in
src/Pods/CLI/Service_Provider.php.Code Changes
Before (Pods_CLI_Command.php)
After (Pods_CLI_Command.php)
Before (PodsAPI_CLI_Command.php)
After (PodsAPI_CLI_Command.php)
Testing
wp plugin list)wp pods-legacy --helpandwp pods-legacy-api --helpChecklist
Plugin Zip
pods-fix-7458.zip