Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




sanitize_post [ WordPress Function ]

sanitize_post ( $post, $context = 'display' )
Parameters:
  • (object|array) $post The Post Object or Array
  • (string) $context Optional, default is 'display'. How to sanitize post fields.
Uses:
Returns:
  • (object|array) The now sanitized Post Object or Array (will be the same type as $post)
Defined at:



Sanitize every post field.

If the context is 'raw', then the post object or array will get minimal santization of the int fields.

Source


<?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;
    } 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;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics