Astra_Customizer_Sanitizes::sanitize_alpha_color( string $color )

Sanitize Alpha color


Description


Parameters

$color

(string) (Required) setting input.


Return

(string) setting input value.


Source

File: inc/customizer/class-astra-customizer-sanitizes.php

		public static function sanitize_alpha_color( $color ) {

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

			// CSS variable value sanitize.
			if ( 0 === strpos( $color, 'var(--' ) ) {
				return preg_replace( '/[^A-Za-z0-9_)(\-,.]/', '', $color );
			}

			if ( false === strpos( $color, 'rgba' ) ) {
				/* Hex sanitize */
				return self::sanitize_hex_color( $color );
			}

			/* rgba sanitize */
			$color = str_replace( ' ', '', $color );
			sscanf( $color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );
			return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')';
		}


User Contributed Notes

You must log in before being able to contribute a note or feedback.