wppaste
WordPress

block_core_gallery_get_column_gap_value( string|array|null $gap, string $fallback_gap ): string

Since
7.1.0
Source
wp-includes/blocks/gallery.php:64
Returns the column gap value used for Gallery image width calculations.

Compatibility

WordPress
since 7.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$gapstring|array|null
Gallery block gap value.
$fallback_gapstring
Fallback gap value.

Return value

string
Gallery column gap value.

Performance profile

How much work a call to block_core_gallery_get_column_gap_value() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
20–47

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 51.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost block_core_gallery_get_column_gap_value() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always20–33none
is_string($gap) && $gap36–47strrpos(), _wp_to_kebab_case()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5120–4710
8.55120–4710
8.45120–47109 fewer instructions than PHP 8.3
8.36020–5610
8.26020–5610
8.16020–5610
7.46020–5610

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 2

  • str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
  • _wp_to_kebab_case()This function is trying to replicate what lodash's kebabCase (JS library) does in the client.

Used by · 1

Source code

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;}

Changelog

Introduced in 7.1.0.

Signature, return type and hooks compared across 1 parsed release.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/gallery.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.