When deleting a term, delete its metadata as well.
Props barryceelen. Fixes #34626. git-svn-id: https://develop.svn.wordpress.org/trunk@35585 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
01b19a6345
commit
c13a263830
@ -558,7 +558,7 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) {
|
|||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
|
* @param string $meta_type Type of object metadata is for (e.g., comment, post, meta, or user).
|
||||||
* @param int $meta_id ID for a specific meta row
|
* @param int $meta_id ID for a specific meta row
|
||||||
* @return object|false Meta object or false.
|
* @return object|false Meta object or false.
|
||||||
*/
|
*/
|
||||||
@ -692,7 +692,7 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key =
|
|||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
|
* @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
|
||||||
* @param int $meta_id ID for a specific meta row
|
* @param int $meta_id ID for a specific meta row
|
||||||
* @return bool True on successful delete, false on failure.
|
* @return bool True on successful delete, false on failure.
|
||||||
*/
|
*/
|
||||||
|
@ -2054,6 +2054,8 @@ function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
|
|||||||
* If the term is a parent of other terms, then the children will be updated to
|
* If the term is a parent of other terms, then the children will be updated to
|
||||||
* that term's parent.
|
* that term's parent.
|
||||||
*
|
*
|
||||||
|
* Metadata associated with the term will be deleted.
|
||||||
|
*
|
||||||
* The `$args` 'default' will only override the terms found, if there is only one
|
* The `$args` 'default' will only override the terms found, if there is only one
|
||||||
* term found. Any other and the found terms are used.
|
* term found. Any other and the found terms are used.
|
||||||
*
|
*
|
||||||
@ -2172,6 +2174,11 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) {
|
|||||||
foreach ( $tax_object->object_type as $object_type )
|
foreach ( $tax_object->object_type as $object_type )
|
||||||
clean_object_term_cache( $objects, $object_type );
|
clean_object_term_cache( $objects, $object_type );
|
||||||
|
|
||||||
|
$term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) );
|
||||||
|
foreach ( $term_meta_ids as $mid ) {
|
||||||
|
delete_metadata_by_mid( 'term', $mid );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires immediately before a term taxonomy ID is deleted.
|
* Fires immediately before a term taxonomy ID is deleted.
|
||||||
*
|
*
|
||||||
|
@ -381,6 +381,24 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
|||||||
$this->assertSame( 'ambiguous_term_id', $found->get_error_code() );
|
$this->assertSame( 'ambiguous_term_id', $found->get_error_code() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 34626
|
||||||
|
*/
|
||||||
|
public function test_term_meta_should_be_deleted_when_term_is_deleted() {
|
||||||
|
$t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||||
|
|
||||||
|
add_term_meta( $t, 'foo', 'bar' );
|
||||||
|
add_term_meta( $t, 'foo1', 'bar' );
|
||||||
|
|
||||||
|
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||||
|
$this->assertSame( 'bar', get_term_meta( $t, 'foo1', true ) );
|
||||||
|
|
||||||
|
$this->assertTrue( wp_delete_term( $t, 'wptests_tax' ) );
|
||||||
|
|
||||||
|
$this->assertSame( '', get_term_meta( $t, 'foo', true ) );
|
||||||
|
$this->assertSame( '', get_term_meta( $t, 'foo1', true ) );
|
||||||
|
}
|
||||||
|
|
||||||
public static function set_cache_results( $q ) {
|
public static function set_cache_results( $q ) {
|
||||||
$q->set( 'cache_results', true );
|
$q->set( 'cache_results', true );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user