sanitize_post_field [ WordPress Function ]
sanitize_post_field ( $field, $value, $post_id, $context )
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: sanitize_term_field, sanitize_user_field, sanitize_text_field, sanitize_post, sanitize_bookmark_field
Sanitize post field based on context.
Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' when calling filters.
Source
<?php
function sanitize_post_field($field, $value, $post_id, $context) {
$int_fields = array('ID', 'post_parent', 'menu_order');
if ( in_array($field, $int_fields) )
$value = (int) $value;
// Fields which contain arrays of ints.
$array_int_fields = array( 'ancestors' );
if ( in_array($field, $array_int_fields) ) {
$value = array_map( 'absint', $value);
return $value;
}
if ( 'raw' == $context )
return $value;
$prefixed = false;
if ( false !== strpos($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 ) {
$value = apply_filters("edit_{$field}", $value, $post_id);
// Old school
$value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id);
} else {
$value = apply_filters("edit_post_{$field}", $value, $post_id);
}
if ( in_array($field, $format_to_edit) ) {
if ( 'post_content' == $field )
$value = format_to_edit($value, user_can_richedit());
else
$value = format_to_edit($value);
} else {
$value = esc_attr($value);
}
} else if ( 'db' == $context ) {
if ( $prefixed ) {
$value = apply_filters("pre_{$field}", $value);
$value = apply_filters("{$field_no_prefix}_save_pre", $value);
} else {
$value = apply_filters("pre_post_{$field}", $value);
$value = apply_filters("{$field}_pre", $value);
}
} else {
// Use display filters by default.
if ( $prefixed )
$value = apply_filters($field, $value, $post_id, $context);
else
$value = apply_filters("post_{$field}", $value, $post_id, $context);
}
if ( 'attribute' == $context )
$value = esc_attr($value);
else if ( 'js' == $context )
$value = esc_js($value);
return $value;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- sanitize_post_field (WordPress Function) - WPSeek.com
WordPress lookup for sanitize_post_field, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - #7422 (pass $post_id to filters in sanitize_post_field() on post ...
the function sanitize_post_field in wp-includes/post.php calls most of the " database writes" post filters (e.g. content_save_pre). if a post is updated or created, the ...
core.trac.wordpress.org - Function Reference/sanitize post field « WordPress Codex
Description. Sanitize a post field based on the context of where the field is being used. Usage. Parameters. $field: (string) (required) The post object field name ...
codex.wordpress.org - PHPXRef 0.7 : WordPress : Function Reference: sanitize_post_field()
sanitize_post_field(). Defined at: /wp-includes/post.php -> line 1698. Referenced 7 times: /wp-includes/post.php -> line 478 · /wp-includes/post.php -> line 1400 ...
phpxref.ftwr.co.uk