<!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>[11878] trunk/wp-includes:
Move the storage of the metadata for trashed posts into the post meta table rather than storing it in an option
.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11878">11878</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2009-08-25 22:05:15 +0000 (Tue, 25 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Move the storage of the metadata for trashed posts into the post meta table rather than storing it in an option. See <a href="http://trac.wordpress.org/ticket/4529">#4529</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (11877 => 11878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2009-08-25 08:11:07 UTC (rev 11877)
+++ trunk/wp-includes/capabilities.php        2009-08-25 22:05:15 UTC (rev 11878)
</span><span class="lines">@@ -776,8 +776,7 @@
</span><span class="cx">                         if ( 'publish' == $post->post_status ) {
</span><span class="cx">                                 $caps[] = 'delete_published_posts';
</span><span class="cx">                         } elseif ( 'trash' == $post->post_status ) {
</span><del>-                                $trash_meta = get_option('wp_trash_meta');
-                                if (is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish')
</del><ins>+                                if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
</ins><span class="cx">                                         $caps[] = 'delete_published_posts';
</span><span class="cx">                         } else {
</span><span class="cx">                                 // If the post is draft...
</span><span class="lines">@@ -805,8 +804,7 @@
</span><span class="cx">                         if ( $page->post_status == 'publish' ) {
</span><span class="cx">                                 $caps[] = 'delete_published_pages';
</span><span class="cx">                         } elseif ( 'trash' == $page->post_status ) {
</span><del>-                                $trash_meta = get_option('wp_trash_meta');
-                                if (is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish')
</del><ins>+                                if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
</ins><span class="cx">                                         $caps[] = 'delete_published_pages';
</span><span class="cx">                         } else {
</span><span class="cx">                                 // If the page is draft...
</span><span class="lines">@@ -840,8 +838,7 @@
</span><span class="cx">                         if ( 'publish' == $post->post_status ) {
</span><span class="cx">                                 $caps[] = 'edit_published_posts';
</span><span class="cx">                         } elseif ( 'trash' == $post->post_status ) {
</span><del>-                                $trash_meta = get_option('wp_trash_meta');
-                                if ( is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish' )
</del><ins>+                                if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
</ins><span class="cx">                                         $caps[] = 'edit_published_posts';
</span><span class="cx">                         } else {
</span><span class="cx">                                 // If the post is draft...
</span><span class="lines">@@ -869,8 +866,7 @@
</span><span class="cx">                         if ( 'publish' == $page->post_status ) {
</span><span class="cx">                                 $caps[] = 'edit_published_pages';
</span><span class="cx">                         } elseif ( 'trash' == $page->post_status ) {
</span><del>-                                $trash_meta = get_option('wp_trash_meta');
-                                if ( is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish' )
</del><ins>+                                if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
</ins><span class="cx">                                         $caps[] = 'edit_published_pages';
</span><span class="cx">                         } else {
</span><span class="cx">                                 // If the page is draft...
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (11877 => 11878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2009-08-25 08:11:07 UTC (rev 11877)
+++ trunk/wp-includes/functions.php        2009-08-25 22:05:15 UTC (rev 11878)
</span><span class="lines">@@ -3346,24 +3346,29 @@
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><span class="cx"> function wp_scheduled_delete() {
</span><ins>+        global $wpdb;
+
+        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
+        
+        $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
+        
+        foreach ( (array) $posts_to_delete as $post ) {
+                wp_delete_post($post['post_id']);
+        }
+
+        //Trashed Comments
+        //TODO Come up with a better store for the comment trash meta.
</ins><span class="cx">         $trash_meta = get_option('wp_trash_meta');
</span><span class="cx">         if ( !is_array($trash_meta) )
</span><span class="cx">                 return;
</span><span class="cx">
</span><del>-        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
-
</del><span class="cx">         foreach ( (array) $trash_meta['comments'] as $id => $meta ) {
</span><span class="cx">                 if ( $meta['time'] < $delete_timestamp ) {
</span><span class="cx">                         wp_delete_comment($id);
</span><span class="cx">                         unset($trash_meta['comments'][$id]);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        foreach ( (array) $trash_meta['posts'] as $id => $meta ) {
-                if ( $meta['time'] < $delete_timestamp ) {
-                        wp_delete_post($id);
-                        unset($trash_meta['posts'][$id]);
-                }
-        }
</del><span class="cx">
</span><span class="cx">         update_option('wp_trash_meta', $trash_meta);
</span><span class="cx"> }
</span><ins>+?>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (11877 => 11878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2009-08-25 08:11:07 UTC (rev 11877)
+++ trunk/wp-includes/post.php        2009-08-25 22:05:15 UTC (rev 11878)
</span><span class="lines">@@ -1149,11 +1149,8 @@
</span><span class="cx">
</span><span class="cx">         do_action('delete_post', $postid);
</span><span class="cx">         
</span><del>-        $trash_meta = get_option('wp_trash_meta');
-        if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
-                unset($trash_meta['posts'][$postid]);
-                update_option('wp_trash_meta', $trash_meta);
-        }
</del><ins>+        delete_post_meta($postid,'_wp_trash_meta_status');
+        delete_post_meta($postid,'_wp_trash_meta_time');
</ins><span class="cx">
</span><span class="cx">         /** @todo delete for pluggable post taxonomies too */
</span><span class="cx">         wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
</span><span class="lines">@@ -1224,26 +1221,22 @@
</span><span class="cx"> * @param int $postid Post ID.
</span><span class="cx"> * @return mixed False on failure
</span><span class="cx"> */
</span><del>-function wp_trash_post($postid = 0) {
</del><ins>+function wp_trash_post($post_id = 0) {
</ins><span class="cx">         if ( EMPTY_TRASH_DAYS == 0 )
</span><del>-                return wp_delete_post($postid);
</del><ins>+                return wp_delete_post($post_id);
</ins><span class="cx">
</span><del>-        if ( !$post = wp_get_single_post($postid, ARRAY_A) )
</del><ins>+        if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
</ins><span class="cx">                 return $post;
</span><span class="cx">
</span><del>-        do_action('trash_post', $postid);
</del><ins>+        do_action('trash_post', $post_id);
</ins><span class="cx">
</span><del>-        $trash_meta = get_option('wp_trash_meta');
-        if ( !is_array($trash_meta) )
-                $trash_meta = array();
-        $trash_meta['posts'][$postid]['status'] = $post['post_status'];
-        $trash_meta['posts'][$postid]['time'] = time();
-        update_option('wp_trash_meta', $trash_meta);
</del><ins>+        add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
+        add_post_meta($post_id,'_wp_trash_meta_time', time());
</ins><span class="cx">
</span><span class="cx">         $post['post_status'] = 'trash';
</span><span class="cx">         wp_insert_post($post);
</span><span class="cx">
</span><del>-        do_action('trashed_post', $postid);
</del><ins>+        do_action('trashed_post', $post_id);
</ins><span class="cx">
</span><span class="cx">         return $post;
</span><span class="cx"> }
</span><span class="lines">@@ -1258,24 +1251,20 @@
</span><span class="cx"> * @param int $postid Post ID.
</span><span class="cx"> * @return mixed False on failure
</span><span class="cx"> */
</span><del>-function wp_untrash_post($postid = 0) {
-        if ( !$post = wp_get_single_post($postid, ARRAY_A) )
</del><ins>+function wp_untrash_post($post_id = 0) {
+        if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
</ins><span class="cx">                 return $post;
</span><span class="cx">
</span><del>-        do_action('untrash_post', $postid);
</del><ins>+        do_action('untrash_post', $post_id);
</ins><span class="cx">
</span><del>-        $post['post_status'] = ($post->post_type == 'attachment') ? 'inherit' : 'draft';
</del><ins>+        $post['post_status'] = ('attachment' == $post['post_type'] ) ? 'inherit' : 'draft';
</ins><span class="cx">
</span><del>-        $trash_meta = get_option('wp_trash_meta');
-        if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
-                $post['post_status'] = $trash_meta['posts'][$postid]['status'];
-                unset($trash_meta['posts'][$postid]);
-                update_option('wp_trash_meta', $trash_meta);
-        }
</del><ins>+        delete_post_meta($post_id,'_wp_trash_meta_status');
+        delete_post_meta($post_id,'_wp_trash_meta_time');
</ins><span class="cx">
</span><span class="cx">         wp_insert_post($post);
</span><span class="cx">
</span><del>-        do_action('untrashed_post', $postid);
</del><ins>+        do_action('untrashed_post', $post_id);
</ins><span class="cx">
</span><span class="cx">         return $post;
</span><span class="cx"> }
</span><span class="lines">@@ -2666,11 +2655,9 @@
</span><span class="cx">         if ( 'trash' != $post->post_status )
</span><span class="cx">                 return wp_trash_post($postid);
</span><span class="cx">
</span><del>-        $trash_meta = get_option('wp_trash_meta');
-        if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
-                unset($trash_meta['posts'][$postid]);
-                update_option('wp_trash_meta', $trash_meta);
-        }
</del><ins>+        delete_post_meta($post_id,'_wp_trash_meta_status');
+        delete_post_meta($post_id,'_wp_trash_meta_time');
+                
</ins><span class="cx">
</span><span class="cx">         $meta = wp_get_attachment_metadata( $postid );
</span><span class="cx">         $file = get_attached_file( $postid );
</span></span></pre>
</div>
</div>
</body>
</html>