<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11941] trunk/wp-includes/taxonomy.php: Actions for taxonomy updates.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11941">11941</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-09-17 14:03:57 +0000 (Thu, 17 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Actions for taxonomy updates. Props Demitrious Kelly. fixes <a href="http://trac.wordpress.org/ticket/10750">#10750</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (11940 => 11941)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2009-09-16 03:13:21 UTC (rev 11940)
+++ trunk/wp-includes/taxonomy.php        2009-09-17 14:03:57 UTC (rev 11941)
</span><span class="lines">@@ -1078,7 +1078,9 @@
</span><span class="cx">         foreach ( (array) $taxonomies as $taxonomy ) {
</span><span class="cx">                 $tt_ids = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
</span><span class="cx">                 $in_tt_ids = &quot;'&quot; . implode(&quot;', '&quot;, $tt_ids) . &quot;'&quot;;
</span><ins>+                do_action( 'delete_term_relationships', $object_id, $tt_ids );
</ins><span class="cx">                 $wpdb-&gt;query( $wpdb-&gt;prepare(&quot;DELETE FROM $wpdb-&gt;term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)&quot;, $object_id) );
</span><ins>+                do_action( 'deleted_term_relationships', $object_id, $tt_ids );
</ins><span class="cx">                 wp_update_term_count($tt_ids, $taxonomy);
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="lines">@@ -1137,7 +1139,10 @@
</span><span class="cx">                         return $term_obj;
</span><span class="cx">                 $parent = $term_obj-&gt;parent;
</span><span class="cx"> 
</span><ins>+                $edit_tt_ids = $wpdb-&gt;get_col( &quot;SELECT `term_taxonomy_id` FROM $wpdb-&gt;term_taxonomy WHERE `parent` = &quot; . (int)$term_obj-&gt;term_id );
+                do_action( 'edit_term_taxonomies', $edit_tt_ids );
</ins><span class="cx">                 $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'parent' ), array( 'parent' =&gt; $term_obj-&gt;term_id) + compact( 'taxonomy' ) );
</span><ins>+                do_action( 'edited_term_taxonomies', $edit_tt_ids );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $objects = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT object_id FROM $wpdb-&gt;term_relationships WHERE term_taxonomy_id = %d&quot;, $tt_id ) );
</span><span class="lines">@@ -1155,7 +1160,9 @@
</span><span class="cx">                 wp_set_object_terms($object, $terms, $taxonomy);
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        do_action( 'delete_term_taxonomy', $tt_id );
</ins><span class="cx">         $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM $wpdb-&gt;term_taxonomy WHERE term_taxonomy_id = %d&quot;, $tt_id ) );
</span><ins>+        do_action( 'deleted_term_taxonomy', $tt_id );
</ins><span class="cx"> 
</span><span class="cx">         // Delete the term if no taxonomies use it.
</span><span class="cx">         if ( !$wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_taxonomy WHERE term_id = %d&quot;, $term) ) )
</span><span class="lines">@@ -1377,7 +1384,9 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
</span><span class="cx">                         $term_group = $wpdb-&gt;get_var(&quot;SELECT MAX(term_group) FROM $wpdb-&gt;terms&quot;) + 1;
</span><ins>+                        do_action( 'edit_terms', $alias-&gt;term_id );
</ins><span class="cx">                         $wpdb-&gt;update($wpdb-&gt;terms, compact('term_group'), array('term_id' =&gt; $alias-&gt;term_id) );
</span><ins>+                        do_action( 'edited_terms', $alias-&gt;term_id );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1396,7 +1405,9 @@
</span><span class="cx"> 
</span><span class="cx">         if ( empty($slug) ) {
</span><span class="cx">                 $slug = sanitize_title($slug, $term_id);
</span><ins>+                do_action( 'edit_terms', $term_id );
</ins><span class="cx">                 $wpdb-&gt;update( $wpdb-&gt;terms, compact( 'slug' ), compact( 'term_id' ) );
</span><ins>+                do_action( 'edited_terms', $term_id );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $tt_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT tt.term_taxonomy_id FROM $wpdb-&gt;term_taxonomy AS tt INNER JOIN $wpdb-&gt;terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d&quot;, $taxonomy, $term_id ) );
</span><span class="lines">@@ -1474,7 +1485,9 @@
</span><span class="cx"> 
</span><span class="cx">                 if ( $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT term_taxonomy_id FROM $wpdb-&gt;term_relationships WHERE object_id = %d AND term_taxonomy_id = %d&quot;, $object_id, $tt_id ) ) )
</span><span class="cx">                         continue;
</span><ins>+                do_action( 'add_term_relationship', $object_id, $tt_id );
</ins><span class="cx">                 $wpdb-&gt;insert( $wpdb-&gt;term_relationships, array( 'object_id' =&gt; $object_id, 'term_taxonomy_id' =&gt; $tt_id ) );
</span><ins>+                do_action( 'added_term_relationship', $object_id, $tt_id );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         wp_update_term_count($tt_ids, $taxonomy);
</span><span class="lines">@@ -1483,7 +1496,9 @@
</span><span class="cx">                 $delete_terms = array_diff($old_tt_ids, $tt_ids);
</span><span class="cx">                 if ( $delete_terms ) {
</span><span class="cx">                         $in_delete_terms = &quot;'&quot; . implode(&quot;', '&quot;, $delete_terms) . &quot;'&quot;;
</span><ins>+                        do_action( 'delete_term_relationships', $object_id, $delete_terms );
</ins><span class="cx">                         $wpdb-&gt;query( $wpdb-&gt;prepare(&quot;DELETE FROM $wpdb-&gt;term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_delete_terms)&quot;, $object_id) );
</span><ins>+                        do_action( 'deleted_term_relationships', $object_id, $delete_terms );
</ins><span class="cx">                         wp_update_term_count($delete_terms, $taxonomy);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -1646,7 +1661,9 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
</span><span class="cx">                         $term_group = $wpdb-&gt;get_var(&quot;SELECT MAX(term_group) FROM $wpdb-&gt;terms&quot;) + 1;
</span><ins>+                        do_action( 'edit_terms', $alias-&gt;term_id );
</ins><span class="cx">                         $wpdb-&gt;update( $wpdb-&gt;terms, compact('term_group'), array( 'term_id' =&gt; $alias-&gt;term_id ) );
</span><ins>+                        do_action( 'edited_terms', $alias-&gt;term_id );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1660,18 +1677,19 @@
</span><span class="cx">                 else
</span><span class="cx">                         return new WP_Error('duplicate_term_slug', sprintf(__('The slug &amp;#8220;%s&amp;#8221; is already in use by another term'), $slug));
</span><span class="cx">         }
</span><del>-
</del><ins>+        do_action( 'edit_terms', $alias-&gt;term_id );
</ins><span class="cx">         $wpdb-&gt;update($wpdb-&gt;terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
</span><del>-
</del><span class="cx">         if ( empty($slug) ) {
</span><span class="cx">                 $slug = sanitize_title($name, $term_id);
</span><span class="cx">                 $wpdb-&gt;update( $wpdb-&gt;terms, compact( 'slug' ), compact( 'term_id' ) );
</span><span class="cx">         }
</span><ins>+        do_action( 'edited_terms', $alias-&gt;term_id );
</ins><span class="cx"> 
</span><span class="cx">         $tt_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT tt.term_taxonomy_id FROM $wpdb-&gt;term_taxonomy AS tt INNER JOIN $wpdb-&gt;terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d&quot;, $taxonomy, $term_id) );
</span><del>-
</del><ins>+        do_action( 'edit_term_taxonomy', $tt_id );
</ins><span class="cx">         $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' =&gt; $tt_id ) );
</span><del>-
</del><ins>+        do_action( 'edited_term_taxonomy', $tt_id );
+        
</ins><span class="cx">         do_action(&quot;edit_term&quot;, $term_id, $tt_id);
</span><span class="cx">         do_action(&quot;edit_$taxonomy&quot;, $term_id, $tt_id);
</span><span class="cx"> 
</span><span class="lines">@@ -1771,7 +1789,9 @@
</span><span class="cx">                 // Default count updater
</span><span class="cx">                 foreach ( (array) $terms as $term) {
</span><span class="cx">                         $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_relationships WHERE term_taxonomy_id = %d&quot;, $term) );
</span><ins>+                        do_action( 'edit_term_taxonomy', $term );
</ins><span class="cx">                         $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' =&gt; $term ) );
</span><ins>+                        do_action( 'edited_term_taxonomy', $term );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">         }
</span><span class="lines">@@ -2153,7 +2173,9 @@
</span><span class="cx"> 
</span><span class="cx">         foreach ( (array) $terms as $term ) {
</span><span class="cx">                 $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(*) FROM $wpdb-&gt;term_relationships, $wpdb-&gt;posts WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d&quot;, $term ) );
</span><ins>+                do_action( 'edit_term_taxonomy', $term );
</ins><span class="cx">                 $wpdb-&gt;update( $wpdb-&gt;term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' =&gt; $term ) );
</span><ins>+                do_action( 'edited_term_taxonomy', $term );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>