Skip to content

Fix: Remove WP_Error from get_term_by return type #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

IanDelMar
Copy link
Contributor

get_term_by calls get_terms and get_term, both of which can return a WP_Error object if the taxonomy specified in $args['taxonomy'] (corresponding to the $taxonomy parameter of get_term_by) does not exist. However, get_term_by handles any potential errors from get_term and get_terms by converting them into a false return value, thereby ensuring it never directly returns a WP_Error object.

Removing WP_Error from the return type of get_term_by reflects the actual behaviour of the function.

Closes #284

`get_term_by` calls `get_terms` and `get_term`, both of which can return a `WP_Error` object if the taxonomy specified in `$args['taxonomy']` (corresponding to the `$taxonomy` parameter of `get_term_by`) does not exist. However, `get_term_by` handles any potential errors from `get_term` and `get_terms` by converting them into a `false` return value, thereby ensuring it never directly returns a `WP_Error` object.

Removing `WP_Error` from the return type of `get_term_by` reflects the actual behaviour of the function.

Closes php-stubs#284
@szepeviktor
Copy link
Member

Much better now.

Thank you!

@szepeviktor szepeviktor merged commit 7b5e911 into php-stubs:master Apr 25, 2025
6 checks passed
@IanDelMar IanDelMar deleted the get_term_by branch April 26, 2025 11:12
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.

get_term_by does not return WP_Error
2 participants