WordPress 6.7+ notice: Betheme Visual Builder Yoast integration triggers wordpress-seo translations
Hi,
I’m seeing the following notice on a site running Betheme with debugging enabled and Yoast SEO active:
Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. This message was added in version 6.7.0.
I added a temporary debug mu-plugin to capture the backtrace when the notice is triggered, and it points to the Betheme Visual Builder Yoast integration being instantiated while the theme is still loading:
/wp-content/themes/betheme/visual-builder/integrations/yoast/yoast.php:61
/wp-content/themes/betheme/visual-builder/visual-builder.php:117
/wp-content/themes/betheme/functions.php:243
The relevant part of visual-builder.php appears to be:
if( defined( 'WPSEO_FILE' ) ) {
require_once( get_theme_file_path('/visual-builder/integrations/yoast/yoast.php') );
require_once( get_theme_file_path('/visual-builder/integrations/yoast/yoast_post.php') );
add_action('mfn_yoast', 'mfn_yoast_init');
function mfn_yoast_init() {
add_action( 'mfn_footer_enqueue', [ new \BeYoast\Yoast(), 'init' ], 999997 );
}
add_action( 'wp_ajax_wpseo_betheme_save', [ new \BeYoast\Yoast(), 'save_postdata' ] );
}
The issue seems to be that new \BeYoast\Yoast() is being called immediately when the theme file loads, particularly in this line:
add_action( 'wp_ajax_wpseo_betheme_save', [ new \BeYoast\Yoast(), 'save_postdata' ] );
That appears to instantiate the Yoast integration before WordPress reaches init. The constructor then calls through to Yoast’s options helper, which causes the wordpress-seo textdomain to be loaded too early.
For reference, the relevant part of the backtrace is:
#8 __()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-option-titles.php:272
#9 WPSEO_Option_Titles->translate_defaults()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-option.php:404
#10 WPSEO_Option->get_defaults()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-option.php:726
#11 WPSEO_Option->array_filter_merge()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-option.php:446
#12 WPSEO_Option->get_option()
/wp-includes/class-wp-hook.php:343
#13 WP_Hook->apply_filters()
/wp-includes/plugin.php:205
#14 apply_filters()
/wp-includes/option.php:256
#15 get_option()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php:263
#16 WPSEO_Options::get_option()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php:240
#17 WPSEO_Options::get_options()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php:223
#18 WPSEO_Options::get_all()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php:311
#19 WPSEO_Options::prime_cache()
/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php:285
#20 WPSEO_Options::get()
/wp-content/plugins/wordpress-seo/src/helpers/options-helper.php:27
#21 Yoast\WP\SEO\Helpers\Options_Helper->get()
/wp-content/themes/betheme/visual-builder/integrations/yoast/yoast.php:61
#22 BeYoast\Yoast->__construct()
/wp-content/themes/betheme/visual-builder/visual-builder.php:117
#23 require_once()
/wp-content/themes/betheme/functions.php:243
A possible fix may be to avoid instantiating \BeYoast\Yoast directly in the action registration, and instead instantiate it inside a callback when the relevant action actually runs, for example:
add_action( 'wp_ajax_wpseo_betheme_save', function () {
$yoast = new \BeYoast\Yoast();
$yoast->save_postdata();
} );
Similarly, this part may also be safer if the object is created inside the callback:
function mfn_yoast_init() {
add_action( 'mfn_footer_enqueue', function () {
$yoast = new \BeYoast\Yoast();
$yoast->init();
}, 999997 );
}
I’m not suggesting this is necessarily the final fix, as you’ll know the Visual Builder loading flow better than I do, but it looks like the issue is caused by the Yoast integration object being instantiated too early.
Could you please check this for compatibility with WordPress 6.7+?
While waiting for a response from one of our team members, we recommend to check Support Center where it is highly likely that you will find the answer to your question in no time.
FAQ | Video Tutorials | How to