alleyinteractive / alleyinteractive/wp-asset-manager
SVG_Sprite adds a nested array to safe_style_css, triggering "Array to string conversion" php warning under newer kses
- Langage dominant
- PHP
- Étoiles
- 30
- Forks
- 5
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
### Description of the bug
**Summary**
`SVG_Sprite::__construct()` appends its extra CSS properties to the `safe_style_css` allowlist as a nested array instead of spreading them as individual strings. The filter is documented (and used by core) as `string[]`: https://developer.wordpress.org/reference/hooks/safe_style_css/. This has been latent for years, but newer kses code in WordPress 7.1 / Gutenberg now casts allowlist entries to strings via `array_unique()`, which raises a PHP Array to string conversion warning on every rendered page.
**Affected code**
[src/class-svg-sprite.php](https://github.com/alleyinteractive/wp-asset-manager/blob/production/src/class-svg-sprite.php#L85-L91), in the constructor:
```
add_filter(
'safe_style_css',
fn ( $styles ) => [
...array_values( $styles ),
[ 'left', 'overflow', 'position' ], // ← nested array; should be spread
],
);
```
The docblock immediately above it declares the value as @param string[], so the nested array violates the filter's own contract.
### Steps To Reproduce
On PHP 8.1+, load a site where `SVG_Sprite` is instantiated (so its `safe_style_css` filter is registered).
Have another `safe_style_css` callback that runs `array_unique()` over the allowlist registered after it (e.g. Gutenberg's `gutenberg_add_svg_to_safe_style_css`).
Render any front-end page (the filter runs via `wp_kses` → `safecss_filter_attr` during style processing).
Expected: no warning; `left`, `overflow`, `position` present in the allowlist as strings.
Actual:
`Warning: Array to string conversion in .../kses.php on line 97`
fired from inside the downstream `array_unique()` consumer.
### Additional Information
**Environment where this was noticed**
wp-asset-manager v1.4.3
Surfaced by WordPress 7.1 / Gutenberg kses compat (gutenberg_add_svg_to_safe_style_css)
PHP 8.1+
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.