51 return $_bookmark; |
51 return $_bookmark; |
52 } |
52 } |
53 |
53 |
54 $_bookmark = sanitize_bookmark( $_bookmark, $filter ); |
54 $_bookmark = sanitize_bookmark( $_bookmark, $filter ); |
55 |
55 |
56 if ( OBJECT == $output ) { |
56 if ( OBJECT === $output ) { |
57 return $_bookmark; |
57 return $_bookmark; |
58 } elseif ( ARRAY_A == $output ) { |
58 } elseif ( ARRAY_A === $output ) { |
59 return get_object_vars( $_bookmark ); |
59 return get_object_vars( $_bookmark ); |
60 } elseif ( ARRAY_N == $output ) { |
60 } elseif ( ARRAY_N === $output ) { |
61 return array_values( get_object_vars( $_bookmark ) ); |
61 return array_values( get_object_vars( $_bookmark ) ); |
62 } else { |
62 } else { |
63 return $_bookmark; |
63 return $_bookmark; |
64 } |
64 } |
65 } |
65 } |
389 * @since 2.3.0 |
389 * @since 2.3.0 |
390 * |
390 * |
391 * @param string $field The bookmark field. |
391 * @param string $field The bookmark field. |
392 * @param mixed $value The bookmark field value. |
392 * @param mixed $value The bookmark field value. |
393 * @param int $bookmark_id Bookmark ID. |
393 * @param int $bookmark_id Bookmark ID. |
394 * @param string $context How to filter the field value. Accepts 'raw', 'edit', 'attribute', |
394 * @param string $context How to filter the field value. Accepts 'raw', 'edit', 'db', |
395 * 'js', 'db', or 'display' |
395 * 'display', 'attribute', or 'js'. Default 'display'. |
396 * @return mixed The filtered value. |
396 * @return mixed The filtered value. |
397 */ |
397 */ |
398 function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { |
398 function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { |
|
399 $int_fields = array( 'link_id', 'link_rating' ); |
|
400 if ( in_array( $field, $int_fields, true ) ) { |
|
401 $value = (int) $value; |
|
402 } |
|
403 |
399 switch ( $field ) { |
404 switch ( $field ) { |
400 case 'link_id': // ints |
|
401 case 'link_rating': |
|
402 $value = (int) $value; |
|
403 break; |
|
404 case 'link_category': // array( ints ) |
405 case 'link_category': // array( ints ) |
405 $value = array_map( 'absint', (array) $value ); |
406 $value = array_map( 'absint', (array) $value ); |
406 // We return here so that the categories aren't filtered. |
407 // We return here so that the categories aren't filtered. |
407 // The 'link_category' filter is for the name of a link category, not an array of a link's link categories. |
408 // The 'link_category' filter is for the name of a link category, not an array of a link's link categories. |
408 return $value; |
409 return $value; |