Skip to content

Conversation

josephscott
Copy link
Contributor

https://core.trac.wordpress.org/ticket/63877

Need to check the return value from the call to get_term().


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

https://core.trac.wordpress.org/ticket/63877

Need to check the return value from the call to `get_term()`.
Copy link

github-actions bot commented Aug 25, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props josephscott, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@westonruter
Copy link
Member

While tests are having trouble passing now in trunk, it would be nice to add a test for the case when something other than WP_Term is returned.

@josephscott
Copy link
Contributor Author

I thought about tests before submitting this, but wasn't sure what form a test would take. For example, I could generate a test that fails when get_term() returns null - but that test would then always fail. What would success look like in that scenario?

The inverse also seems not very helpful, if we test that we got null back in a way we expected, then it would always pass. Something like:

class Tests_Term_Null_Term_Handling extends WP_UnitTestCase {
    public function test_orphaned_hierarchy_causes_null_term_access() {
        global $wpdb;
        register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );    
        $parent_term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
        $non_existent_child_id = 99999;
        $hierarchy = array( $parent_term => array( $non_existent_child_id ) );
        update_option( 'wptests_tax_children', $hierarchy ); 
        $this->assertNull( get_term( $non_existent_child_id, 'wptests_tax' ), 'Non-existent term should return null' );
    }
}

If you are ok with a test like that, I'm happy to clean it up ( and add comments ) and add that to the patch.

@westonruter
Copy link
Member

Yeah, I mean whatever scenario caused the error to happen in the first place on your site would be good to add a test for.

@josephscott
Copy link
Contributor Author

I honestly don't know what happened, I noticed it on sites that have been running for more than 15 years and have probably been generating this warning for years.

Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60661
GitHub commit: 9bc4e2f

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Aug 26, 2025
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