sanitize_bookmark

函数
sanitize_bookmark ( $bookmark, $context = 'display' )
参数
  • (stdClass|array) $bookmark Bookmark row.
    Required:
  • (string) $context Optional. How to filter the fields. Default 'display'.
    Required:
    Default: 'display'
返回值
  • (stdClass|array) Same type as $bookmark but with fields sanitized.
定义位置
相关方法
sanitize_bookmark_fieldsanitize_metasanitize_emailsanitize_keysanitize_option
引入
2.3.0
弃用
-

sanitize_bookmark: 这是一个WordPress的函数,用于净化书签的URL,删除任何潜在的危险字符或代码: 该函数用于确保用户输入的书签URL可以安全使用。

对所有书签字段进行净化。

function sanitize_bookmark( $bookmark, $context = 'display' ) {
	$fields = array(
		'link_id',
		'link_url',
		'link_name',
		'link_image',
		'link_target',
		'link_category',
		'link_description',
		'link_visible',
		'link_owner',
		'link_rating',
		'link_updated',
		'link_rel',
		'link_notes',
		'link_rss',
	);

	if ( is_object( $bookmark ) ) {
		$do_object = true;
		$link_id   = $bookmark->link_id;
	} else {
		$do_object = false;
		$link_id   = $bookmark['link_id'];
	}

	foreach ( $fields as $field ) {
		if ( $do_object ) {
			if ( isset( $bookmark->$field ) ) {
				$bookmark->$field = sanitize_bookmark_field( $field, $bookmark->$field, $link_id, $context );
			}
		} else {
			if ( isset( $bookmark[ $field ] ) ) {
				$bookmark[ $field ] = sanitize_bookmark_field( $field, $bookmark[ $field ], $link_id, $context );
			}
		}
	}

	return $bookmark;
}

常见问题

FAQs
查看更多 >