sanitize_bookmark() WordPress Function

The sanitize_bookmark() function is a built-in WordPress function that is used to clean up bookmark data before it is saved to the database. This function is called when a user adds or edits a bookmark in the WordPress admin interface. The sanitize_bookmark() function takes two arguments: the $bookmark data to be sanitized, and an array of options (optional). The $bookmark data is an array of data for the bookmark being saved. The options array can be used to specify how the data should be sanitized. The sanitize_bookmark() function sanitizes the $bookmark data by stripping tags and attributes that are not allowed in WordPress. It also converts all relative URLs to absolute URLs. The sanitize_bookmark() function returns a sanitized array of data for the bookmark. This sanitized data can then be saved to the database.

sanitize_bookmark( stdClass|array $bookmark, string $context = 'display' ) #

Sanitizes all bookmark fields.


Parameters

$bookmark

(stdClass|array)(Required)Bookmark row.

$context

(string)(Optional) How to filter the fields.

Default value: 'display'


Top ↑

Return

(stdClass|array) Same type as $bookmark but with fields sanitized.


Top ↑

Source

File: wp-includes/bookmark.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.