wpseek.com
A WordPress-centric search engine for devs and theme authors



block_core_gallery_get_column_gap_value › WordPress Function

Since7.1.0
Deprecatedn/a
block_core_gallery_get_column_gap_value ( $gap, $fallback_gap )
Parameters: (2)
  • (string|array|null) $gap Gallery block gap value.
    Required: Yes
  • (string) $fallback_gap Fallback gap value.
    Required: Yes
Returns:
  • (string) Gallery column gap value.
Defined at:
Codex:

Returns the column gap value used for Gallery image width calculations.



Source

function block_core_gallery_get_column_gap_value( $gap, $fallback_gap ) {
	if ( is_array( $gap ) ) {
		$gap = $gap['left'] ?? $fallback_gap;
	}

	// Make sure $gap is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null.
	$gap = is_string( $gap ) ? $gap : '';

	// Skip if gap value contains unsupported characters.
	// Regex for CSS value borrowed from `safecss_filter_attr`, and used here
	// because we only want to match against the value, not the CSS attribute.
	$gap = $gap && preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;

	// Get spacing CSS variable from preset value if provided.
	if ( is_string( $gap ) && str_contains( $gap, 'var:preset|spacing|' ) ) {
		$index_to_splice = strrpos( $gap, '|' ) + 1;
		$slug            = _wp_to_kebab_case( substr( $gap, $index_to_splice ) );
		$gap             = "var(--wp--preset--spacing--$slug)";
	}

	$gap_column = ( null !== $gap && '' !== $gap ) ? $gap : $fallback_gap;

	// The unstable gallery gap calculation requires a real value (such as `0px`) and not `0`.
	return '0' === $gap_column ? '0px' : $gap_column;
}