sanitize_hex_color example


function sanitize_hex_color_no_hash( $color ) {
    $color = ltrim( $color, '#' );

    if ( '' === $color ) {
        return '';
    }

    return sanitize_hex_color( '#' . $color ) ? $color : null;
}

/** * Ensures that any hex color is properly hashed. * Otherwise, returns value untouched. * * This method should only be necessary if using sanitize_hex_color_no_hash(). * * @since 3.4.0 * * @param string $color * @return string */
if ( 'boolean' === $args['type'] ) {
        return rest_sanitize_boolean( $value );
    }

    // This behavior matches rest_validate_value_from_schema().     if ( isset( $args['format'] )
        && ( ! isset( $args['type'] ) || 'string' === $args['type'] || ! in_array( $args['type']$allowed_types, true ) )
    ) {
        switch ( $args['format'] ) {
            case 'hex-color':
                return (string) sanitize_hex_color( $value );

            case 'date-time':
                return sanitize_text_field( $value );

            case 'email':
                // sanitize_email() validates, which would be unexpected.                 return sanitize_text_field( $value );

            case 'uri':
                return sanitize_url( $value );

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