Closed lipemat closed 9 hours ago
diff --git a/functionMap.php b/functionMap.php
index 7065d1f..2619d5e 100644
--- a/functionMap.php
+++ b/functionMap.php
@@ -136,4 +136,5 @@ return [
'WP_Widget::form' => [null, 'instance' => 'T'],
'WP_Widget::update' => [null, 'new_instance' => 'T', 'old_instance' => 'T'],
'WP_Widget::widget' => [null, 'instance' => 'T', 'args' => 'array{name:string,id:string,description:string,class:string,before_widget:string,after_widget:string,before_title:string,after_title:string,before_sidebar:string,after_sidebar:string,show_in_rest:boolean,widget_id:string,widget_name:string}'],
+ 'block_template_part' => ['void', 'part' => 'string']
];
diff --git a/wordpress-stubs.php b/wordpress-stubs.php
index dfdea96..3a4a5d3 100644
--- a/wordpress-stubs.php
+++ b/wordpress-stubs.php
@@ -95084,6 +95084,7 @@ namespace {
*
* @param string $part The block template part to print. Either 'header' or 'footer'.
* @phpstan-param 'header'|'footer' $part
+ * @phpstan-param string $part
* @phpstan-return void
*/
function block_template_part($part)
@johnbillion Do you know where @phpstan-param 'header'|'footer' $part
comes from?
Couldn't find it in this repository.
@lipemat Thank you!
What is your specific $part
value?
Varies per project but here are some I was testing with.
Do you know where
@phpstan-param 'header'|'footer' $part
comes from?
Without losing all the 'either ... or ...' constructs, we cannot fix this in the visitor except by skipping predefined functions. So there are basically two options: 1) exclude specific functions, or 2) use the function map to override tags automatically added by identifying expressions that indicate a restricted set of possible values.
Please do not complicate this more. It can be resolved in local stubs.
Let's just fix this in WordPress itself :-)
With 6.6 being released, this issue can be closed once the stubs are updated in this repo.
The block_template_part function can accept any string although the documentation suggests only 'header' or 'footer'.
To recreate:
block_template_part
with the slug of the custom template.My hunch is the documentation is referring to how WP core uses the parameter which is only 'header' and 'footer'.
Within the stubs the following is generated, but so far I have been unable to explain why.
@phpstan-param 'header'|'footer' $part
I created a patch which adjusts the map for this function but ends up doubling up the parameter like so.
block-template-part.patch
Works but not ideal.