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'
Return
(stdClass|array) Same type as $bookmark but with fields sanitized.
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;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |