{"id":122547,"date":"2013-10-14T16:15:07","date_gmt":"2013-10-14T20:15:07","guid":{"rendered":"http:\/\/wpmu.org\/?p=122547"},"modified":"2018-08-21T19:27:53","modified_gmt":"2018-08-21T19:27:53","slug":"how-to-stop-accidental-editing-of-published-wordpress-posts","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-stop-accidental-editing-of-published-wordpress-posts\/","title":{"rendered":"How To Stop Accidental Editing Of Published WordPress Posts"},"content":{"rendered":"<p>Why is it that WordPress happily allows you edit and update published posts? Surely, once content is published, updates should have to go through the same, albeit often rudimentary, process if only to make you pause for thought?<\/p>\n<p>You want to keep your publishing process simple but this is an accident just waiting to happen. Revisions can help recover from an ill-advised or unintentional update but, as we all know, prevention is always better than a cure.<\/p>\n<p>Let me show you how preventing the editing of published posts is as simple as it is beneficial.<\/p>\n<figure id=\"attachment_122552\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[122547]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/10\/Japanese_car_accident.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-122552\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/10\/Japanese_car_accident-700x262.jpg\" alt=\"Photo of a minor car accident in Japan\" width=\"700\" height=\"262\" \/><\/a><figcaption class=\"wp-caption-text\">Allowing editing of published posts is an accident waiting to happen<\/figcaption><\/figure>\n<p>WordPress&#8217; simplicity is as much a benefit as it is a drawback. The ease of publishing often means that we don&#8217;t take as much care as we should when we publish. After all, if something&#8217;s wrong we can easily correct it, can&#8217;t we?<\/p>\n<p>It&#8217;s also far too easy to change something without thinking. If you are at least an author with publishing rights then it&#8217;s often just click-edit-click and you are done.<\/p>\n<h2>Published Posts Should Not Be Editable<\/h2>\n<p>Published posts should not be editable: updates should go through some sort of process, even if it&#8217;s just back to draft and then publish again. It puts in that mental break; a pause to allow the author to stop and think about what they are doing.<\/p>\n<p>And, of course, if the post is changed back to draft then it&#8217;s not going to be available on the site. Surely, a good thing if it is still being corrected?<\/p>\n<p>But we don&#8217;t want to create bottlenecks such as restricting who can publish. We want to maintain the flexibility but put some process in place for updates.<\/p>\n<h2>Removing Edit Links For Published Posts<\/h2>\n<figure id=\"attachment_122554\" class=\"wp-caption alignright\" data-caption=\"true\"><a rel=\"lightbox[122547]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/10\/preventing-publish-edit.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-1-4 wp-image-122554\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/10\/preventing-publish-edit-177x155.jpg\" alt=\"Image composed of 3 screen grabs of the various edit links for a WordPress post\" width=\"177\" height=\"155\" \/><\/a><figcaption class=\"wp-caption-text\">3 edit link locations<\/figcaption><\/figure>\n<p>To stop accidental editing of published posts we need to remove the edit links. These appear in three spots:<\/p>\n<ol>\n<li><strong>Admin bar<\/strong> &#8211; if you are logged in and can edit the post you get an Edit Post link<\/li>\n<li><strong>Admin interface<\/strong> &#8211; post listing, in the actions that appear when you rollover a post title<\/li>\n<li><strong>Public interface<\/strong> &#8211; again, if you are logged and authorised to edit the post you&#8217;ll often see an Edit link near the post metadata<\/li>\n<\/ol>\n<p>We&#8217;ll accomplish this by building a simple plugin that hooks into two filters and one action. The plugin is <a title=\"Go to the download\" href=\"#download\">available for download<\/a> if you don&#8217;t want to build it yourself.<\/p>\n<p>Here&#8217;s the code:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?php\r\n\/*\r\nPlugin Name: Prevent Publish Edit\r\nPlugin URI: https:\/\/wpmudev.com\/blog\/\r\nDescription: Prevents the edit links appearing for published posts, forcing posts to be moved back to draft status before editing\r\nAuthor: Chris Knowles\r\nVersion: 1.0\r\nAuthor URI: https:\/\/wpmudev.com\/blog\r\n*\/\r\n\r\n\/*\r\n* Removes the edit action from the post row actions if the post is published\r\n*\/\r\nfunction pep_post_row_actions( $actions , $post ) {\r\n\r\nif ( $post-&gt;post_status == &#039;publish&#039; ) unset( $actions&#x5B;&#039;edit&#039;] );\r\nreturn $actions;\r\n}\r\n\r\n\/*\r\n* Blanks the Edit link shown in the public interface if the post is published\r\n*\/\r\nfunction pep_edit_post_link( $link ) {\r\n\r\nglobal $post;\r\nif ( $post-&gt;post_status == &#039;publish&#039; ) $link = &#039;&#039;;\r\nreturn $link;\r\n\r\n}\r\n\r\n\/*\r\n* Removes the Edit Post option from the admin bar if a single post is being shown and\r\n* the post is published\r\n*\/\r\nfunction pep_before_admin_bar_render() {\r\n\r\nglobal $wp_admin_bar, $post;\r\nif ( is_single() &amp;&amp; $post-&gt;post_status == &#039;publish&#039; ) $wp_admin_bar-&gt;remove_menu(&#039;edit&#039;);\r\n\r\n}\r\n\r\n\/\/ set up the filters\r\nadd_filter( &#039;post_row_actions&#039; , &#039;pep_post_row_actions&#039; , 1 , 2 );\r\nadd_filter( &#039;edit_post_link&#039; , &#039;pep_edit_post_link&#039; , 1 );\r\n\r\n\/\/ set up the action\r\nadd_action( &#039;wp_before_admin_bar_render&#039; , &#039;pep_before_admin_bar_render&#039; );\r\n\r\n?&gt;\r\n\r\n<\/pre>\n<p>That&#8217;s it! I told you it was simple.<\/p>\n<p>It&#8217;s really just three simple <em>if<\/em> statements that get executed in the three situations I outlined earlier. Each time we check to see if the relevant post is published and if it is then we remove the edit link.<\/p>\n<h2>Governance and Process Get Little Attention<\/h2>\n<p>Governance and process often get little consideration in our rush to publish. Adding this simple step of not allowing published posts to be edited without having to go back to draft status will provide at least some pause for thought.<\/p>\n<p><strong>What techniques do you use to improve the quality of your posts and your publishing process?\u00a0<\/strong><\/p>\n<p><a id=\"download\" target=\"_blank\"><\/a>Download:\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/10\/prevent-publish-edit-plugin.zip\" target=\"_blank\">prevent-publish-edit-plugin<\/a>\u00a0(zipped)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why is it that WordPress happily allows you edit and update published posts? You want to keep your publishing process simple but this is an accident just waiting to happen. Revisions can help recover from an ill-advised or unintentional update but, as we all know, prevention is always better than a cure.<\/p>\n<p>Let me show you how preventing the editing of published posts is as simple as it is beneficial.<\/p>\n","protected":false},"author":262394,"featured_media":162713,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[10211],"tutorials_categories":[],"class_list":["post-122547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-admin"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/122547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/262394"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=122547"}],"version-history":[{"count":3,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/122547\/revisions"}],"predecessor-version":[{"id":173932,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/122547\/revisions\/173932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/162713"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=122547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=122547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=122547"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=122547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}