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: http://svn.automattic.com/wordpress/trunk@10813 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-03-18 21:06:49 +00:00
parent 6de4ae1ad8
commit 789522a21a
1 changed files with 8 additions and 3 deletions

View File

@ -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 * 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.
* *
* 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 * @package WordPress
* @subpackage Taxonomy * @subpackage Taxonomy
* @since 2.3.0 * @since 2.3.0
@ -1110,10 +1112,13 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) {
foreach ( (array) $objects as $object ) { foreach ( (array) $objects as $object ) {
$terms = wp_get_object_terms($object, $taxonomy, 'fields=ids'); $terms = wp_get_object_terms($object, $taxonomy, 'fields=ids');
if ( 1 == count($terms) && isset($default) ) if ( 1 == count($terms) && isset($default) ) {
$terms = array($default); $terms = array($default);
else } else {
$terms = array_diff($terms, array($term)); $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); $terms = array_map('intval', $terms);
wp_set_object_terms($object, $terms, $taxonomy); wp_set_object_terms($object, $terms, $taxonomy);
} }