wppaste
WordPress

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
Merges an individual style property in the 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
22–32

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

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 WP_Interactivity_API::merge_style_property() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($style_property_value)22–26explode()
!empty($style_property_value)28–32explode(), rtrim()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5522–3161 fewer instruction than PHP 8.5
8.55622–326
8.45622–32613 fewer instructions than PHP 8.3
8.36925–376
8.26925–376
8.16925–3762 fewer instructions than PHP 7.4
7.47126–396

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.