WordPress.org

Make WordPress Core

Changeset 35585


Ignore:
Timestamp:
11/09/2015 03:35:56 AM (6 years ago)
Author:
boonebgorges
Message:

When deleting a term, delete its metadata as well.

Props barryceelen.
Fixes #34626.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta-functions.php

    r35170 r35585  
    559559 * @global wpdb $wpdb WordPress database abstraction object.
    560560 *
    561  * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
     561 * @param string $meta_type Type of object metadata is for (e.g., comment, post, meta, or user).
    562562 * @param int    $meta_id   ID for a specific meta row
    563563 * @return object|false Meta object or false.
     
    693693 * @global wpdb $wpdb WordPress database abstraction object.
    694694 *
    695  * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
     695 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
    696696 * @param int    $meta_id   ID for a specific meta row
    697697 * @return bool True on successful delete, false on failure.
  • trunk/src/wp-includes/taxonomy-functions.php

    r35537 r35585  
    20552055 * that term's parent.
    20562056 *
     2057 * Metadata associated with the term will be deleted.
     2058 *
    20572059 * The `$args` 'default' will only override the terms found, if there is only one
    20582060 * term found. Any other and the found terms are used.
     
    21722174    foreach ( $tax_object->object_type as $object_type )
    21732175        clean_object_term_cache( $objects, $object_type );
     2176
     2177    $term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) );
     2178    foreach ( $term_meta_ids as $mid ) {
     2179        delete_metadata_by_mid( 'term', $mid );
     2180    }
    21742181
    21752182    /**
  • trunk/tests/phpunit/tests/term/meta.php

    r35515 r35585  
    382382    }
    383383
     384    /**
     385     * @ticket 34626
     386     */
     387    public function test_term_meta_should_be_deleted_when_term_is_deleted() {
     388        $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     389
     390        add_term_meta( $t, 'foo', 'bar' );
     391        add_term_meta( $t, 'foo1', 'bar' );
     392
     393        $this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
     394        $this->assertSame( 'bar', get_term_meta( $t, 'foo1', true ) );
     395
     396        $this->assertTrue( wp_delete_term( $t, 'wptests_tax' ) );
     397
     398        $this->assertSame( '', get_term_meta( $t, 'foo', true ) );
     399        $this->assertSame( '', get_term_meta( $t, 'foo1', true ) );
     400    }
     401
    384402    public static function set_cache_results( $q ) {
    385403        $q->set( 'cache_results', true );
Note: See TracChangeset for help on using the changeset viewer.