How to Object.freeze wp_localize_script

I have a localize script that have sensitive information that i dont want other users change it from the console.
is it possible to Object freeze my localized script?

        wp_localize_script('test-script', 'test_ajax', array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('test-nonce'),
            'action_thanks' => ACTION_THANKS,
            'univ_short_name' => UNIV_SHORT_NAME,
            'action_general' => ACTION_GENERAL,
            'action_catalog' => ACTION_CATALOG,
            'action_ebook' => ACTION_EBOOK,
            'university_id' => UNIVERSITY_ID,
            // in js needs to be converted to bool
            'is_sf' => IS_SF
        ));

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

No, it is not possible to do this from wp_localize_script().

You would need to add add Object.freeze( text_ajax ); to the beginning of your script.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x