我有一个本地化脚本,其中包含敏感信息,我不希望其他用户从控制台更改它。是否可以对象冻结我的本地化脚本?
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
));
最合适的回答,由SO网友:Jacob Peattie 整理而成
不,无法从wp_localize_script()
.
您需要添加添加Object.freeze( text_ajax );
到脚本的开头。