From 545124ffb3b1224ee7393213c9c738453d2992ef Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 9 Nov 2015 03:36:26 +0000 Subject: [PATCH] When deleting a term, delete its metadata as well. Props barryceelen. Fixes #34626. Built from https://develop.svn.wordpress.org/trunk@35585 git-svn-id: http://core.svn.wordpress.org/trunk@35549 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta-functions.php | 4 ++-- wp-includes/taxonomy-functions.php | 7 +++++++ wp-includes/version.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/meta-functions.php b/wp-includes/meta-functions.php index be7ad5b65a..29cf291f92 100644 --- a/wp-includes/meta-functions.php +++ b/wp-includes/meta-functions.php @@ -558,7 +558,7 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) { * * @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 * @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. * - * @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 * @return bool True on successful delete, false on failure. */ diff --git a/wp-includes/taxonomy-functions.php b/wp-includes/taxonomy-functions.php index 174fe7427d..035f18b0d4 100644 --- a/wp-includes/taxonomy-functions.php +++ b/wp-includes/taxonomy-functions.php @@ -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 * 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 * 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 ) 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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 7a8f8acbea..0b1952dca6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta3-35584'; +$wp_version = '4.4-beta3-35585'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.