sanitize_bookmark_field() - WordPress 函数参考中文文档

返回介绍

sanitize_bookmark_field()

发布于 2017-09-11 字数4347 浏览 927 评论 0

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

Sanitizes a bookmark field.


描述

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

更新日志

Version 描述
2.3.0 Introduced.

相关函数

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

上一篇:sanitize_bookmark()

下一篇:sanitize_category()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!