Make WordPress Core


Ignore:
Timestamp:
12/14/2025 07:11:49 AM (11 months ago)
Author:
westonruter
Message:

Taxonomy: Avoid type error in wp_delete_object_term_relationships() when invalid taxonomy supplied.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10621

Props owolter, westonruter.
Fixes #64406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php

    r48939 r61376  
    5454                $this->assertSameSets( array( $t2 ), $terms );
    5555        }
     56
     57        /**
     58         * @ticket 64406
     59         */
     60        public function test_delete_when_error() {
     61                $taxonomy_name = 'wptests_tax';
     62                register_taxonomy( $taxonomy_name, 'post' );
     63                $term_id   = self::factory()->term->create( array( 'taxonomy' => $taxonomy_name ) );
     64                $object_id = 567;
     65                wp_set_object_terms( $object_id, array( $term_id ), $taxonomy_name );
     66
     67                // Confirm the setup.
     68                $terms = wp_get_object_terms( $object_id, array( $taxonomy_name ), array( 'fields' => 'ids' ) );
     69                $this->assertSame( array( $term_id ), $terms, 'Expected same object terms.' );
     70
     71                // Try wp_delete_object_term_relationships() when the taxonomy is invalid (no change expected).
     72                wp_delete_object_term_relationships( $object_id, 'wptests_taxation' );
     73                $terms = wp_get_object_terms( $object_id, array( $taxonomy_name ), array( 'fields' => 'ids' ) );
     74                $this->assertSame( array( $term_id ), $terms, 'Expected the object terms to be unchanged.' );
     75        }
    5676}
Note: See TracChangeset for help on using the changeset viewer.