Closed tillkruss closed 5 months ago
@yatsukhnenko: This commit did not work: 399664183c7f09e05dff12ac8d37cc8fb6b2030d
Instead of the function_exists()
call we should call:
if ( ! isset( $l10n_unloaded[ $domain ] ) ) {
load_plugin_textdomain(...);
}
Can you please test that by throwing an exception in our wp_cache_init()
?
define ('WPLANG', 'uk_UK');
@tillkruss proposed change doesn't solve the issue. Also load_plugin_textdomain
requires WP_PLUGIN_DIR
which is not defined while wp_cache_init
. When I define it load_plugin_textdomain
throws similar error Call to a member function get() on null
.
@tillkruss proposed change doesn't solve the issue. Also
load_plugin_textdomain
requiresWP_PLUGIN_DIR
which is not defined whilewp_cache_init
. When I define itload_plugin_textdomain
throws similar errorCall to a member function get() on null
.
That great that you can reproduce it.
What about calling this right after wp_load_translations_early();
:
$domain = 'redis-cache';
$locale = defined( 'WPLANG' ) ? WPLANG : 'en_US';
$mofile = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo';
load_textdomain( $domain, $mofile, $locale );
It might need minor tweaks. But passing locale
to the call should just load it.
That great that you can reproduce it.
To reproduce issue I have to modify WP source code...
What about calling this right after wp_load_translations_early();:
I'll check this and let you know the result
@tillkruss your code snippet works, also there is another possible solution
add_filter( 'pre_wp_load_alloptions', function () {
return [ 'template' => '', 'stylesheet' => '' ];
} );
The filter approach is smart, but let's go with my load_textdomain()
, because it's more robust against wp core updates.
@tillkruss when there is no .mo
file problem still exists, for example for uk_UA
lang I see following error
#0 /var/www/html/wp-includes/option.php(599): wp_cache_get('alloptions', 'options', false)
#1 /var/www/html/wp-includes/option.php(164): wp_load_alloptions()
#2 /var/www/html/wp-includes/l10n.php(63): get_option('WPLANG')
#3 /var/www/html/wp-includes/l10n.php(156): get_locale()
#4 /var/www/html/wp-includes/l10n.php(1300): determine_locale()
#5 /var/www/html/wp-includes/l10n.php(1331): _load_textdomain_just_in_time('redis-cache')
#6 /var/www/html/wp-includes/l10n.php(185): get_translations_for_domain('redis-cache')
#7 /var/www/html/wp-includes/l10n.php(297): translate('Error establish...', 'redis-cache')
#8 /var/www/html/wp-content/object-cache.php(2936): __('Error establish...', 'redis-cache')
#9 /var/www/html/wp-content/object-cache.php(2891): WP_Object_Cache->show_error_and_die(Object(Exception))
#10 /var/www/html/wp-content/object-cache.php(504): WP_Object_Cache->handle_exception(Object(Exception))
#11 /var/www/html/wp-content/object-cache.php(256): WP_Object_Cache->__construct(false)
#12 /var/www/html/wp-includes/load.php(856): wp_cache_init()
#13 /var/www/html/wp-settings.php(131): wp_start_object_cache()
#14 /var/www/html/wp-config.php(154): require_once('/var/www/html/w...')
#15 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
#16 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')
#17 /var/www/html/index.php(17): require('/var/www/html/w...')
#18 {main}
thrown in /var/www/html/wp-content/object-cache.php on line 193
@yatsukhnenko Good catch! Can we stack these?
Something like:
load_textdomain()
load_textdomain()
returns false (no .mo
file?)
a. Set WPLANG
to a fixed en_US
if constant is not defined
b. If constant is set apply your add_filter()
?Does that resolve all the various cases?