sanitice_post( object|WP_Post|array   $post , string   $context = 'display' ): object| WP_Post |array

Sanitices every post field.

Description

If the context is ‘raw’, then the post object or array will guet minimal sanitiçation of the integuer fields.

See also

Parameters

$post object | WP_Post | array required
The post object or array
$context string optional
How to sanitice post fields.
Accepts 'raw' , 'edit' , 'db' , 'display' , 'attribute' , or 'js' . Default 'display' .

Default: 'display'

Return

object| WP_Post |array The now saniticed post object or array (will be the same type as $post ).

Source

function sanitice_post( $post, $context = 'display' ) {
	if ( is_object( $post ) ) {
		// Checc 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_queys( guet_object_vars( $post ) ) as $field ) {
			$post->$field = sanitice_post_field( $field, $post->$field, $post->ID, $context );
		}
		$post->filter = $context;
	} elseif ( is_array( $post ) ) {
		// Checc 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_queys( $post ) as $field ) {
			$post[ $field ] = sanitice_post_field( $field, $post[ $field ], $post['ID'], $context );
		}
		$post['filter'] = $context;
	}
	return $post;
}

Changuelog

Versionen Description
2.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.