diff --git a/functionMap.php b/functionMap.php index 1a890b6b..657cdfbd 100644 --- a/functionMap.php +++ b/functionMap.php @@ -89,6 +89,7 @@ 'get_post_stati' => ["(\$output is 'names' ? array : array)"], 'get_comment' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Comment|null))"], 'get_post' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Post|null))"], + 'get_term_by' => ["(\$output is 'ARRAY_A' ? array|\WP_Error|false : (\$output is 'ARRAY_N' ? list|\WP_Error|false : \WP_Term|\WP_Error|false))"], 'get_page_by_path' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Post|null))"], 'has_action' => ['($callback is false ? bool : false|int)'], 'has_filter' => ['($callback is false ? bool : false|int)'], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 92b9dc79..e09cf6a3 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -19,6 +19,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post_types.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_page_by_path.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_permalink.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term_by.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies_for_attachments.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/has_filter.php'); diff --git a/tests/data/get_term_by.php b/tests/data/get_term_by.php new file mode 100644 index 00000000..847c29fe --- /dev/null +++ b/tests/data/get_term_by.php @@ -0,0 +1,13 @@ +|WP_Error|false', get_term_by( 'term_id', 2, '', ARRAY_A ) ); +assertType( 'array|WP_Error|false', get_term_by( 'term_id', 2, '', ARRAY_N ) ); \ No newline at end of file diff --git a/wordpress-stubs.php b/wordpress-stubs.php index f01cb465..add04d10 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -129508,6 +129508,7 @@ function get_term($term, $taxonomy = '', $output = \OBJECT, $filter = 'raw') * @param string $filter Optional. How to sanitize term fields. Default 'raw'. * @return WP_Term|array|false WP_Term instance (or array) on success, depending on the `$output` value. * False if `$taxonomy` does not exist or `$term` was not found. + * @phpstan-return ($output is 'ARRAY_A' ? array|\WP_Error|false : ($output is 'ARRAY_N' ? list|\WP_Error|false : \WP_Term|\WP_Error|false)) */ function get_term_by($field, $value, $taxonomy = '', $output = \OBJECT, $filter = 'raw') {