wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_sanitize_block_gap_value › WordPress Function

Depuis7.1.0
Dépréciéen/a
› wp_sanitize_block_gap_value ( $gap_value )
Paramètres:
  • (mixed) $gap_value Block gap value.
    Requis: Oui
Retourne:
  • (string|string[]|null) Sanitized block gap value.
Défini(e) dans:
Codex:
Changelog:
  • Numeric

Sanitizes a block gap value before layout style generation.



Source

function wp_sanitize_block_gap_value( $gap_value ) {
	if ( is_array( $gap_value ) ) {
		foreach ( $gap_value as $key => $value ) {
			$sanitized_value = wp_sanitize_block_gap_value( $value );
			if ( ! is_string( $sanitized_value ) ) {
				unset( $gap_value[ $key ] );
				continue;
			}
			$gap_value[ $key ] = $sanitized_value;
		}

		return empty( $gap_value ) ? null : $gap_value;
	}

	if ( ( is_int( $gap_value ) || is_float( $gap_value ) ) && 0.0 === (float) $gap_value ) {
		return '0';
	}

	if ( ! is_string( $gap_value ) ) {
		return null;
	}

	if ( '' === trim( $gap_value ) ) {
		return null;
	}

	// Allow valid CSS custom property references, e.g. var(--wp--preset--spacing--32).
	if ( preg_match( '/^var\(--[a-zA-Z0-9_-]+\)$/', $gap_value ) ) {
		return $gap_value;
	}

	return $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
}