admin管理员组文章数量:1122846
I'm trying to fix up my code to meet the WordPress VIP Coding Standards. I'm getting a couple of issues that I'd like to see go away, but i'm not sure what the best strategy is.
The first issue is when i'm verifying a nonce while saving metabox data:
$nonce = isset( $_POST['revv_meta_box_nonce'] ) ? $_POST['revv_meta_box_nonce'] : '';
The error i'm getting here is 'Processing data without nonce verification'
. Which is pretty silly since i'm just storing the nonce in a variable, which I am then verifying on the next line.
The second issue is when i'm storing the data:
$foo = isset($_POST['foo']) ? sanitize_text_field( $_POST['foo'] ) : '';
update_post_meta( $post_id, '_foo', $foo );
On the first line there, the sniffer is complaining that i'm not running wp_unslash
on the data before sanitizing it. But the data is going directly into update_post_meta
on the next line, which expects that data to not be unslashed.
Any ideas on the best strategy for getting rid of these error messages? Thanks!
I'm trying to fix up my code to meet the WordPress VIP Coding Standards. I'm getting a couple of issues that I'd like to see go away, but i'm not sure what the best strategy is.
The first issue is when i'm verifying a nonce while saving metabox data:
$nonce = isset( $_POST['revv_meta_box_nonce'] ) ? $_POST['revv_meta_box_nonce'] : '';
The error i'm getting here is 'Processing data without nonce verification'
. Which is pretty silly since i'm just storing the nonce in a variable, which I am then verifying on the next line.
The second issue is when i'm storing the data:
$foo = isset($_POST['foo']) ? sanitize_text_field( $_POST['foo'] ) : '';
update_post_meta( $post_id, '_foo', $foo );
On the first line there, the sniffer is complaining that i'm not running wp_unslash
on the data before sanitizing it. But the data is going directly into update_post_meta
on the next line, which expects that data to not be unslashed.
Any ideas on the best strategy for getting rid of these error messages? Thanks!
Share Improve this question asked Jan 16, 2016 at 12:22 dabernathy89dabernathy89 213 bronze badges 3 |1 Answer
Reset to default 0You can use filter_input
to sanitize your $_POST
array.
$nonce = filter_input( INPUT_POST, 'revv_meta_box_nonce', FILTER_SANITIZE_STRING )
use empty()
to check $nonce
has a value or not.
You can use the same for second issue
$foo = filter_input( INPUT_POST, 'foo', FILTER_SANITIZE_STRING )
change 3rd parameter based on your expected data in $_POST['foo']
. check this doc for available filters.
本文标签: securityPHP Code SnifferWordPress VIP Coding Standards
版权声明:本文标题:security - PHP Code Sniffer - WordPress VIP Coding Standards 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287803a1927960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
*_post_meta
functions do not expect the data slashed (it will be escaped at point of db insertion). – TheDeadMedic Commented Jan 17, 2016 at 19:09