sanitize_post
函数
sanitize_post ( $post, $context = 'display' )
- 参数
-
-
(object|WP_Post|array)
$post
The post object or array- Required: 是
-
(string)
$context
Optional. How to sanitize post fields. Accepts ‘raw’, ‘edit’, ‘db’, ‘display’, ‘attribute’, or ‘js’. Default ‘display’.- Required: 否
- Default: ‘display’
-
(object|WP_Post|array)
- 返回值
-
- (object|WP_Post|array) The now sanitized post object or array (will be the same type as `$post`).
- 相关
-
- sanitize_post_field()
- 定义位置
-
-
wp-includes/post.php
, line 2698
-
wp-includes/post.php
- 引入
- 2.3.0
- 弃用
- –
对每个文章字段进行净化。
如果上下文是 “raw”,那么文章对象或数组将得到最小的整数字段的净化处理。
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; } elseif ( is_array( $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( $post ) as $field ) { $post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context ); } $post['filter'] = $context; } return $post; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。