From c8d46a6a36db9ad8742a50d3268e28beae472342 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Wed, 18 Mar 2009 21:06:49 +0000 Subject: [PATCH] Allow wp_delete_term users to force all objects to have a new term applied. Allow for category merging use-case. Fixes #9355. git-svn-id: https://develop.svn.wordpress.org/trunk@10813 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 40d9426ddb..1518ed94dd 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1059,7 +1059,9 @@ function wp_delete_object_term_relationships( $object_id, $taxonomies ) { * * The $args 'default' will only override the terms found, if there is only one * term found. Any other and the found terms are used. - * + * + * The $args 'force_default' will force the term supplied as default to be + * assigned even if the object was not going to be termless * @package WordPress * @subpackage Taxonomy * @since 2.3.0 @@ -1110,10 +1112,13 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { foreach ( (array) $objects as $object ) { $terms = wp_get_object_terms($object, $taxonomy, 'fields=ids'); - if ( 1 == count($terms) && isset($default) ) + if ( 1 == count($terms) && isset($default) ) { $terms = array($default); - else + } else { $terms = array_diff($terms, array($term)); + if (isset($default) && isset($force_default) && $force_default) + $terms = array_merge($terms, array($default)); + } $terms = array_map('intval', $terms); wp_set_object_terms($object, $terms, $taxonomy); }