Plugin Directory

Changeset 574081


Ignore:
Timestamp:
07/18/2012 01:34:23 PM (14 years ago)
Author:
ssandison
Message:

Applied a few fixes supplied to me by users of the plugin (details in change log).
Updated screenshot.

Location:
live-drafts/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • live-drafts/trunk/liveDrafts.php

    r354158 r574081  
    55Author: Stephen Sandison
    66Author URL: http://www.designbuildhost.co.uk/
    7 Version: 3.0.1
     7Version: 3.0.2
    88*/
    99/*  Copyright 2011  Stephen Sandison  (email : stephen.sandison@gmail.com)
    1010
    1111    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
    1313    published by the Free Software Foundation.
    1414
     
    2626
    2727    class liveDrafts {
    28    
     28
    2929        /* PHP4 Contstructor */
    3030        function liveDrafts () {
    31        
     31
    3232            // Admin head
    33             add_action('admin_head-post.php', array($this, 'adminHead'));   
    34            
     33            add_action('admin_head-post.php', array($this, 'adminHead'));
     34
    3535            // Pre-post update
    36             add_action('pre_post_update', array($this, 'prePostUpdate'));   
    37        
     36            add_action('pre_post_update', array($this, 'prePostUpdate'));
     37
    3838        }
    39                
     39
    4040        function adminHead () {
    4141            global $post;
    42            
     42
    4343            // Only show on published pages
    4444            if (in_array($post->post_type, array('post', 'page')) && $post->post_status == 'publish') {
    4545                ?>
    4646                <script type="text/javascript" >
    47    
     47
    4848                    // Add save draft button to live pages
    4949                    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
    5353                    });
    54    
     54
    5555                </script>
    5656                <?php
    5757            }
    58        
     58
    5959        }
    60        
     60
    6161        function prePostUpdate ($id) {
    62        
     62
    6363            // 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)
    6565                return $id;
    66            
     66
    6767            // Only continue if this request is for the post or page post type
    6868            if (!in_array($_POST['post_type'], array('post', 'page'))) {
    6969                return $id;
    7070            }
    71            
     71
    7272            // Check permissions
    7373            if (!current_user_can('edit_' . ($_POST['post_type'] == 'posts' ? 'posts' : 'page'), $id )) {
    7474                return $id;
    7575            }
    76    
     76
    7777            // Catch only when a draft is saved of a live page
    7878            if ($_REQUEST['save'] == 'Save Draft' && $_REQUEST['post_status'] == 'publish') {
    79    
     79
    8080                // Duplicate post and set as a draft
    8181                $draftPost = array(
     
    9494                  'tags_input' => (isset($_REQUEST['tax_input']['post_tag']) ? $_REQUEST['tax_input']['post_tag'] : '')
    9595                );
    96    
     96
    9797                // Insert the post into the database
    9898                $newId = wp_insert_post($draftPost);
    99    
     99
    100100                // Custom meta data
    101101                $custom = get_post_custom($id);
     
    107107                    }
    108108                }
    109    
     109
    110110                // Add a hidden meta data value to indicate that this is a draft of a live page
    111111                update_post_meta($newId, '_pc_liveId',  $id);
    112    
    113    
     112
     113
    114114                // Send user to new edit page
    115115                wp_redirect(admin_url('post.php?action=edit&post=' . $newId));
    116116                exit();
    117    
     117
    118118            }
    119    
     119
    120120            // 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
    123123                // Check for post meta that identifies this as a 'live draft'
    124124                $_pc_liveId = get_post_meta($id, '_pc_liveId', true);
    125    
     125
    126126                // If post meta exists then replace live page
    127127                if ($_pc_liveId != false) {
    128    
     128
    129129                    // Duplicate post and set as a draft
    130130                    $updatedPost = array(
     
    144144                      'tags_input' => (isset($_REQUEST['tax_input']['post_tag']) ? $_REQUEST['tax_input']['post_tag'] : '')
    145145                    );
    146    
     146
    147147                    // Insert the post into the database
    148                     wp_insert_post($updatedPost);
    149    
     148                    wp_update_post($updatedPost);
     149
    150150                    // Clear existing meta data
    151151                    $existing = get_post_custom($_pc_liveId);
     
    153153                        delete_post_meta($_pc_liveId, $ekey);
    154154                    }
    155    
     155
    156156                    // New custom meta data - from draft
    157157                    $custom = get_post_custom($id);
     
    163163                        }
    164164                    }
    165    
    166                     // Delete draft post, force delete in 2.9, no sending to trash
     165
     166                    // Delete draft post, force delete since 2.9, no sending to trash
    167167                    wp_delete_post($id, true);
    168    
     168
    169169                    // Send user to live edit page
    170170                    wp_redirect(admin_url('post.php?action=edit&post=' . $_pc_liveId));
    171171                    exit();
    172    
     172
    173173                }
    174    
     174
    175175            }
    176        
     176
    177177        }
    178        
    179        
     178
     179
    180180    }
    181    
     181
    182182    // Create an object from the class when the admin_init action fires
    183183    add_action ('admin_init', create_function('', 'global $liveDrafts; $liveDrafts = new liveDrafts();'));
    184    
     184
    185185}
    186186
  • live-drafts/trunk/readme.txt

    r354158 r574081  
    33Tags: live drafts, draft, draft page, draft post
    44Requires at least: 2.9.2
    5 Tested up to: 3.1
     5Tested up to: 3.4.1
    66Stable tag: 4.3
    77
     
    1414== Changelog ==
    1515
     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
    1621= 3.0.1 =
    1722* Code improvements as kindly suggested by Peter Westwood.
Note: See TracChangeset for help on using the changeset viewer.