Support » Plugin: WP-Live Chat by 3CX » Warning: Cannot assign an empty string to a string offset

  • Resolved Foxhounds

    (@foxhounds)


    Hi guys, unfortunately it comes to an error when running your plugin on our website http://www.450heartbeats.com

    It says:
    Warning: Cannot assign an empty string to a string offset in wp-includes/class.wp-scripts.php on line 447

    Do you know why?

    Thanks! Hubertus

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Jarryd

    (@jarryd-long)

    Hi Hubertus

    Thank you for getting in touch with us.

    Please confirm what version of the plugin is currently installed on your site, as well as what version of PHP is used on your web server?

    Can you share how this was resolved? I’m having the exact same error:
    ……/public_html/wp-includes/class.wp-scripts.php on line 447

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    This one is definitely not resolved with the current version. That said, I do have some insight from what I was able to track down.

    The line in question in the errors is from WordPress core and deals with localizing content for javascript. The plugin itself utilizes wp_localize_script() many times, but the code does not like empty strings for that, at least for some people as found here.

    The biggest thing is that simply sometimes, the variables being passed in to wp_localize_script() are empty strings, because no value ended up being assigned to them. I cleared one instance of the error by simply passing in a simple space.

    Use of some better defaults/fallbacks would be one way to handle this. I don’t know the plugin well enough to know what risks there may be with backwards compatibility there, though.

    The developers just need to add an !empty conditional for $value around line 443… I.e:

    		foreach ( (array) $l10n as $key => $value ) {
    			if ( !is_scalar($value) )
    				continue;
    
    			$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
    		}

    to…

    		foreach ( (array) $l10n as $key => $value ) {
    			if ( !is_scalar($value) )
    				continue;
    
    			if (!empty($value)) {
    				$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
    			}
    		}

    It’s generally not a good practice to modify core WP files. Dev needs to fix some syntax in their plugin code…

    After digging around, this error had something to do with WP Live Chat being network activated in Multisite. I network deactivated and activated on the local site and the error went away.

    There was progress with this error?

    We have the same problem on a multisite installation.
    No matter if network activated or on a single site.

    Warning: Cannot assign an empty string to a string offset in C:\xampp\htdocs\thelexiconart\wp-includes\class.wp-scripts.php on line 426
    After the plugin install how to resolve please suggest me.

    depodra solved my problem! genious!

    mikeyt

    (@miketurnermk)

    I’m not using multisite but have the same error but only when loading via my iphone. It doesn’t show on my desktop using Chrome

    What is the fix?

    Thanks depodra !

    Hi!

    I solved doing this:

    foreach ( (array) $l10n as $key => $value ) {
         if ( !is_scalar($value) || empty($value) )
            continue;
    
         $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
    }

    So, any not expected value is ignored.

    But that the best solution is, of course, to solve the problem in the plugin.

    Alexandra A.

    (@montenegroecoadventuresorg)

    Hi there, same problem again today with “Cannot assign an empty string to a string offset in …..\wp-includes\class.wp-scripts.php on line 426”

    @depodra, can you please be so kind to advise me what to do here?
    Do I need to edit the file through FTP and change the code?
    Thanks in advance!
    Alexandra A.

    Hi @montenegroecoadventuresorg – as @spiffyd mentioned previously this should be fixed by the plugin developers – sad to see 11 months on this hasn’t been resolved. If you fix your script and then update WordPress, your fix will be overwritten. However, as a temporary resolution to the error displaying:

    For WP 4.9.7:

    Login to your FTP,
    Navigate to /yourwebroot/wp-includes/ and open class.wp-scripts.php. Navigate to line 426:

    $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');

    Replace with:

    if (!empty($value)) { $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); }

    • This reply was modified 1 year, 10 months ago by depodra.
    • This reply was modified 1 year, 10 months ago by depodra.
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Warning: Cannot assign an empty string to a string offset’ is closed to new replies.