function sanitize_user_field($field, $value, $user_id, $context) {}

Sanitize user field based on context.
Possible context values are: ‘raw’, ‘edit’, ‘db’, ‘display’, ‘attribute’ and ‘js’. The ‘display’ context is used by default. ‘attribute’ and ‘js’ contexts are treated like ‘display’ when calling filters.


  • string $field: The user Object field name.
  • mixed $value: The user Object value.
  • int $user_id: user ID.
  • string $context: How to sanitize user fields. Looks for ‘raw’, ‘edit’, ‘db’, ‘display’, ‘attribute’ and ‘js’.

Return values

returns:Sanitized value.

Defined filters

  • edit_{$field}
    apply_filters("edit_{$field}", $value, $user_id)
  • edit_user_{$field}
    apply_filters("edit_user_{$field}", $value, $user_id)

Source code

function sanitize_user_field($field, $value, $user_id, $context) {

	$int_fields = array('ID');

	if ( in_array($field, $int_fields) )

		$value = (int) $value;

	if ( 'raw' == $context )

		return $value;

	if ( !is_string($value) && !is_numeric($value) )

		return $value;

	$prefixed = false;

	if ( false !== strpos($field, 'user_') ) {

		$prefixed = true;

		$field_no_prefix = str_replace('user_', '', $field);


	if ( 'edit' == $context ) {

		if ( $prefixed ) {

			$value = apply_filters("edit_{$field}", $value, $user_id);

		} else {

			$value = apply_filters("edit_user_{$field}", $value, $user_id);



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: