WP_Interactivity_API::merge_style_property( string $style_attribute_value, string $style_property_name, string|false|null $style_property_value ): string
- Since
- 6.5.0
- Source
wp-includes/interactivity-api/class-wp-interactivity-api.php:1354
style attribute of an HTML element, updating or removing the property when necessary.Description
If a property is modified, the old one is removed and the new one is added at the end of the list.
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$style_attribute_valuestring- The current style attribute value.
$style_property_namestring- The style property name to set.
$style_property_valuestring|false|null- The value to set for the style property. With false, null or an empty string, it removes the style property.
Return value
string- The new style attribute value after the specified property has been added, updated or removed.
Performance profile
How much work a call to WP_Interactivity_API::merge_style_property() 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
- Light
- Scaling
- Scales with input
- Instructions
- 22–32
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 56.
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 WP_Interactivity_API::merge_style_property() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($style_property_value) | 22–26 | explode() |
!empty($style_property_value) | 28–32 | explode(), rtrim() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 55 | 22–31 | 6 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 56 | 22–32 | 6 | |
| 8.4 | 56 | 22–32 | 6 | 13 fewer instructions than PHP 8.3 |
| 8.3 | 69 | 25–37 | 6 | |
| 8.2 | 69 | 25–37 | 6 | |
| 8.1 | 69 | 25–37 | 6 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 71 | 26–39 | 6 |
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.
Used by · 1
- WP_Interactivity_API::data_wp_style_processor()Processes the `data-wp-style` directive.
Source code
private function merge_style_property( string $style_attribute_value, string $style_property_name, $style_property_value ): string { $style_assignments = explode( ';', $style_attribute_value ); $result = array(); $style_property_value = ! empty( $style_property_value ) ? rtrim( trim( $style_property_value ), ';' ) : null; $new_style_property = $style_property_value ? $style_property_name . ':' . $style_property_value . ';' : ''; // Generates an array with all the properties but the modified one. foreach ( $style_assignments as $style_assignment ) { if ( empty( trim( $style_assignment ) ) ) { continue; } list( $name, $value ) = explode( ':', $style_assignment ); if ( trim( $name ) !== $style_property_name ) { $result[] = trim( $name ) . ':' . trim( $value ) . ';'; } } // Adds the new/modified property at the end of the list. $result[] = $new_style_property; return implode( '', $result ); }Changelog
Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/interactivity-api/class-wp-interactivity-api.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.