返回介绍

sanitize_bookmark_field()

发布于 2017-09-11 10:17:51 字数 4345 浏览 1046 评论 0 收藏 0

sanitize_bookmark_field( string $field,  mixed $value,  int $bookmark_id,  string $context )

Sanitizes a bookmark field.


description

Sanitizes the bookmark fields based on what the field name is. If the field has a strict value set, then it will be tested for that, else a more generic filtering is applied. After the more strict filter is applied, if the $context is ‘raw’ then the value is immediately return.

Hooks exist for the more generic cases. With the ‘edit’ context, the ‘edit_$field’ filter will be called and passed the $value and $bookmark_id respectively.

With the ‘db’ context, the ‘pre_$field’ filter is called and passed the value. The ‘display’ context is the final context and has the $field has the filter name and is passed the $value, $bookmark_id, and $context, respectively.


参数

$field

(string) (Required) The bookmark field.

$value

(mixed) (Required) The bookmark field value.

$bookmark_id

(int) (Required) Bookmark ID.

$context

(string) (Required) How to filter the field value. Accepts 'raw', 'edit', 'attribute', 'js', 'db', or 'display'


返回值

(mixed) The filtered value.


源代码

File: wp-includes/bookmark.php

function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) {
	switch ( $field ) {
	case 'link_id' : // ints
	case 'link_rating' :
		$value = (int) $value;
		break;
	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) )
			$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 );
		}
	}

	return $value;
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: esc_html()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/formatting.php: esc_js()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: edit_{$field}
  • wp-includes/post.php: pre_{$field}
  • wp-includes/post.php: {$field}
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/deprecated.php: get_links()
  • wp-includes/deprecated.php: get_linkrating()
  • wp-includes/bookmark-template.php: _walk_bookmarks()
  • wp-includes/bookmark.php: sanitize_bookmark()
  • wp-includes/bookmark.php: get_bookmark_field()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文