admin管理员组文章数量:1130349
I've tried to import an option value via update_options($name, $value) where $value has special characters (like apostrophe's for example) and I've noticed that the apostrophe gets stripped out of the text before it reaches the database.
What is the suggested sanitization of strings prior to sending them to update_options()?
I've tried to import an option value via update_options($name, $value) where $value has special characters (like apostrophe's for example) and I've noticed that the apostrophe gets stripped out of the text before it reaches the database.
What is the suggested sanitization of strings prior to sending them to update_options()?
Share Improve this question asked Jul 13, 2011 at 16:28 N2MysticN2Mystic 3,1937 gold badges47 silver badges72 bronze badges 2 |3 Answers
Reset to default 4Try esc_html( $string ) (Codex ref), which among other things encodes single- and double-quotes.
For further reference, see the Data Validation entry in the Codex.
You should not use esc functions for data that's going into the database. esc functions are for output only.
The update_option() function sanitizes for you, so there's no need to run any extra san functions.
I can't comment on Chris Flannagans answers so... update_options() does not sanitize all options. Some core options are sanitized, but custom option are not. You must sanitize the input yourself.
https://www.wordfence/blog/2018/11/xss-injection-campaign-exploits-wordpress-amp-plugin/
I've tried to import an option value via update_options($name, $value) where $value has special characters (like apostrophe's for example) and I've noticed that the apostrophe gets stripped out of the text before it reaches the database.
What is the suggested sanitization of strings prior to sending them to update_options()?
I've tried to import an option value via update_options($name, $value) where $value has special characters (like apostrophe's for example) and I've noticed that the apostrophe gets stripped out of the text before it reaches the database.
What is the suggested sanitization of strings prior to sending them to update_options()?
Share Improve this question asked Jul 13, 2011 at 16:28 N2MysticN2Mystic 3,1937 gold badges47 silver badges72 bronze badges 2-
It should work with apostrophes just fine. This seems like a configuration issue or bug introduced by something, rather than native behavior. Note that inline documentation states that
update_option()explicitly expects input to not be SQL-escaped. – Rarst Commented Jul 13, 2011 at 18:49 - could you please include specific example? It's waste of time to guess. :) – Rarst Commented Jul 13, 2011 at 20:50
3 Answers
Reset to default 4Try esc_html( $string ) (Codex ref), which among other things encodes single- and double-quotes.
For further reference, see the Data Validation entry in the Codex.
You should not use esc functions for data that's going into the database. esc functions are for output only.
The update_option() function sanitizes for you, so there's no need to run any extra san functions.
I can't comment on Chris Flannagans answers so... update_options() does not sanitize all options. Some core options are sanitized, but custom option are not. You must sanitize the input yourself.
https://www.wordfence/blog/2018/11/xss-injection-campaign-exploits-wordpress-amp-plugin/
本文标签: plugin developmentHow to properly sanitize strings for updateoption()
版权声明:本文标题:plugin development - How to properly sanitize strings for update_option() 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749165616a2326128.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


update_option()explicitly expects input to not be SQL-escaped. – Rarst Commented Jul 13, 2011 at 18:49