error in wp
-
please fix the bug. I have made a patch myself.
Impact: swatches won’t load well , the error leaks in json responses.
The error “Translation loading for the wcvs domain was triggered too early” occurs because translations are being used before the text domain is properly loaded. Here’s how to fix it:
- In class-variation-swatches.php:
- Move the translations out of the constructor
- Initialize types with untranslated strings first
- Add translations after init hook
- In variation-swatches-for-woocommerce.php:
- Remove early text domain loading from plugins_loaded
- Add proper text domain loading on init hook
Here’s the specific code changes needed:
- In class-variation-swatches.php:
public function __construct() { // Initialize with untranslated strings $this->types = array( 'color' => 'Color', 'image' => 'Image', 'label' => 'Label', ); if ( TA_WC_Variation_Swatches::is_pro_addon_active() ) { $this->types['radio'] = 'Radio button'; } $this->includes(); $this->init_hooks(); } public function init_hooks() { // Add translations after init add_action( 'init', array( $this, 'load_translations' ) ); // ... rest of your hooks } public function load_translations() { // Apply translations after text domain is loaded $this->types = array( 'color' => esc_html__( 'Color', 'wcvs' ), 'image' => esc_html__( 'Image', 'wcvs' ), 'label' => esc_html__( 'Label', 'wcvs' ), ); if ( TA_WC_Variation_Swatches::is_pro_addon_active() ) { $this->types['radio'] = esc_html__( 'Radio button', 'wcvs' ); } }- In variation-swatches-for-woocommerce.php:
// Remove text domain loading from constructor function ta_wc_variation_swatches_constructor() { if ( ! function_exists( 'WC' ) ) { add_action( 'admin_notices', 'ta_wc_variation_swatches_wc_notice' ); } elseif ( defined( 'TAWC_VS_PRO' ) ) { add_action( 'admin_notices', 'ta_wc_variation_swatches_pro_notice' ); deactivate_plugins( plugin_basename( __FILE__ ) ); } else { require_once plugin_dir_path( __FILE__ ) . '/includes/class-variation-swatches.php'; TA_WCVS(); } } // Add proper text domain loading function ta_wc_variation_swatches_load_textdomain() { load_plugin_textdomain( 'wcvs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } add_action( 'init', 'ta_wc_variation_swatches_load_textdomain' );This fix ensures that:
- The text domain is loaded at the proper time (during init)
- No translations are attempted before the text domain is loaded
- The plugin’s functionality remains intact
The error occurs because WordPress 6.7.0 added stricter checks for text domain loading timing. Translations should only be loaded at the init action or later, which this fix properly implements.
The page I need help with: [log in to see the link]
The topic ‘error in wp’ is closed to new replies.