wp/wp-includes/bookmark.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    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;
   443 		} elseif ( 'js' === $context ) {
   444 		} elseif ( 'js' === $context ) {
   444 			$value = esc_js( $value );
   445 			$value = esc_js( $value );
   445 		}
   446 		}
   446 	}
   447 	}
   447 
   448 
       
   449 	// Restore the type for integer fields after esc_attr().
       
   450 	if ( in_array( $field, $int_fields, true ) ) {
       
   451 		$value = (int) $value;
       
   452 	}
       
   453 
   448 	return $value;
   454 	return $value;
   449 }
   455 }
   450 
   456 
   451 /**
   457 /**
   452  * Deletes the bookmark cache.
   458  * Deletes the bookmark cache.