| @@ -30,16 +30,25 @@ | ||
| 30 | 30 | /** |
| 31 | 31 | * Register every route a module declared, prefixed with its slug. |
| 32 | 32 | */ |
| 33 | 33 | public static function register_module( Module $module ): void { |
| 34 | - $routes = $module->rest_routes(); | |
| 35 | - if ( empty( $routes ) ) { | |
| 36 | - return; | |
| 37 | - } | |
| 38 | - | |
| 34 | + // rest_routes() is resolved INSIDE the callback, not here. | |
| 35 | + // | |
| 36 | + // This method runs at plugins_loaded, before `init`. Calling | |
| 37 | + // rest_routes() there makes a module build its settings schema, and | |
| 38 | + // those schemas carry __() labels — so WordPress emitted a | |
| 39 | + // _load_textdomain_just_in_time notice for every module, on every | |
| 40 | + // request including the front end (135 per page load with WP_DEBUG on). | |
| 41 | + // The eager call existed only to skip add_action() for modules with no | |
| 42 | + // routes; deferring costs one no-op hook each and moves all translation | |
| 43 | + // work to where it belongs. (QA, 9 Aug 2026) | |
| 39 | 44 | add_action( |
| 40 | 45 | 'rest_api_init', |
| 41 | - static function () use ( $module, $routes ) { | |
| 46 | + static function () use ( $module ) { | |
| 47 | + $routes = $module->rest_routes(); | |
| 48 | + if ( empty( $routes ) ) { | |
| 49 | + return; | |
| 50 | + } | |
| 42 | 51 | $slug = $module->slug(); |
| 43 | 52 | foreach ( $routes as $route ) { |
| 44 | 53 | $path = '/' . trim( $slug, '/' ) . '/' . ltrim( $route['path'] ?? '', '/' ); |
| 45 | 54 | $path = rtrim( $path, '/' ); |