{"id":1973,"date":"2008-08-10T15:50:46","date_gmt":"2008-08-10T20:50:46","guid":{"rendered":"http:\/\/www.allyngibson.net\/?p=1973"},"modified":"2008-08-10T15:50:46","modified_gmt":"2008-08-10T20:50:46","slug":"on-wordpress-bugs-not-features","status":"publish","type":"post","link":"http:\/\/www.allyngibson.com\/?p=1973","title":{"rendered":"On WordPress Bugs, Not Features"},"content":{"rendered":"<p>&#8220;It&#8217;s a feature, not a bug!&#8221;<\/p>\n<p>It&#8217;s a classic line.  A Microsoft line.  About how bugs in software aren&#8217;t really bugs, they&#8217;re undocumented features.<\/p>\n<p>WordPress 2.6 has a new feature called &#8220;Post Revisions.&#8221;  Basically, every time you edit a post, you can &#8220;roll back&#8221; the post and undo changes, as users can with Wikipedia.<\/p>\n<p>It sounds like a nifty idea.<\/p>\n<p>In practical terms, it isn&#8217;t.  It&#8217;s really more of a bug.  A well-intentioned bug.  But still a bug.<\/p>\n<p>Why?  Each &#8220;revision&#8221; is an entirely new row in the WordPress database.  Edit a post to add another tag?  That&#8217;s another row.  Edit a post to fix a spelling mistake?  That&#8217;s another row.  Edit a post ten times, and you&#8217;ve added ten new rows to your WordPress data table.<\/p>\n<p>And WordPress doesn&#8217;t let you turn it off.<\/p>\n<p>Fortunately, <a href=\"http:\/\/lesterchan.net\/wordpress\/2008\/07\/17\/how-to-turn-off-post-revision-in-wordpress-26\/\">WordPress guru Lester Chan found a way<\/a>.  An edit to the wp-config file turns off post revisions.<\/p>\n<p>But, turning it off still leaves junk rows in the database.<\/p>\n<p>Lester gives some SQL code to delete the rows.<\/p>\n<p>I have a better idea.<\/p>\n<p>A few years ago, code was posted in the WordPress support fora to turn off comments after so many days.  The way it worked was that, whenever something was done to a post &mdash; from posting to editing to leaving a comment &mdash; this routine would run.  If a post had open comments and it was more than 21 days old, the plugin would close the comments on the post.<\/p>\n<p>It occurred to me that I could turn that code into something that went through the WordPress post table, looked for revision posts and turn them into draft posts.  Then, the next time I wanted to write a post, rather than start up a new post, I could &#8220;recycle&#8221; one of these draft posts &mdash; and save a line in the database table.<\/p>\n<p>I looked at the code.  I studied my WordPress database tables.  I thought.  I wrote some code.  I crossed my fingers.  And she flew. \ud83d\ude42<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/*<br \/>\nPlugin Name: Revision To Draft<br \/>\nVersion:     1.0<br \/>\nPlugin URI:  http:\/\/www.allyngibson.com\/?p=1973<br \/>\nDescription: Change post Revisions to Drafts<br \/>\nAuthor:      Allyn Gibson<br \/>\nAuthor URI:  http:\/\/www.allyngibson.com\/<br \/>\n*\/<\/p>\n<p>function revision_to_draft() {<br \/>\n    global $wpdb, $tableposts;<\/p>\n<p>    if (!isset($tableposts))<br \/>\n        $tableposts = $wpdb-&gt;posts;<\/p>\n<p>    $wpdb-&gt;query(\"<br \/>\n        \tUPDATE $tableposts<br \/>\n\tSET post_type = 'post', post_status = 'draft', post_content = ''<br \/>\n        \tWHERE (post_type = 'revision')<br \/>\n    \");<\/p>\n<p>    $wpdb-&gt;query(\"<br \/>\n        \tUPDATE $tableposts<br \/>\n\tSET post_date = '0000-00-00 00:00:00', post_date_gmt = '0000-00-00 00:00:00'<br \/>\n        \tWHERE (post_status = 'draft')<br \/>\n    \");<br \/>\n}<\/p>\n<p>add_action('publish_post',   'revision_to_draft', 7);<br \/>\nadd_action('edit_post',      'revision_to_draft', 7);<br \/>\nadd_action('delete_post',    'revision_to_draft', 7);<br \/>\nadd_action('comment_post',   'revision_to_draft', 7);<br \/>\nadd_action('trackback_post', 'revision_to_draft', 7);<br \/>\nadd_action('pingback_post',  'revision_to_draft', 7);<br \/>\nadd_action('edit_comment',   'revision_to_draft', 7);<br \/>\nadd_action('delete_comment', 'revision_to_draft', 7);<br \/>\nadd_action('template_save',  'revision_to_draft', 7);<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p>You need only to upload it, activate it, post a test comment, and then deactivate the plugin.  (There&#8217;s no reason to leave it active, as once you&#8217;ve changed all the revisions over to drafts, you don&#8217;t need to do it again, and everytime you <i>do<\/i> do something, the plugin would run, slowing down your server for no good reason.)<\/p>\n<p>If you&#8217;re on WordPress 2.6 and you don&#8217;t want to gunk up your database table with useless rows, <a href=\"http:\/\/lesterchan.net\/wordpress\/2008\/07\/17\/how-to-turn-off-post-revision-in-wordpress-26\/\">follow Lester&#8217;s instructions to turn off post revisions<\/a>, and run the plugin to change your revisions into drafts.<\/p>\n<p>It&#8217;s that simple. \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;It&#8217;s a feature, not a bug!&#8221; It&#8217;s a classic line. A Microsoft line. About how bugs in software aren&#8217;t really bugs, they&#8217;re undocumented features. WordPress 2.6 has a new feature called &#8220;Post Revisions.&#8221; Basically, every time you edit a post, you can &#8220;roll back&#8221; the post and undo changes, as users can with Wikipedia. It<a class=\"more-link\" href=\"http:\/\/www.allyngibson.com\/?p=1973\">Continue reading <span class=\"screen-reader-text\">&#8220;On WordPress Bugs, Not Features&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4095],"tags":[351,4096],"class_list":["post-1973","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-meta","tag-wordpress","entry"],"_links":{"self":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1973"}],"version-history":[{"count":0,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1973\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1973"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}