sanitize_bookmark_field

Sanitizes a bookmark field.

Description

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

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 filter will be called and passed the $value and $bookmark_id respectively.

With the db context, the 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.

Parameters (4)

0. $field (string)
The bookmark field.
1. $value (mixed)
The bookmark field value.
2. $bookmark_id (int)
The bookmark id.
3. $context (string)
How to filter the field value. Accepts raw,, edit, attribute, js, db, or display

Usage

  1. if ( !function_exists( 'sanitize_bookmark_field' ) ) { 
  2. require_once ABSPATH . WPINC . '/bookmark.php'; 
  3.  
  4. // The bookmark field. 
  5. $field = ''; 
  6.  
  7. // The bookmark field value. 
  8. $value = null; 
  9.  
  10. // The bookmark id. 
  11. $bookmark_id = -1; 
  12.  
  13. // How to filter the field value. Accepts 'raw', 'edit', 'attribute', 
  14. // 'js', 'db', or 'display' 
  15. $context = ''; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = sanitize_bookmark_field($field, $value, $bookmark_id, $context); 
  19.  

Defined (1)

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

/wp-includes/bookmark.php  
  1. function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { 
  2. switch ( $field ) { 
  3. case 'link_id' : // ints 
  4. case 'link_rating' : 
  5. $value = (int) $value; 
  6. break; 
  7. case 'link_category' : // array( ints ) 
  8. $value = array_map('absint', (array) $value); 
  9. // We return here so that the categories aren't filtered. 
  10. // The 'link_category' filter is for the name of a link category, not an array of a link's link categories 
  11. return $value; 
  12.  
  13. case 'link_visible' : // bool stored as Y|N 
  14. $value = preg_replace('/[^YNyn]/', '', $value); 
  15. break; 
  16. case 'link_target' : // "enum" 
  17. $targets = array('_top', '_blank'); 
  18. if ( ! in_array($value, $targets) ) 
  19. $value = ''; 
  20. break; 
  21.  
  22. if ( 'raw' == $context ) 
  23. return $value; 
  24.  
  25. if ( 'edit' == $context ) { 
  26. /** This filter is documented in wp-includes/post.php */ 
  27. $value = apply_filters( "edit_$field", $value, $bookmark_id ); 
  28.  
  29. if ( 'link_notes' == $field ) { 
  30. $value = esc_html( $value ); // textarea_escaped 
  31. } else { 
  32. $value = esc_attr($value); 
  33. } elseif ( 'db' == $context ) { 
  34. /** This filter is documented in wp-includes/post.php */ 
  35. $value = apply_filters( "pre_$field", $value ); 
  36. } else { 
  37. /** This filter is documented in wp-includes/post.php */ 
  38. $value = apply_filters( $field, $value, $bookmark_id, $context ); 
  39.  
  40. if ( 'attribute' == $context ) { 
  41. $value = esc_attr( $value ); 
  42. } elseif ( 'js' == $context ) { 
  43. $value = esc_js( $value ); 
  44.  
  45. return $value;