sanitize_bookmark

Sanitizes all bookmark fields.

Description

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

Returns (stdClass|array)

Same type as $bookmark but with fields sanitized.

Parameters (2)

0. $bookmark (stdClass|array)
The bookmark.
1. $context — Optional. (string) => 'display'
Optional, default is display.. How to filter the fields

Usage

  1. if ( !function_exists( 'sanitize_bookmark' ) ) { 
  2. require_once ABSPATH . WPINC . '/bookmark.php'; 
  3.  
  4. // The bookmark. 
  5. $bookmark = null; 
  6.  
  7. // Optional, default is 'display'. How to filter the 
  8. // fields 
  9. $context = 'display'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = sanitize_bookmark($bookmark, $context); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/bookmark.php  
  1. function sanitize_bookmark($bookmark, $context = 'display') { 
  2. $fields = array('link_id', 'link_url', 'link_name', 'link_image', 'link_target', 'link_category',  
  3. 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_updated',  
  4. 'link_rel', 'link_notes', 'link_rss', ); 
  5.  
  6. if ( is_object($bookmark) ) { 
  7. $do_object = true; 
  8. $link_id = $bookmark->link_id; 
  9. } else { 
  10. $do_object = false; 
  11. $link_id = $bookmark['link_id']; 
  12.  
  13. foreach ( $fields as $field ) { 
  14. if ( $do_object ) { 
  15. if ( isset($bookmark->$field) ) 
  16. $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $link_id, $context); 
  17. } else { 
  18. if ( isset($bookmark[$field]) ) 
  19. $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $link_id, $context); 
  20.  
  21. return $bookmark;