<!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 { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { 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>[14814] trunk: Introduce a 'post_updated' action,
  Fires when a post is updated, Post ID,
  Current and Previous post objects are passed.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14814">14814</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-05-23 07:49:21 +0000 (Sun, 23 May 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce a 'post_updated' action, Fires when a post is updated, Post ID, Current and Previous post objects are passed. Updatewp_check_for_changed_slugs() to use new hook. See <a href="http://trac.wordpress.org/ticket/12473">#12473</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (14813 => 14814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2010-05-23 07:43:07 UTC (rev 14813)
+++ trunk/wp-admin/includes/template.php        2010-05-23 07:49:21 UTC (rev 14814)
</span><span class="lines">@@ -2762,18 +2762,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * {@internal Missing Short Description}}
- *
- * @since unknown
- */
-function wp_remember_old_slug() {
-        global $post;
-        $name = esc_attr($post-&gt;post_name); // just in case
-        if ( strlen($name) )
-                echo '&lt;input type=&quot;hidden&quot; id=&quot;wp-old-slug&quot; name=&quot;wp-old-slug&quot; value=&quot;' . $name . '&quot; /&gt;';
-}
-
-/**
</del><span class="cx">  * Add a meta box to an edit form.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.5.0
</span></span></pre></div>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (14813 => 14814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php        2010-05-23 07:43:07 UTC (rev 14813)
+++ trunk/wp-includes/default-filters.php        2010-05-23 07:49:21 UTC (rev 14814)
</span><span class="lines">@@ -235,11 +235,12 @@
</span><span class="cx"> add_action( 'end_fetch_post_thumbnail_html',   '_wp_post_thumbnail_class_filter_remove' );
</span><span class="cx"> 
</span><span class="cx"> // Redirect Old Slugs
</span><del>-add_action( 'template_redirect',  'wp_old_slug_redirect'       );
-add_action( 'edit_post',          'wp_check_for_changed_slugs' );
-add_action( 'edit_form_advanced', 'wp_remember_old_slug'       );
-add_action( 'init',               '_show_post_preview'         );
</del><ins>+add_action( 'template_redirect', 'wp_old_slug_redirect'              );
+add_action( 'post_updated',      'wp_check_for_changed_slugs', 12, 3 );
</ins><span class="cx"> 
</span><ins>+// Nonce check for Post Previews
+add_action( 'init', '_show_post_preview' );
+
</ins><span class="cx"> // Timezone
</span><span class="cx"> add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (14813 => 14814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-05-23 07:43:07 UTC (rev 14813)
+++ trunk/wp-includes/post.php        2010-05-23 07:49:21 UTC (rev 14814)
</span><span class="lines">@@ -1655,7 +1655,7 @@
</span><span class="cx">  * @since 2.5.0
</span><span class="cx">  *
</span><span class="cx">  * @param string|array $mime_types List of mime types or comma separated string of mime types.
</span><del>- * @param string $table_alias Optional. Specify a table alias, if needed. 
</del><ins>+ * @param string $table_alias Optional. Specify a table alias, if needed.
</ins><span class="cx">  * @return string The SQL AND clause for mime searching.
</span><span class="cx">  */
</span><span class="cx"> function wp_post_mime_type_where($post_mime_types, $table_alias = '') {
</span><span class="lines">@@ -2199,6 +2199,7 @@
</span><span class="cx">         if ( $update ) {
</span><span class="cx">                 $post_ID = (int) $ID;
</span><span class="cx">                 $guid = get_post_field( 'guid', $post_ID );
</span><ins>+                $post_before = get_post($post_ID);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Don't allow contributors to set to set the post slug for pending review posts
</span><span class="lines">@@ -2374,8 +2375,11 @@
</span><span class="cx"> 
</span><span class="cx">         wp_transition_post_status($data['post_status'], $previous_status, $post);
</span><span class="cx"> 
</span><del>-        if ( $update )
</del><ins>+        if ( $update ) {
</ins><span class="cx">                 do_action('edit_post', $post_ID, $post);
</span><ins>+                $post_after = get_post($post_ID);
+                do_action( 'post_updated', $post_ID, $post_after, $post_before);
+        }
</ins><span class="cx"> 
</span><span class="cx">         do_action('save_post', $post_ID, $post);
</span><span class="cx">         do_action('wp_insert_post', $post_ID, $post);
</span><span class="lines">@@ -3778,31 +3782,24 @@
</span><span class="cx">  * @param int $post_id Post ID.
</span><span class="cx">  * @return int Same as $post_id
</span><span class="cx">  */
</span><del>-function wp_check_for_changed_slugs($post_id) {
-        if ( empty($_POST['wp-old-slug']) )
-                return $post_id;
</del><ins>+function wp_check_for_changed_slugs($post_id, $post, $post_before) {
+        // dont bother if it hasnt changed
+        if ( $post-&gt;post_name == $post_before-&gt;post_name )
+                return;
</ins><span class="cx"> 
</span><del>-        $post = &amp;get_post($post_id);
-
</del><span class="cx">         // we're only concerned with published posts
</span><span class="cx">         if ( $post-&gt;post_status != 'publish' || $post-&gt;post_type != 'post' )
</span><del>-                return $post_id;
</del><ins>+                return;
</ins><span class="cx"> 
</span><del>-        // only bother if the slug has changed
-        if ( $post-&gt;post_name == $_POST['wp-old-slug'] )
-                return $post_id;
-
</del><span class="cx">         $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
</span><span class="cx"> 
</span><span class="cx">         // if we haven't added this old slug before, add it now
</span><del>-        if ( !count($old_slugs) || !in_array($_POST['wp-old-slug'], $old_slugs) )
-                add_post_meta($post_id, '_wp_old_slug', $_POST['wp-old-slug']);
</del><ins>+        if ( !in_array($post_before-&gt;post_name, $old_slugs) )
+                add_post_meta($post_id, '_wp_old_slug', $post_before-&gt;post_name);
</ins><span class="cx"> 
</span><span class="cx">         // if the new slug was used previously, delete it from the list
</span><span class="cx">         if ( in_array($post-&gt;post_name, $old_slugs) )
</span><span class="cx">                 delete_post_meta($post_id, '_wp_old_slug', $post-&gt;post_name);
</span><del>-
-        return $post_id;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>