What’s $object->filter for?

The $post->filter contains the context under which the contents of the post have been filtered. Context could be something like “display” indicating the post is meant to be displayed on the page.

This is done by the sanitization functions, to indicate under what context the post data was sanitized. Different contexts get different types of sanitization. “raw”, for example, is unsanitized data. “display” has probably gone through the esc_html function, or whatever is relevant for that context. The sanitize_post() function uses this to check for pre-existing sanitizations, in order to prevent double escaping things and so forth.

One other use for the $post->filter is in the get_sample_permalink() function. You’ll find that it sets the $post->filter="sample" before calling get_permalink(). The use of “sample” here indicates to the get_permalink function, and to code below it, that the purpose of this call is to create a sample permalink for displaying on the edit post screen. This will change the way some of the functions below it work.

Leave a Comment