Function WP_Scripts::localize was called incorrectly

Discussion in 'PHP' started by Divvy, Nov 16, 2023.

  1. #1
    Can someone help me fix this error, please?
    I know that the plugin snax is the one responsable, but I don't know what to look for...

        Function 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. (This message was added in version 5.7.0.)
    
        WP_Scripts->localize()
        wp-includes/class-wp-scripts.php:605
        wp_localize_script()
        wp-includes/functions.wp-scripts.php:234
        snax_collection_enqueue_scripts()
        wp-content/plugins/snax/includes/collections/functions.php:157
        do_action('wp_enqueue_scripts')
        wp-includes/plugin.php:517
        wp_enqueue_scripts()
        wp-includes/script-loader.php:2262
        do_action('wp_head')
        wp-includes/plugin.php:517
        wp_head()
        wp-includes/general-template.php:3052
        load_template('wp-content/themes/wp-theme/header.php')
        wp-includes/template.php:790
        locate_template()
        wp-includes/template.php:725
        get_header()
        wp-includes/general-template.php:48
    Code (markup):
    Line 157 from wp-content/plugins/snax/includes/collections/functions.php:157

        wp_localize_script( 'snax-collections', 'snax_collections_js_config', wp_json_encode( $config ) );
    Code (markup):
    value of $config:

        $config = array(
        'ajax_url'  => admin_url( 'admin-ajax.php' ),
        'home_url'  => home_url(),
        'user_id'   => get_current_user_id(),
        'post_id'   => apply_filters( 'snax_can_be_stored_in_history', is_single() ) ? get_the_ID() : 0,
        'nonce'     => wp_create_nonce( 'snax-collection-add' ),
        'history'   => snax_is_history_collection_activated() ? 'on' : 'off',
        'i18n'      => array(
        'are_you_sure_remove'    => _x( 'Entire collection with all items will be removed. Proceed?', 'Collection action message', 'snax' ),
        'are_you_sure_clear_all' => _x( 'All collection items will be removed. Proceed?', 'Collection action message', 'snax' ),
        'removed'                => _x( 'Collection has been successfully removed', 'Collection action message', 'snax' ),
        'removing_items'         => _x( 'Removing collection items...', 'Collection action message', 'snax' ),
        ),);
    Code (markup):
    Thank you in advance
     
    Divvy, Nov 16, 2023 IP