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
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
- Scaling
- Constant
- Instructions
- 20–47
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 51.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 20–33 | none |
is_string($gap) && $gap | 36–47 | strrpos(), _wp_to_kebab_case() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 51 | 20–47 | 10 | |
| 8.5 | 51 | 20–47 | 10 | |
| 8.4 | 51 | 20–47 | 10 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 60 | 20–56 | 10 | |
| 8.2 | 60 | 20–56 | 10 | |
| 8.1 | 60 | 20–56 | 10 | |
| 7.4 | 60 | 20–56 | 10 |
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
- block_core_gallery_render()Renders the `core/gallery` block on the server.
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.