Skip to content

Add support for tracking WordPress array parameter keys - #26

Merged
johnbillion merged 8 commits into
johnbillion:trunkfrom
swissspidy:claude/array-parameter-schema-dtdlmt
Oct 9, 2026
Merged

johnbillion merged 8 commits into
johnbillion:trunkfrom
swissspidy:claude/array-parameter-schema-dtdlmt

Conversation

@swissspidy

Copy link
Copy Markdown
Contributor

Summary

This PR extends WPCompat to track and validate the introduction versions of array keys within function and method parameters. Previously, the extension only checked if parameters themselves were available in the target WordPress version. Now it also validates that specific array keys used within those parameters were introduced before the minimum supported version.

Key Changes

  • New documentation extraction: Added getHashNotationKeys() function to parse WordPress's hash notation documentation format and extract array keys from @param blocks
  • Key version tracking: Implemented getParameterKeysSinceFromDoc() to identify which array keys were introduced in specific WordPress versions by analyzing @since changelog entries
  • PHPStan rule enhancement: Extended SinceVersionRule to detect when array keys are used and report errors if they were introduced after the minimum version
  • Array key detection: Added hasArrayKeyPath() method to determine if a given key path exists in an array argument using PHPStan's type analysis
  • Schema updates: Modified symbols.json schema to support optional keys property on parameters, allowing documentation of per-key version information
  • Comprehensive data population: Updated symbols.json with version information for array keys across 40+ WordPress functions and methods (e.g., register_meta(), wp_get_attachment_image(), WP_Theme_JSON::get_stylesheet())

Implementation Details

  • Array keys are documented using WordPress's standard hash notation with nested @type tags
  • Key paths support nesting with dot-delimited notation (e.g., options.skip_root_layout_styles)
  • Changelog entries are parsed to identify which keys were introduced, using heuristics to distinguish new keys from changes to existing ones
  • Only statically known array keys trigger errors, avoiding false positives from conditionally-assembled arrays
  • The implementation handles both positional and named arguments in function calls

https://claude.ai/code/session_01JZCYw6juqn1GruS2o7Exmr

claude and others added 3 commits August 28, 2026 14:11
WordPress documents the elements of an array shaped parameter with the hash
notation, so the generator can collect those keys along with their nesting and
then attribute the `@since` changelog entries of the symbol to them.

A key is only recorded when the changelog entry describes it as being added, and
only when it postdates both the symbol and the parameter that holds it. Entries
which merely describe a change to an existing key, such as "Added support for
`$operator`", are ignored, as are keys which share their name with a parameter
of the same symbol because those are already handled as parameters.

Co-authored-by: Pascal Birchler <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01JZCYw6juqn1GruS2o7Exmr
An argument which is an array is checked against the keys recorded for its
parameter, so passing an element which WordPress only understands from a later
version triggers an error. Nested keys are supported too, which is how the
`meta` argument of the Abilities API is documented.

Only keys which PHPStan knows are present get reported, so an array which is
assembled conditionally doesn't trigger an error.

Co-authored-by: Pascal Birchler <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01JZCYw6juqn1GruS2o7Exmr
Adds the array keys of 41 parameters, covering registration APIs such as
register_post_type(), register_taxonomy(), register_meta(), register_setting()
and register_sidebar(), as well as WP_Query, WP_Block_Type, and a number of
template functions.

Co-authored-by: Pascal Birchler <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01JZCYw6juqn1GruS2o7Exmr
Copilot AI lite review requested due to automatic review settings August 28, 2026 16:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

claude and others added 3 commits August 28, 2026 17:41
getParametersSinceFromDoc() and getParameterKeysSinceFromDoc() both matched the
@SInCE tags, mapped the MU version, validated the version format and discarded
the entries which predate the symbol. getSinceEntriesFromDoc() now does that
once and hands back the version and description of each entry, leaving the two
callers to do only their own attribution.

Regenerating the symbols against WordPress 7.1 produces an identical file.

Co-authored-by: Pascal Birchler <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01JZCYw6juqn1GruS2o7Exmr
The symbol extraction has moved out of generate.php and into SymbolExtractor,
so generate.php and symbols.json are resolved in favour of trunk. The array key
extraction they carried needs reapplying to the extractor.
@johnbillion

Copy link
Copy Markdown
Owner

Neat, thanks. I reworked this a bit because in the main branch I extracted the symbols.json generation to make it testable.

@johnbillion johnbillion added this to the 2.1.0 milestone Aug 29, 2026
@johnbillion johnbillion modified the milestones: 2.1.0, 3.0.0 Aug 29, 2026
@swissspidy

Copy link
Copy Markdown
Contributor Author

Awesome, thank you!

@johnbillion
johnbillion merged commit e240b08 into johnbillion:trunk Oct 9, 2026
13 checks passed
@johnbillion johnbillion modified the milestones: 2.1.0, 3.0.0 Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants