Uses
| Uses | Description |
|---|---|
| wp-includes/post.php: sanitize_post_field() | Sanitizes a post field based on context. |
Sanitize every post field.
If the context is ‘raw’, then the post object or array will get minimal sanitization of the integer fields.
(object|WP_Post|array) (Required) The Post Object or Array
(string) (Optional) How to sanitize post fields. Accepts 'raw', 'edit', 'db', or 'display'.
Default value: 'display'
(object|WP_Post|array) The now sanitized Post Object or Array (will be the same type as $post).
File: wp-includes/post.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;
} | Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/sanitize_post