Skip to content

Conversation

@IanDelMar
Copy link
Contributor

$callback is narrowed based on its invocation in core (see shortcodes.php#L432–L434):

$content = isset( $m[5] ) ? $m[5] : null;
$output  = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6];

Here, $shortcode_tags[$tag] is the $callback passed to add_shortcode(), $attr (often called $atts in callbacks) are the parsed attributes, $content is the enclosed content or null when no closing tag is present, and $tag is the shortcode name.
Accordingly, $callback is narrowed to: callable(array<string>, ?string, string): string.

Afaik, in current core, $attr is always an array; attributes without explicit values (e.g. [mytag attribute]) produce integer keys. As this is user input - though deprecated - keys may be int|string; hence array<string> and not array<string, string>.

@IanDelMar IanDelMar marked this pull request as ready for review October 29, 2025 04:49
@szepeviktor
Copy link
Member

Very thorough.

@szepeviktor szepeviktor merged commit dc9489b into php-stubs:master Oct 29, 2025
7 checks passed
@IanDelMar IanDelMar deleted the add_shortcode branch October 29, 2025 05:16
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.

2 participants