Advertisements

sanitize_post

Definition:
function sanitize_post($post, $context = 'display') {}

Sanitize every post field.
If the context is ‘raw’, then the post object or array will get minimal santization of the int fields.

Parameters

  • object|array $post: The Post Object or Array
  • string $context: Optional, default is ‘display’. How to sanitize post fields.

Return values

returns:The now sanitized Post Object or Array (will be the same type as $post)

Source code

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;

	} else {

		// 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;

}

2779

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: