sanitize_bookmark_field
函数
sanitize_bookmark_field ( $field, $value, $bookmark_id, $context )
- 参数
-
-
(string)
$field
The bookmark field.- Required: 是
-
(mixed)
$value
The bookmark field value.- Required: 是
-
(int)
$bookmark_id
Bookmark ID.- Required: 是
-
(string)
$context
How to filter the field value. Accepts ‘raw’, ‘edit’, ‘db’, ‘display’, ‘attribute’, or ‘js’. Default ‘display’.- Required: 是
-
(string)
- 返回值
-
- (mixed) The filtered value.
- 定义位置
-
-
wp-includes/bookmark.php
, line 398
-
wp-includes/bookmark.php
- 引入
- 2.3.0
- 弃用
- –
净化一个书签字段。
根据字段的名称对书签字段进行消毒。如果该字段有一个严格的值设置,那么它将被测试,否则将应用一个更通用的过滤。在应用了更严格的过滤后,如果`$context`是’raw’,那么该值将立即返回。
钩子存在于更通用的情况下。在’edit’上下文中,{@see ‘edit_$field’}过滤器将被调用并分别传递`$value’和`$bookmark_id’。
在’db’上下文中,{@see ‘pre_$field’}过滤器会被调用并传递值。’display’上下文是最终的上下文,`$field’有过滤器名称,并分别传递`$value’、`$bookmark_id’和`$context’。
function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { $int_fields = array( 'link_id', 'link_rating' ); if ( in_array( $field, $int_fields, true ) ) { $value = (int) $value; } switch ( $field ) { case 'link_category': // array( ints ) $value = array_map( 'absint', (array) $value ); // We return here so that the categories aren't filtered. // The 'link_category' filter is for the name of a link category, not an array of a link's link categories. return $value; case 'link_visible': // bool stored as Y|N $value = preg_replace( '/[^YNyn]/', '', $value ); break; case 'link_target': // "enum" $targets = array( '_top', '_blank' ); if ( ! in_array( $value, $targets, true ) ) { $value = ''; } break; } if ( 'raw' === $context ) { return $value; } if ( 'edit' === $context ) { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "edit_{$field}", $value, $bookmark_id ); if ( 'link_notes' === $field ) { $value = esc_html( $value ); // textarea_escaped } else { $value = esc_attr( $value ); } } elseif ( 'db' === $context ) { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "pre_{$field}", $value ); } else { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "{$field}", $value, $bookmark_id, $context ); if ( 'attribute' === $context ) { $value = esc_attr( $value ); } elseif ( 'js' === $context ) { $value = esc_js( $value ); } } // Restore the type for integer fields after esc_attr(). if ( in_array( $field, $int_fields, true ) ) { $value = (int) $value; } return $value; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。