sanitize_user_field example

if ( isset( $this->data->$key ) ) {
            $value = $this->data->$key;
        } else {
            if ( isset( self::$back_compat_keys[ $key ] ) ) {
                $key = self::$back_compat_keys[ $key ];
            }
            $value = get_user_meta( $this->ID, $key, true );
        }

        if ( $this->filter ) {
            $value = sanitize_user_field( $key$value$this->ID, $this->filter );
        }

        return $value;
    }

    /** * Magic method for setting custom user fields. * * This method does not update custom fields in the database. It only stores * the value on the WP_User instance. * * @since 3.3.0 * * @param string $key User meta key. * @param mixed $value User meta value. */

function sanitize_user_object($user$context = 'display') {
    _deprecated_function( __FUNCTION__, '3.3.0' );

    if ( is_object($user) ) {
        if ( !isset($user->ID) )
            $user->ID = 0;
        if ( ! ( $user instanceof WP_User ) ) {
            $vars = get_object_vars($user);
            foreach ( array_keys($vars) as $field ) {
                if ( is_string($user->$field) || is_numeric($user->$field) )
                    $user->$field = sanitize_user_field($field$user->$field$user->ID, $context);
            }
        }
        $user->filter = $context;
    } else {
        if ( !isset($user['ID']) )
            $user['ID'] = 0;
        foreach ( array_keys($user) as $field )
            $user[$field] = sanitize_user_field($field$user[$field]$user['ID']$context);
        $user['filter'] = $context;
    }

    
Home | Imprint | This part of the site doesn't use cookies.