Changeset 574081
- Timestamp:
- 07/18/2012 01:34:23 PM (14 years ago)
- Location:
- live-drafts/trunk
- Files:
-
- 3 edited
-
liveDrafts.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
-
screenshot-1.jpg (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
live-drafts/trunk/liveDrafts.php
r354158 r574081 5 5 Author: Stephen Sandison 6 6 Author URL: http://www.designbuildhost.co.uk/ 7 Version: 3.0. 17 Version: 3.0.2 8 8 */ 9 9 /* Copyright 2011 Stephen Sandison (email : stephen.sandison@gmail.com) 10 10 11 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License, version 2, as 12 it under the terms of the GNU General Public License, version 2, as 13 13 published by the Free Software Foundation. 14 14 … … 26 26 27 27 class liveDrafts { 28 28 29 29 /* PHP4 Contstructor */ 30 30 function liveDrafts () { 31 31 32 32 // Admin head 33 add_action('admin_head-post.php', array($this, 'adminHead')); 34 33 add_action('admin_head-post.php', array($this, 'adminHead')); 34 35 35 // Pre-post update 36 add_action('pre_post_update', array($this, 'prePostUpdate')); 37 36 add_action('pre_post_update', array($this, 'prePostUpdate')); 37 38 38 } 39 39 40 40 function adminHead () { 41 41 global $post; 42 42 43 43 // Only show on published pages 44 44 if (in_array($post->post_type, array('post', 'page')) && $post->post_status == 'publish') { 45 45 ?> 46 46 <script type="text/javascript" > 47 47 48 48 // Add save draft button to live pages 49 49 jQuery(document).ready(function() { 50 51 jQuery('<input type="submit" class="button button-highlighted" tabindex="4" value="Save Draft" id="save-post" name="save">'). appendTo('#save-action');52 50 51 jQuery('<input type="submit" class="button button-highlighted" tabindex="4" value="Save Draft" id="save-post" name="save">').prependTo('#save-action'); 52 53 53 }); 54 54 55 55 </script> 56 56 <?php 57 57 } 58 58 59 59 } 60 60 61 61 function prePostUpdate ($id) { 62 62 63 63 // Check if this is an auto save routine. If it is we dont want to do anything 64 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 64 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 65 65 return $id; 66 66 67 67 // Only continue if this request is for the post or page post type 68 68 if (!in_array($_POST['post_type'], array('post', 'page'))) { 69 69 return $id; 70 70 } 71 71 72 72 // Check permissions 73 73 if (!current_user_can('edit_' . ($_POST['post_type'] == 'posts' ? 'posts' : 'page'), $id )) { 74 74 return $id; 75 75 } 76 76 77 77 // Catch only when a draft is saved of a live page 78 78 if ($_REQUEST['save'] == 'Save Draft' && $_REQUEST['post_status'] == 'publish') { 79 79 80 80 // Duplicate post and set as a draft 81 81 $draftPost = array( … … 94 94 'tags_input' => (isset($_REQUEST['tax_input']['post_tag']) ? $_REQUEST['tax_input']['post_tag'] : '') 95 95 ); 96 96 97 97 // Insert the post into the database 98 98 $newId = wp_insert_post($draftPost); 99 99 100 100 // Custom meta data 101 101 $custom = get_post_custom($id); … … 107 107 } 108 108 } 109 109 110 110 // Add a hidden meta data value to indicate that this is a draft of a live page 111 111 update_post_meta($newId, '_pc_liveId', $id); 112 113 112 113 114 114 // Send user to new edit page 115 115 wp_redirect(admin_url('post.php?action=edit&post=' . $newId)); 116 116 exit(); 117 117 118 118 } 119 119 120 120 // Catch draft pages that need to replace a live page 121 if (isset($_REQUEST['publish']) && $_REQUEST['post_status'] == 'draft') {122 121 if (isset($_REQUEST['publish'])) { 122 123 123 // Check for post meta that identifies this as a 'live draft' 124 124 $_pc_liveId = get_post_meta($id, '_pc_liveId', true); 125 125 126 126 // If post meta exists then replace live page 127 127 if ($_pc_liveId != false) { 128 128 129 129 // Duplicate post and set as a draft 130 130 $updatedPost = array( … … 144 144 'tags_input' => (isset($_REQUEST['tax_input']['post_tag']) ? $_REQUEST['tax_input']['post_tag'] : '') 145 145 ); 146 146 147 147 // Insert the post into the database 148 wp_ insert_post($updatedPost);149 148 wp_update_post($updatedPost); 149 150 150 // Clear existing meta data 151 151 $existing = get_post_custom($_pc_liveId); … … 153 153 delete_post_meta($_pc_liveId, $ekey); 154 154 } 155 155 156 156 // New custom meta data - from draft 157 157 $custom = get_post_custom($id); … … 163 163 } 164 164 } 165 166 // Delete draft post, force delete in2.9, no sending to trash165 166 // Delete draft post, force delete since 2.9, no sending to trash 167 167 wp_delete_post($id, true); 168 168 169 169 // Send user to live edit page 170 170 wp_redirect(admin_url('post.php?action=edit&post=' . $_pc_liveId)); 171 171 exit(); 172 172 173 173 } 174 174 175 175 } 176 176 177 177 } 178 179 178 179 180 180 } 181 181 182 182 // Create an object from the class when the admin_init action fires 183 183 add_action ('admin_init', create_function('', 'global $liveDrafts; $liveDrafts = new liveDrafts();')); 184 184 185 185 } 186 186 -
live-drafts/trunk/readme.txt
r354158 r574081 3 3 Tags: live drafts, draft, draft page, draft post 4 4 Requires at least: 2.9.2 5 Tested up to: 3. 15 Tested up to: 3.4.1 6 6 Stable tag: 4.3 7 7 … … 14 14 == Changelog == 15 15 16 = 3.0.2 = 17 * Post slug fix suggested by epowell. 18 * Save draft button now resembles new WP UI as provided by Jason (sorry I don't know your surname). 19 * Now works with "pending review" posts also provided Jason. 20 16 21 = 3.0.1 = 17 22 * Code improvements as kindly suggested by Peter Westwood.
Note: See TracChangeset
for help on using the changeset viewer.