Cas*_*asi 1 validation wordpress sanitization
嗨,我的问题是如何正确清理包含 html 的输入字段。现在我这样做:
if( isset( $_POST[ 'obecnie' ] ) ) {
update_post_meta( $post_id, 'obecnie', sanitize_text_field($_POST['obecnie' ]));
}
sanitize_text_field 是一个 Wordpress 函数,它从输入中删除所有 html。我需要实现的实际上是允许用户在输入中插入中断标记或新行实体并在前端显示它。
wp_kses从字符串中去除HTML 标签和属性,除了您调用它时列入白名单的那些。
例如,只允许带有 href 属性的 br 标签和链接(但不允许其他标签和链接,甚至没有样式或标题),您可以这样称呼它:
$allowed_html = array(
'a' => array(
'href' => array(),
),
'br' => array(),
);
$str = wp_kses( $str, $allowed_html );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3954 次 |
| 最近记录: |