消毒每个岗位。
原型
sanitize_post( object|WP_Post|array $post, string $context = 'display' )
描述
如果上下文是’raw’,那么post对象或数组将获得整数字段的最小清理。
参考:
- sanitize_post_field()
参数
$post
(object|WP_Post|array)
(Required)
邮政对象或数组
$context
(string)
(Optional)
如何清理邮政领域。接受’raw’,‘edit’,‘db’或’display’。
返回值
(object|WP_Post|array)
现在已清理的Post对象或数组(与$ post的类型相同)。
源文件
路径:wp-includes/post.php
<?php
...
function sanitize_post( $post, $context = 'display' ) {
if ( is_object($post) ) {
// Check if post already filtered for this context.
if ( isset($post->filter) && $context == $post->filter )
return $post;
if ( !isset($post->ID) )
$post->ID = 0;
foreach ( array_keys(get_object_vars($post)) as $field )
$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
$post->filter = $context;
} elseif ( is_array( $post ) ) {
// Check if post already filtered for this context.
if ( isset($post['filter']) && $context == $post['filter'] )
return $post;
if ( !isset($post['ID']) )
$post['ID'] = 0;
foreach ( array_keys($post) as $field )
$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
$post['filter'] = $context;
}
return $post;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/sanitize_post/