wp-includes/post.php:2965Sanitizes a post field based on context.
$fieldstring$valuemixed$post_idint$contextstringoptional'display'mixed9 hooks fire while sanitize_post_field() runs, in this order:
Filters the value of a specific post field to edit.
Filters the value of a specific post field to edit.
Filters the value of a specific post field to edit.
Filters the value of a specific post field before saving.
Filters the value of a specific field before saving.
Filters the value of a specific field before saving.
Filters the value of a specific post field before saving.
Filters the value of a specific post field for display.
Filters the value of a specific post field for display.
function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { $int_fields = array( 'ID', 'post_parent', 'menu_order' ); if ( in_array( $field, $int_fields, true ) ) { $value = (int) $value; } // Fields which contain arrays of integers. $array_int_fields = array( 'ancestors' ); if ( in_array( $field, $array_int_fields, true ) ) { $value = array_map( 'absint', $value ); return $value; } if ( 'raw' === $context ) { return $value; } $prefixed = false; if ( str_contains( $field, 'post_' ) ) { $prefixed = true; $field_no_prefix = str_replace( 'post_', '', $field ); } if ( 'edit' === $context ) { $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' ); if ( $prefixed ) { /** * Filters the value of a specific post field to edit. * * The dynamic portion of the hook name, `$field`, refers to the post * field name. Possible filter names include: * * - `edit_post_author` * - `edit_post_date` * - `edit_post_date_gmt` * - `edit_post_content` * - `edit_post_title` * - `edit_post_excerpt` * - `edit_post_status` * - `edit_post_password` * - `edit_post_name` * - `edit_post_modified` * - `edit_post_modified_gmt` * - `edit_post_content_filtered` * - `edit_post_parent` * - `edit_post_type` * - `edit_post_mime_type` * * @since 2.3.0 * * @param mixed $value Value of the post field. * @param int $post_id Post ID. */ $value = apply_filters( "edit_{$field}", $value, $post_id ); /** * Filters the value of a specific post field to edit. * * Only applied to post fields with a name which is prefixed with `post_`. * * The dynamic portion of the hook name, `$field_no_prefix`, refers to the * post field name minus the `post_` prefix. Possible filter names include: * * - `author_edit_pre` * - `date_edit_pre` * - `date_gmt_edit_pre` * - `content_edit_pre` * - `title_edit_pre` * - `excerpt_edit_pre` * - `status_edit_pre` * - `password_edit_pre` * - `name_edit_pre` * - `modified_edit_pre` * - `modified_gmt_edit_pre` * - `content_filtered_edit_pre` * - `parent_edit_pre` * - `type_edit_pre` * - `mime_type_edit_pre`Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.