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
- 主要语言
- PHP
- 星标
- 30
- 派生
- 5
- PR 合并指标
- 30 天内没有已合并 PR
描述
### 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+
贡献指南
调研方向
Start in src/class-svg-sprite.php around the safe_style_css filter in SVG_Sprite::__construct(), then review how the allowlist reaches wp_kses and safecss_filter_attr. Confirm that left, overflow, and position are individual strings and that the downstream array_unique() consumer produces no Array to string conversion warning.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- web-dev
- Issue 类型
- 缺陷
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100