<!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>[11968] trunk: Actions for postmeta updates.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11968">11968</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-09-24 17:10:28 +0000 (Thu, 24 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Actions for postmeta updates. Props Demitrious Kelly. see <a href="http://trac.wordpress.org/ticket/10750">#10750</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpincludescommentphp">trunk/wp-includes/comment.php</a></li>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludesmetaphp">trunk/wp-includes/meta.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (11967 => 11968)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2009-09-24 08:47:33 UTC (rev 11967)
+++ trunk/wp-admin/includes/post.php        2009-09-24 17:10:28 UTC (rev 11968)
</span><span class="lines">@@ -588,6 +588,8 @@
</span><span class="cx">                 wp_cache_delete($post_ID, 'post_meta');
</span><span class="cx">
</span><span class="cx">                 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
</span><ins>+                do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
+                
</ins><span class="cx">                 return $wpdb->insert_id;
</span><span class="cx">         }
</span><span class="cx">         return false;
</span><span class="lines">@@ -608,7 +610,11 @@
</span><span class="cx">         $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
</span><span class="cx">         wp_cache_delete($post_id, 'post_meta');
</span><span class="cx">
</span><del>-        return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
</del><ins>+        do_action( 'delete_postmeta', $mid );
+        $rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
+        do_action( 'deleted_postmeta', $mid );
+
+        return $rval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -697,7 +703,11 @@
</span><span class="cx">         $data = compact( 'meta_key', 'meta_value' );
</span><span class="cx">         $where = compact( 'meta_id' );
</span><span class="cx">
</span><del>-        return $wpdb->update( $wpdb->postmeta, $data, $where );
</del><ins>+        do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
+        $rval = $wpdb->update( $wpdb->postmeta, $data, $where );
+        do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
+
+        return $rval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> //
</span></span></pre></div>
<a id="trunkwpincludescommentphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/comment.php (11967 => 11968)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/comment.php        2009-09-24 08:47:33 UTC (rev 11967)
+++ trunk/wp-includes/comment.php        2009-09-24 17:10:28 UTC (rev 11968)
</span><span class="lines">@@ -1449,13 +1449,19 @@
</span><span class="cx">
</span><span class="cx">         // Do pingbacks
</span><span class="cx">         while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
</span><del>-                $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
</del><ins>+                $mid = $wpdb->get_var( "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme' LIMIT 1");
+                do_action( 'delete_postmeta', $mid );
+                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_id = %d", $mid ) );
+                do_action( 'deleted_postmeta', $mid );
</ins><span class="cx">                 pingback($ping->post_content, $ping->ID);
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         // Do Enclosures
</span><span class="cx">         while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
</span><del>-                $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme';", $enclosure->ID) );
</del><ins>+                $mid = $wpdb->get_var( $wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme'", $enclosure->ID) );
+                do_action( 'delete_postmeta', $mid );
+                $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id = %d", $mid) );
+                do_action( 'deleted_postmeta', $mid );
</ins><span class="cx">                 do_enclose($enclosure->post_content, $enclosure->ID);
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (11967 => 11968)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2009-09-24 08:47:33 UTC (rev 11967)
+++ trunk/wp-includes/functions.php        2009-09-24 17:10:28 UTC (rev 11968)
</span><span class="lines">@@ -1163,7 +1163,10 @@
</span><span class="cx">
</span><span class="cx">         foreach ( $pung as $link_test ) {
</span><span class="cx">                 if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
</span><del>-                        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
</del><ins>+                        $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
+                        do_action( 'delete_postmeta', $mid );
+                        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id IN(%s)", implode( ',', $mid ) ) );
+                        do_action( 'deleted_postmeta', $mid );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -1186,6 +1189,7 @@
</span><span class="cx">                                 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
</span><span class="cx">                                         $meta_value = "$url\n$len\n$type\n";
</span><span class="cx">                                         $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
</span><ins>+                                        do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
</ins><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -3386,4 +3390,4 @@
</span><span class="cx">                 wp_delete_comment($comment['comment_id']);
</span><span class="cx">         }
</span><span class="cx"> }
</span><del>-?>
</del><span class="cx">\ No newline at end of file
</span><ins>+?>
</ins></span></pre></div>
<a id="trunkwpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/meta.php (11967 => 11968)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/meta.php        2009-09-24 08:47:33 UTC (rev 11967)
+++ trunk/wp-includes/meta.php        2009-09-24 17:10:28 UTC (rev 11968)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx">         // expected_slashed ($meta_key)
</span><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx">
</span><del>-        if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
</del><ins>+        if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
</ins><span class="cx">                 return add_metadata($meta_type, $object_id, $meta_key, $meta_value);
</span><span class="cx">
</span><span class="cx">         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
</span><span class="lines">@@ -70,12 +70,12 @@
</span><span class="cx">                 $where['meta_value'] = $prev_value;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        do_action( "update_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
</del><ins>+        do_action( "update_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_id );
</ins><span class="cx">
</span><span class="cx">         $wpdb->update( $table, $data, $where );
</span><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">
</span><del>-        do_action( "updated_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
</del><ins>+        do_action( "updated_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_id );
</ins><span class="cx">
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="lines">@@ -95,10 +95,16 @@
</span><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx">         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
</span><span class="cx">
</span><del>-        $query = $wpdb->prepare( "DELETE FROM $table WHERE meta_key = %s", $meta_key );
-
</del><ins>+        $query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
+        
</ins><span class="cx">         if ( $meta_value )
</span><span class="cx">                 $query .= $wpdb->prepare("AND meta_value = %s", $meta_value );
</span><ins>+
+        $meta_ids = $wpdb->get_col( $query );
+        if ( !count( $meta_ids ) )
+                return false;
+
+        $query = "DELETE FROM $table WHERE meta_id IN( " . implode( ',', $meta_ids ) . " )";
</ins><span class="cx">         
</span><span class="cx">         $count = $wpdb->query($query);
</span><span class="cx">         
</span><span class="lines">@@ -107,7 +113,7 @@
</span><span class="cx">
</span><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">
</span><del>-        do_action( "deleted_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
</del><ins>+        do_action( "deleted_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_ids );
</ins><span class="cx">
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="lines">@@ -212,4 +218,4 @@
</span><span class="cx">
</span><span class="cx">         return $wpdb->$table_name;
</span><span class="cx"> }
</span><del>-?>
</del><span class="cx">\ No newline at end of file
</span><ins>+?>
</ins></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (11967 => 11968)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2009-09-24 08:47:33 UTC (rev 11967)
+++ trunk/wp-includes/post.php        2009-09-24 17:10:28 UTC (rev 11968)
</span><span class="lines">@@ -601,7 +601,10 @@
</span><span class="cx">         global $wpdb;
</span><span class="cx">         $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key));
</span><span class="cx">         if ( $post_ids ) {
</span><del>-                $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key));
</del><ins>+                $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key ) );
+                do_action( 'delete_postmeta', $postmetaids );
+                $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids) ) );
+                do_action( 'deleted_postmeta', $postmetaids );
</ins><span class="cx">                 foreach ( $post_ids as $post_id )
</span><span class="cx">                         wp_cache_delete($post_id, 'post_meta');
</span><span class="cx">                 return true;
</span><span class="lines">@@ -1102,11 +1105,19 @@
</span><span class="cx">         // Point all attachments to this post up one level
</span><span class="cx">         $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
</span><span class="cx">
</span><del>-        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
</del><ins>+        $commentids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
+        do_action( 'delete_comment', $commentids );
+        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_ID IN(%s)", implode( ',', $commentids ) ));
+        do_action( 'deleted_comment', $commentids );
</ins><span class="cx">
</span><del>-        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d", $postid ));
</del><ins>+        $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
+        do_action( 'delete_postmeta', $postmetaids );
+        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids ) ));
+        do_action( 'deleted_postmeta', $postmetaids );
</ins><span class="cx">
</span><ins>+        do_action( 'delete_post', $post_id );
</ins><span class="cx">         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));
</span><ins>+        do_action( 'deleted_post', $post_id );
</ins><span class="cx">
</span><span class="cx">         if ( 'page' == $post->post_type ) {
</span><span class="cx">                 clean_page_cache($postid);
</span><span class="lines">@@ -2584,11 +2595,19 @@
</span><span class="cx">         /** @todo Delete for pluggable post taxonomies too */
</span><span class="cx">         wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
</span><span class="cx">
</span><del>-        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
</del><ins>+        $commentids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
+        do_action( 'delete_comment', $commentids );
+        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_ID IN(%s)", implode( ',', $commentids ) ));
+        do_action( 'deleted_comment', $commentids );
</ins><span class="cx">
</span><del>-        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
</del><ins>+        $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
+        do_action( 'delete_postmeta', $postmetaids );
+        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids ) ));
+        do_action( 'deleted_postmeta', $postmetaids );
</ins><span class="cx">
</span><ins>+        do_action( 'delete_post', $post_id );
</ins><span class="cx">         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
</span><ins>+        do_action( 'deleted_post', $post_id );
</ins><span class="cx">
</span><span class="cx">         $uploadpath = wp_upload_dir();
</span><span class="cx">
</span><span class="lines">@@ -3270,9 +3289,13 @@
</span><span class="cx">                 return;
</span><span class="cx">
</span><span class="cx">         $data = array( 'post_id' => $post_id, 'meta_value' => '1' );
</span><del>-        if ( get_option('default_pingback_flag') )
</del><ins>+        if ( get_option('default_pingback_flag') ) {
</ins><span class="cx">                 $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
</span><ins>+                do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
+        }
</ins><span class="cx">         $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
</span><ins>+        do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
+
</ins><span class="cx">         wp_schedule_single_event(time(), 'do_pings');
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>