<!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>[11909] trunk: More add/delete/update actions.</title>
</head>
<body>

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

<h3>Log Message</h3>
<pre>More add/delete/update actions. Props Demitrious Kelly. see <a href="http://trac.wordpress.org/ticket/10750">#10750</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludespluginphp">trunk/wp-admin/includes/plugin.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/plugin.php (11908 => 11909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/plugin.php        2009-09-10 01:21:03 UTC (rev 11908)
+++ trunk/wp-admin/includes/plugin.php        2009-09-10 14:43:45 UTC (rev 11909)
</span><span class="lines">@@ -314,8 +314,10 @@
</span><span class="cx">                 @include(WP_PLUGIN_DIR . '/' . $plugin);
</span><span class="cx">                 $current[] = $plugin;
</span><span class="cx">                 sort($current);
</span><ins>+                do_action( 'activate_plugin', trim( $plugin) );
</ins><span class="cx">                 update_option('active_plugins', $current);
</span><del>-                do_action('activate_' . $plugin);
</del><ins>+                do_action( 'activate_' . trim( $plugin ) );
+                do_action( 'activated_plugin', trim( $plugin) );
</ins><span class="cx">                 ob_end_clean();
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -343,9 +345,14 @@
</span><span class="cx">                 $plugin = plugin_basename($plugin);
</span><span class="cx">                 if( ! is_plugin_active($plugin) )
</span><span class="cx">                         continue;
</span><ins>+                if ( ! $silent )
+                        do_action( 'deactivate_plugin', trim( $plugin ) );
</ins><span class="cx">                 array_splice($current, array_search( $plugin, $current), 1 ); // Fixed Array-fu!
</span><del>-                if ( ! $silent ) //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.
-                        do_action('deactivate_' . trim( $plugin ));
</del><ins>+                //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.
+                if ( ! $silent ) {
+                        do_action( 'deactivate_' . trim( $plugin ) );
+                        do_action( 'deactivated_plugin', trim( $plugin ) );
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         update_option('active_plugins', $current);
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (11908 => 11909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2009-09-10 01:21:03 UTC (rev 11908)
+++ trunk/wp-includes/post.php        2009-09-10 14:43:45 UTC (rev 11909)
</span><span class="lines">@@ -532,6 +532,8 @@
</span><span class="cx"> 
</span><span class="cx">         wp_cache_delete($post_id, 'post_meta');
</span><span class="cx"> 
</span><ins>+        do_action( 'added_post_meta', $wpdb-&gt;insert_id, $post_id, $meta_key, $meta_value );
+
</ins><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -573,12 +575,16 @@
</span><span class="cx">         if ( !$meta_id )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><ins>+        do_action( 'delete_post_meta', $meta_id, $post_id, $meta_key, $meta_value );
+
</ins><span class="cx">         if ( empty( $meta_value ) )
</span><span class="cx">                 $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM $wpdb-&gt;postmeta WHERE post_id = %d AND meta_key = %s&quot;, $post_id, $meta_key ) );
</span><span class="cx">         else
</span><span class="cx">                 $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM $wpdb-&gt;postmeta WHERE post_id = %d AND meta_key = %s AND meta_value = %s&quot;, $post_id, $meta_key, $meta_value ) );
</span><span class="cx"> 
</span><span class="cx">         wp_cache_delete($post_id, 'post_meta');
</span><ins>+        
+        do_action( 'deleted_post_meta', $meta_id, $post_id, $meta_key, $meta_value );
</ins><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="lines">@@ -651,9 +657,9 @@
</span><span class="cx">         if ( !$meta_key )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( ! $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT meta_key FROM $wpdb-&gt;postmeta WHERE meta_key = %s AND post_id = %d&quot;, $meta_key, $post_id ) ) ) {
</del><ins>+        $meta_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT meta_id FROM $wpdb-&gt;postmeta WHERE meta_key = %s AND post_id = %d&quot;, $meta_key, $post_id ) );
+        if ( ! $meta_id )
</ins><span class="cx">                 return add_post_meta($post_id, $meta_key, $meta_value);
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
</span><span class="cx"> 
</span><span class="lines">@@ -665,8 +671,13 @@
</span><span class="cx">                 $where['meta_value'] = $prev_value;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        do_action( 'update_post_meta', $meta_id, $post_id, $meta_key, $meta_value );
+        
</ins><span class="cx">         $wpdb-&gt;update( $wpdb-&gt;postmeta, $data, $where );
</span><span class="cx">         wp_cache_delete($post_id, 'post_meta');
</span><ins>+        
+        do_action( 'updated_post_meta', $meta_id, $post_id, $meta_key, $meta_value );
+        
</ins><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (11908 => 11909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2009-09-10 01:21:03 UTC (rev 11908)
+++ trunk/wp-includes/user.php        2009-09-10 14:43:45 UTC (rev 11909)
</span><span class="lines">@@ -307,6 +307,11 @@
</span><span class="cx">                 $meta_value = serialize($meta_value);
</span><span class="cx">         $meta_value = trim( $meta_value );
</span><span class="cx"> 
</span><ins>+        $cur = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;usermeta WHERE user_id = %d AND meta_key = %s&quot;, $user_id, $meta_key) );
+
+        if ( $cur &amp;&amp; $cur-&gt;umeta_id )
+                do_action( 'delete_usermeta', $cur-&gt;umeta_id, $user_id, $meta_key, $meta_value );
+
</ins><span class="cx">         if ( ! empty($meta_value) )
</span><span class="cx">                 $wpdb-&gt;query( $wpdb-&gt;prepare(&quot;DELETE FROM $wpdb-&gt;usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s&quot;, $user_id, $meta_key, $meta_value) );
</span><span class="cx">         else
</span><span class="lines">@@ -314,6 +319,9 @@
</span><span class="cx"> 
</span><span class="cx">         wp_cache_delete($user_id, 'users');
</span><span class="cx"> 
</span><ins>+        if ( $cur &amp;&amp; $cur-&gt;umeta_id )
+                do_action( 'deleted_usermeta', $cur-&gt;umeta_id, $user_id, $meta_key, $meta_value );
+
</ins><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -399,6 +407,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $cur = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;usermeta WHERE user_id = %d AND meta_key = %s&quot;, $user_id, $meta_key) );
</span><ins>+
+        if ( $cur )
+                do_action( 'update_usermeta', $cur-&gt;umeta_id, $user_id, $meta_key, $meta_value );
+
</ins><span class="cx">         if ( !$cur )
</span><span class="cx">                 $wpdb-&gt;insert($wpdb-&gt;usermeta, compact('user_id', 'meta_key', 'meta_value') );
</span><span class="cx">         else if ( $cur-&gt;meta_value != $meta_value )
</span><span class="lines">@@ -408,6 +420,11 @@
</span><span class="cx"> 
</span><span class="cx">         wp_cache_delete($user_id, 'users');
</span><span class="cx"> 
</span><ins>+        if ( !$cur ) 
+                do_action( 'added_usermeta', $wpdb-&gt;insert_id, $user_id, $meta_key, $meta_value );
+        else
+                do_action( 'updated_usermeta', $cur-&gt;umeta_id, $user_id, $meta_key, $meta_value );
+
</ins><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>