Support » Plugin: PPOM for WooCommerce » ppom_wpml_translate breaks ability to save default settings in WooCommerce

  • Resolved brozra

    (@brozra)


    Ran into an issue with the ppom_wpml_translate function in functions.php line 110. When loading the WooCommerce settings page and trying to save changes to it there are two PHP warnings that interfere with the ability to save any changes.

    Using the Query Monitor plugin I was able to trace it to your plugin causing a save failure in WooCommerce settings.

    Warning stripslashes() expects parameter 1 to be string, array given
    Count = 10
    wp-content/plugins/woocommerce-product-addon/inc/functions.php:119
    Plugin: woocommerce-product-addon

    Warning strtolower() expects parameter 1 to be string, array given
    Count = 10
    wp-includes/formatting.php:2126
    Plugin: woocommerce-product-addon

    It looks as though an array is being passed to the function as a field value. Not even sure why PPOM is loading on the default WooCommerce settings page. It should only be loaded for its particular settings tab.

    Quick fix I implemented:

    
    function ppom_wpml_translate($field_value, $domain) {
    	if (!is_array($field_value)) {
    		$field_name = $domain . ' - ' . sanitize_key($field_value);
    		//WMPL
    		/**
    		 * register strings for translation
    		 * source: https://wpml.org/wpml-hook/wpml_translate_single_string/
    		 */
    		$field_value = stripslashes($field_value);
    	} else {
    		// Do something with the array here??
    	}
    
        if( has_filter('wpml_translate_single_string') ) {
    		$field_value = apply_filters('wpml_translate_single_string', $field_value, $domain, $field_name );
        }
    
    	// Polylang
    	if( function_exists('pll__') ) {
    		$field_value = pll__($field_value);
    	}
    
    	return $field_value;
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author N-Media

    (@nmedia)

    Hi @brozra,

    Thanks for sharing this fix, I have this in core plugin with little change and it will be released in version 18.4:

    function ppom_wpml_translate($field_value, $domain) {
    		
    		// $field_value is array then return
    		if( is_array($field_value) ) return $field_value;
    		
    		$field_name = $domain . ' - ' . sanitize_key($field_value);
    	    $field_value = stripslashes($field_value);
    		
    		//WMPL
    	    /**
    	     * register strings for translation
    	     * source: https://wpml.org/wpml-hook/wpml_translate_single_string/
    	     */
    	    if( has_filter('wpml_translate_single_string') ) {
    			$field_value = apply_filters('wpml_translate_single_string', $field_value, $domain, $field_name );
    	    }
    	    
    	    
    		// Polylang
    		if( function_exists('pll__') ) {
    			$field_value = pll__($field_value);
    		}
    		
    		return $field_value;
    	}

    Hi,

    Has this update been released yet?
    I have the pro version – will I need to log in to the client access on the plug in site to receive the most recent update or will it be available as an update on my wordpress dashboard?

    If the update is not yet live, where do I add the above code?

    This error is stopping me from telling the woocommerce store what countries to sell to / deliver to. I try to save and it shows the error and loses the settings I just entered.

    Any help would be much appreciated. 🙂

    Thanks.

    • This reply was modified 1 month, 1 week ago by  katiev.

    Version 18.4 has just been released. Check your updates. It’s not a PRO feature. The problem code is in the primary plugin. I have looked at the code in that version and verified it has been corrected.

    Plugin Author N-Media

    (@nmedia)

    Hi @katiev,

    Yes, we have fixed and released version 18.4.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.