wpseek.com
WordPress开发者和主题制作者的搜索引擎
sanitize_post › WordPress Function
Since2.3.0
已弃用n/a
› sanitize_post ( $post, $context = 'display' )
| 参数: (2) |
|
| 查看: | |
| 返回: |
|
| 定义在: |
|
| 文档: |
Sanitizes every post field.
If the context is 'raw', then the post object or array will get minimal sanitization of the integer fields.Related Functions: sanitize_post_field, sanitize_option, sanitize_meta, sanitize_term, sanitize_user
源码
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, (int) $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 ], (int) $post['ID'], $context );
}
$post['filter'] = $context;
}
return $post;
}