Plugin Directory

Changeset 354158


Ignore:
Timestamp:
03/02/2011 03:23:45 PM (15 years ago)
Author:
ssandison
Message:

Code updates

Location:
live-drafts/trunk
Files:
1 added
2 edited

Legend:

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

    r341286 r354158  
    55Author: Stephen Sandison
    66Author URL: http://www.designbuildhost.co.uk/
    7 Version: 3.0
     7Version: 3.0.1
    88*/
    99/*  Copyright 2011  Stephen Sandison  (email : stephen.sandison@gmail.com)
     
    3737       
    3838        }
    39        
    40         /* Activation function */
    41         function activate () {
    42        
    43             // Nothing to see here, yet!
    44            
    45         }
    46        
     39               
    4740        function adminHead () {
    4841            global $post;
    4942           
    5043            // Only show on published pages
    51             if (($post->post_type == 'page' || $post->post_type == 'post') && $post->post_status == 'publish') {
     44            if (in_array($post->post_type, array('post', 'page')) && $post->post_status == 'publish') {
    5245                ?>
    5346                <script type="text/javascript" >
     
    7265                return $id;
    7366           
     67            // Only continue if this request is for the post or page post type
     68            if (!in_array($_POST['post_type'], array('post', 'page'))) {
     69                return $id;
     70            }
     71           
    7472            // Check permissions
    75             if ( 'page' == $_POST['post_type'] ) {
    76                 if ( !current_user_can( 'edit_page', $id ) )
    77                     return $id;
    78             } else {
    79                 if ( !current_user_can( 'edit_post', $id ) )
    80                     return $id;
    81             }       
    82        
     73            if (!current_user_can('edit_' . ($_POST['post_type'] == 'posts' ? 'posts' : 'page'), $id )) {
     74                return $id;
     75            }
     76   
    8377            // Catch only when a draft is saved of a live page
    84             if (($_REQUEST['post_type'] == 'page' || $_REQUEST['post_type'] == 'post') && $_REQUEST['save'] == 'Save Draft' && $_REQUEST['post_status'] == 'publish') {
     78            if ($_REQUEST['save'] == 'Save Draft' && $_REQUEST['post_status'] == 'publish') {
    8579   
    8680                // Duplicate post and set as a draft
     
    119113   
    120114                // Send user to new edit page
    121                 header('Location: '.get_option('siteurl').'/wp-admin/post.php?action=edit&post=' . $newId);
     115                wp_redirect(admin_url('post.php?action=edit&post=' . $newId));
    122116                exit();
    123117   
     
    125119   
    126120            // Catch draft pages that need to replace a live page
    127             if (isset($_REQUEST['publish']) && ($_REQUEST['post_type'] == 'page' || $_REQUEST['post_type'] == 'post') && $_REQUEST['post_status'] == 'draft') {
     121            if (isset($_REQUEST['publish']) && $_REQUEST['post_status'] == 'draft') {
    128122   
    129123                // Check for post meta that identifies this as a 'live draft'
     
    174168   
    175169                    // Send user to live edit page
    176                     header('Location: '.get_option('siteurl').'/wp-admin/post.php?action=edit&post=' . $_pc_liveId);
     170                    wp_redirect(admin_url('post.php?action=edit&post=' . $_pc_liveId));
    177171                    exit();
    178172   
     
    186180    }
    187181   
    188     // Create an object from the class when WP runs the INIT action.
    189     if (is_admin()) {
    190         add_action ('init', create_function('', 'global $liveDrafts; $liveDrafts = new liveDrafts();'));
    191         register_activation_hook(__FILE__, array('liveDrafts', 'activate'));
    192     }
     182    // Create an object from the class when the admin_init action fires
     183    add_action ('admin_init', create_function('', 'global $liveDrafts; $liveDrafts = new liveDrafts();'));
    193184   
    194185}
  • live-drafts/trunk/readme.txt

    r341287 r354158  
    1414== Changelog ==
    1515
     16= 3.0.1 =
     17* Code improvements as kindly suggested by Peter Westwood.
     18
    1619= 3.0 =
    1720* Initial public version.
     21
     22== Screenshots ==
     23
     241. The save draft button will now appear on published pages.
Note: See TracChangeset for help on using the changeset viewer.