Getting notice is wordpress "WP_Scripts:was called incorrectly"

Complete message: Notice: WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array. To pass arbitrary data to scripts, use the wp_add_inline_script() function instead. Please see Debugging in WordPress for more information. (This message was added in version 5.7.0.) in /home3/dduconne/public_html/wp-includes/functions.php on line 5313

Appeared just after updating wordpress to 5.7.0

Solutions

This is a new warning appearing in Wordpress 5.7. If you don't want to see it, and still want to have WP_DEBUG set to true, it is possible to disable the message by adding the following for example in your theme's functions.php:

 add_filter('doing_it_wrong_trigger_error', function () {return false;}, 10, 0);

Ok since there quite a few views and the previous answer just throws it under the rug.

Yes it is a warning now, but who knows what will happen, it is a warning for a reason, disabling something is not resolving it, there is a reason devs set it as a warning for now.

While we wait for plugin developers to resolve it on their ends, you can find out the source of the problem by enabling php_xdebug in php. I recommend not leaving it after debugging, as I am not sure about the performance cost of it being enabled.

php_xdebug will return a stack of all files affected, from there you can trace it to the source of the problem. The fix once found the source is quite easy. Culprit most likely is wp_localize_script() which requires last parameter to be an array() !

So you would find something like this:

wp_localize_script( 'handle', 'object_name', 'l10n_culprit_string' );

Which should be turned into:

wp_localize_script( 'handle', 'object_name', array( 'l10n_culprit_string' ) );

Solution to problem came from here

It is now a notice if you are using wp5.7 and php7.4, but changing to php8 it may gets reported as error. For me, when i changed (in my own code) the passed value to array (yes, probably some changes also needed in the involved js), everything worked just fine.

Similar questions

Notice: Undefined index: error and understanding wordpress
I am trying to create custom post types with wordpress 4. I followed a tutorial book called "Buildin Wordpress Themes From Scratch". I am on localhost so debug mode is on. When I try create a new CPT, I get the form but still I get undefined index errors on source, author and date. I tried to solve by checking array index but it did not solve eithe...
Wordpress custom widget undefined variable notice
I am developing a theme and I have created a custom widget for it. When I turn on debug mode I get the following notices, This is the contents of the widget file, I think I have to set a default variable for those fields, but I am not sure how to do it? Any ideas?
PHP notice coming from the WordPress core?
Do you also experience this particular notice? ( Of course one has to turn on the DEBUG mode at the wp-config.php to be able to see this kind of a notice ). Since this is coming from one of the core files, it has puzzled me as how it made it to production as such or I'm reading this entire thing in a wrong way.
Wordpress admin notice in plugin function
i have sample wordpress plugin class. Im hooking woocommerce woocommerce_saved_order_items and i want create a admin notice. Add action from __construct works, but when i want create a notice in hook function it doesnt appears, where is the problem?
Is there a plugin to have DMCA takedown notice form in Wordpress?
I was looking to do something like this in Wordpress: https://www.mysavings.com/removal-request.asp But I can't find any plugin that makes that. I hope you can help me with ideas. Thanks in advance.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .