WordPress.org

Make WordPress Core

Ticket #4529: delete-post.1.diff

File delete-post.1.diff, 25.7 KB (added by caesarsgrunt, 9 years ago)

Trash status for posts, first attempt...

  • wp-includes/post.php

     
    998998
    999999        $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    10001000
    1001         $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0 );
     1001        $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0, 'deleted' => 0 );
    10021002        foreach( (array) $count as $row_num => $row ) {
    10031003                $stats[$row['post_status']] = $row['num_posts'];
    10041004        }
     
    11351135 * @return mixed False on failure
    11361136 */
    11371137function wp_delete_post($postid = 0) {
     1138        if (get_post_status($postid) != 'deleted') {
     1139                wp_update_post(array('ID'=>$postid, 'post_status'=>'deleted'));
     1140                wp_schedule_post_destruction($postid);
     1141                return true;
     1142        }
     1143       
    11381144        global $wpdb, $wp_rewrite;
    11391145
    11401146        if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
     
    11441150                return wp_delete_attachment($postid);
    11451151
    11461152        do_action('delete_post', $postid);
     1153       
     1154        wp_unschedule_post_destruction($postid);
    11471155
    11481156        /** @todo delete for pluggable post taxonomies too */
    11491157        wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
     
    12051213}
    12061214
    12071215/**
     1216 * Removes a post or page from the Trash
     1217 *
     1218 * @since 2.9.0
     1219 * @uses do_action() on 'undelete_post' before deletion
     1220 * @uses do_action() on 'undeleted_post' after deletion
     1221 *
     1222 * @param int $postid Post ID.
     1223 * @return mixed False on failure
     1224 */
     1225function wp_undelete_post($postid = 0) {
     1226        global $wpdb, $wp_rewrite;
     1227
     1228        if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
     1229                return $post;
     1230
     1231        do_action('undelete_post', $postid);
     1232       
     1233        wp_update_post(array('ID'=>$postid, 'post_status'=>'draft'));
     1234       
     1235        wp_unschedule_post_destruction($postid);
     1236
     1237        do_action('undeleted_post', $postid);
     1238
     1239        return $post;
     1240}
     1241
     1242/**
     1243 * Schedules a post for destruction.
     1244 *
     1245 * @since 2.9.0
     1246 *
     1247 * @param int $post_id Post ID.
     1248 * @return void
     1249 */
     1250function wp_schedule_post_destruction($post_id) {
     1251        $to_destroy = get_option('to_destroy');
     1252        if (!is_array($to_destroy))
     1253                $to_destroy = array();
     1254       
     1255        $to_destroy['posts'][$post_id] = time();
     1256       
     1257        update_option('to_destroy', $to_destroy);
     1258}
     1259
     1260/**
     1261 * Unschedules a post for destruction.
     1262 *
     1263 * @since 2.9.0
     1264 *
     1265 * @param int $post_id Post ID.
     1266 * @return void
     1267 */
     1268function wp_unschedule_post_destruction($post_id) {
     1269        $to_destroy = get_option('to_destroy');
     1270        if (!is_array($to_destroy))
     1271                return;
     1272       
     1273        unset($to_destroy['posts'][$post_id]);
     1274       
     1275        update_option('to_destroy', $to_destroy);
     1276}
     1277
     1278/**
    12081279 * Retrieve the list of categories for a post.
    12091280 *
    12101281 * Compatibility layer for themes and plugins. Also an easy layer of abstraction
  • wp-includes/query.php

     
    20992099                                $p_status[] = "$wpdb->posts.post_status = 'private'";
    21002100                        if ( in_array( 'publish', $q_status ) )
    21012101                                $r_status[] = "$wpdb->posts.post_status = 'publish'";
     2102                        if ( in_array( 'deleted', $q_status ) )
     2103                                $r_status[] = "$wpdb->posts.post_status = 'deleted'";
    21022104
    21032105                        if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
    21042106                                $r_status = array_merge($r_status, $p_status);
  • wp-includes/pluggable.php

     
    17681768endif;
    17691769
    17701770/**
    1771  * Destroys comments which have previously been scheduled for destruction.
    1772  * Will do the same for posts, pages, etc in the future.
     1771 * Destroys posts, pages, and comments which have previously been scheduled for destruction.
    17731772 *
    17741773 * @access private
    17751774 * @since 2.9.0
     
    17881787                        unset($to_destroy['comments'][$comment_id]);
    17891788                }
    17901789        }
     1790        foreach ($to_destroy['posts'] as $post_id => $timestamp) {
     1791                if ($timestamp < $deletetimestamp) {
     1792                        wp_delete_post($post_id);
     1793                        unset($to_destroy['posts'][$post_id]);
     1794                }
     1795        }
    17911796
    17921797        update_option('to_destroy', $to_destroy);
    17931798}
  • wp-admin/includes/post.php

     
    795795                                'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
    796796                                'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
    797797                                'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
     798                                'deleted' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
    798799                        );
    799800
    800801        $post_stati = apply_filters('post_stati', $post_stati);
  • wp-admin/includes/template.php

     
    14351435                case 'title':
    14361436                        $attributes = 'class="post-title column-title"' . $style;
    14371437                ?>
    1438                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
     1438                <td <?php echo $attributes ?>><strong><?php if ( current_user_can('edit_post', $post->ID) && $post->post_status != 'deleted' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
    14391439                <?php
    14401440                        if ( 'excerpt' == $mode )
    14411441                                the_excerpt();
    14421442
    14431443                        $actions = array();
    1444                         if ( current_user_can('edit_post', $post->ID) ) {
    1445                                 $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
    1446                                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
    1447                         }
    1448                         if ( current_user_can('delete_post', $post->ID) ) {
    1449                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    1450                         }
    1451                         if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1452                                 if ( current_user_can('edit_post', $post->ID) )
    1453                                         $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1444                        if ( 'deleted' == $post->post_status ) {
     1445                                $actions['undelete'] = "<a title='" . esc_attr(__('Remove this post from the Trash')) . "' href='" . wp_nonce_url("post.php?action=undelete&amp;post=$post->ID", 'undelete-post_' . $post->ID) . "'>" . __('Return to Drafts') . "</a>";
     1446                                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post permanently')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf(__("You are about to permanently delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete Permanently') . "</a>";
    14541447                        } else {
    1455                                 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1448                                if ( current_user_can('edit_post', $post->ID) ) {
     1449                                        $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
     1450                                        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
     1451                                }
     1452                                if ( current_user_can('delete_post', $post->ID) ) {
     1453                                        $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Move to Trash') . "</a>";
     1454                                }
     1455                                if ( in_array($post->post_status, array('pending', 'draft')) ) {
     1456                                        if ( current_user_can('edit_post', $post->ID) )
     1457                                                $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1458                                } else {
     1459                                        $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1460                                }
    14561461                        }
    14571462                        $actions = apply_filters('post_row_actions', $actions, $post);
    14581463                        $action_count = count($actions);
     
    16531658                $attributes = 'class="post-title page-title column-title"' . $style;
    16541659                $edit_link = get_edit_post_link( $page->ID );
    16551660                ?>
    1656                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_page', $page->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
     1661                <td <?php echo $attributes ?>><strong><?php if ( current_user_can('edit_page', $page->ID) && $post->post_status != 'deleted' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
    16571662                <?php
    16581663                $actions = array();
    1659                 if ( current_user_can('edit_page', $page->ID) ) {
    1660                         $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
    1661                         $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
    1662                 }
    1663                 if ( current_user_can('delete_page', $page->ID) ) {
    1664                         $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page')) . "' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $page->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n 'Cancel' to stop, 'OK' to delete."), $page->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    1665                 }
    1666                 if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1667                         if ( current_user_can('edit_page', $page->ID) )
    1668                                 $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1664                if ($post->post_status == 'deleted') {
     1665                        if ( current_user_can('delete_page', $page->ID) ) {
     1666                                $actions['undelete'] = "<a title='" . esc_attr(__('Remove this page from the Trash')) . "' href='" . wp_nonce_url("page.php?action=undelete&amp;post=$page->ID", 'undelete-page_' . $page->ID) . "'>" . __('Return to Drafts') . "</a>";
     1667                                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page permanently')) . "' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf(__("You are about to permanently delete this page '%s'\n 'Cancel' to stop, 'OK' to delete."), $page->post_title )) . "') ) { return true;}return false;\">" . __('Delete Permanently') . "</a>";
     1668                        }
    16691669                } else {
    1670                         $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1670                        if ( current_user_can('edit_page', $page->ID) ) {
     1671                                $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
     1672                                $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
     1673                        }
     1674                        if ( current_user_can('delete_page', $page->ID) ) {
     1675                                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "'>" . __('Move to Trash') . "</a>";
     1676                        }
     1677                        if ( in_array($post->post_status, array('pending', 'draft')) ) {
     1678                                if ( current_user_can('edit_page', $page->ID) )
     1679                                        $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1680                        } else {
     1681                                $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1682                        }
    16711683                }
    16721684                $actions = apply_filters('page_row_actions', $actions, $page);
    16731685                $action_count = count($actions);
  • wp-admin/post.php

     
    116116        $post = get_post($post_ID);
    117117
    118118        if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
     119        if ( $post->post_status == 'deleted' ) wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please move it out of the Trash and try again.') );
    119120
    120121        if ( 'post' != $post->post_type ) {
    121122                wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
     
    206207        exit();
    207208        break;
    208209
     210case 'undelete':
     211        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     212        check_admin_referer('undelete-post_' . $post_id);
     213
     214        $post = & get_post($post_id);
     215
     216        if ( !wp_undelete_post($post_id) )
     217                wp_die( __('Error in undeleting...') );
     218
     219        $sendback = wp_get_referer();
     220        if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?undeleted=1');
     221        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     222        else $sendback = add_query_arg('undeleted', 1, $sendback);
     223        wp_redirect($sendback);
     224        exit();
     225        break;
     226
    209227case 'preview':
    210228        check_admin_referer( 'autosave', 'autosavenonce' );
    211229
  • wp-admin/edit-page-form.php

     
    216216<div id="delete-action">
    217217<?php
    218218if ( ( 'edit' == $action ) && current_user_can('delete_page', $post->ID) ) { ?>
    219 <a class="submitdelete deletion" href="<?php echo wp_nonce_url("page.php?action=delete&amp;post=$post->ID", 'delete-page_' . $post->ID); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )); ?>') ) {return true;}return false;"><?php _e('Delete'); ?></a>
     219<a class="submitdelete deletion" href="<?php echo wp_nonce_url("page.php?action=delete&amp;post=$post->ID", 'delete-page_' . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
    220220<?php } ?>
    221221</div>
    222222
  • wp-admin/edit-form-advanced.php

     
    229229<div id="delete-action">
    230230<?php
    231231if ( ( 'edit' == $action ) && current_user_can('delete_post', $post->ID) ) { ?>
    232 <a class="submitdelete deletion" href="<?php echo wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )); ?>') ) {return true;}return false;"><?php _e('Delete'); ?></a>
     232<a class="submitdelete deletion" href="<?php echo wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
    233233<?php } ?>
    234234</div>
    235235
  • wp-admin/edit.php

     
    4343                                }
    4444                        }
    4545                        break;
     46                case 'undelete':
     47                        if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
     48                                check_admin_referer('bulk-posts');
     49                                $undeleted = 0;
     50                                foreach( (array) $_GET['post'] as $post_id ) {
     51                                        $post_del = & get_post($post_id);
     52
     53                                        if ( !wp_undelete_post($post_id) )
     54                                                wp_die( __('Error in undeleting...') );
     55                                       
     56                                        $undeleted++;
     57                                }
     58                        }
     59                        break;
    4660                case 'edit':
    4761                        if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    4862                                check_admin_referer('bulk-posts');
     
    7084        }
    7185        if ( isset($deleted) )
    7286                $sendback = add_query_arg('deleted', $deleted, $sendback);
     87        if ( isset($undeleted) )
     88                $sendback = add_query_arg('undeleted', $undeleted, $sendback);
    7389        wp_redirect($sendback);
    7490        exit();
    7591} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
     
    127143        unset($_GET['deleted']);
    128144}
    129145
     146if ( isset($_GET['undeleted']) && (int) $_GET['undeleted'] ) {
     147        printf( _n( 'Post returned to Pending.', '%s posts returned to Pending.', $_GET['undeleted'] ), number_format_i18n( $_GET['undeleted'] ) );
     148        unset($_GET['undeleted']);
     149}
     150
    130151$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted'), $_SERVER['REQUEST_URI'] );
    131152?>
    132153</p></div>
     
    139160if ( empty($locked_post_status) ) :
    140161$status_links = array();
    141162$num_posts = wp_count_posts( 'post', 'readable' );
    142 $total_posts = array_sum( (array) $num_posts );
     163$total_posts = array_sum( (array) $num_posts ) - $num_posts->deleted;
    143164$class = empty( $_GET['post_status'] ) ? ' class="current"' : '';
    144165$status_links[] = "<li><a href='edit.php' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
    145166
     
    192213<div class="alignleft actions">
    193214<select name="action">
    194215<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     216<?php if ($_GET['post_status'] == 'deleted') { ?>
     217<option value="undelete"><?php _e('Return to Pending'); ?></option>
     218<option value="delete"><?php _e('Delete Permanently'); ?></option>
     219<?php } else { ?>
    195220<option value="edit"><?php _e('Edit'); ?></option>
    196 <option value="delete"><?php _e('Delete'); ?></option>
     221<option value="delete"><?php _e('Move to Trash'); ?></option>
     222<?php } ?>
    197223</select>
    198224<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
    199225<?php wp_nonce_field('bulk-posts'); ?>
     
    272298<div class="alignleft actions">
    273299<select name="action2">
    274300<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     301<?php if ($_GET['post_status'] == 'deleted') { ?>
     302<option value="undelete"><?php _e('Return to Pending'); ?></option>
     303<option value="delete"><?php _e('Delete Permanently'); ?></option>
     304<?php } else { ?>
    275305<option value="edit"><?php _e('Edit'); ?></option>
    276 <option value="delete"><?php _e('Delete'); ?></option>
     306<option value="delete"><?php _e('Move to Trash'); ?></option>
     307<?php } ?>
    277308</select>
    278309<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
    279310<br class="clear" />
  • wp-admin/page.php

     
    8383        $post = get_post_to_edit($page_ID);
    8484
    8585        if ( empty($post->ID) ) wp_die( __('You attempted to edit a page that doesn&#8217;t exist. Perhaps it was deleted?') );
     86        if ( $post->post_status == 'deleted' ) wp_die( __('You can&#8217;t edit this page because it is in the Trash. Please move it out of the Trash and try again.') );
    8687
    8788        if ( 'page' != $post->post_type ) {
    8889                wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
     
    165166        exit();
    166167        break;
    167168
     169case 'undelete':
     170        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     171        check_admin_referer('undelete-page_' . $post_id);
     172
     173        $post = & get_post($post_id);
     174
     175        if ( !wp_undelete_post($post_id) )
     176                wp_die( __('Error in undeleting...') );
     177
     178        $sendback = wp_get_referer();
     179        if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit.php?undeleted=1');
     180        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     181        else $sendback = add_query_arg('undeleted', 1, $sendback);
     182        wp_redirect($sendback);
     183        exit();
     184        break;
     185
    168186case 'preview':
    169187        check_admin_referer( 'autosave', 'autosavenonce' );
    170188
  • wp-admin/edit-pages.php

     
    3535                                }
    3636                        }
    3737                        break;
     38                case 'undelete':
     39                        if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
     40                                check_admin_referer('bulk-pages');
     41                                $undeleted = 0;
     42                                foreach( (array) $_GET['post'] as $post_id ) {
     43                                        $post_del = & get_post($post_id);
     44
     45                                        if ( !wp_undelete_post($post_id) )
     46                                                wp_die( __('Error in undeleting...') );
     47                                       
     48                                        $undeleted++;
     49                                }
     50                        }
     51                        break;
    3852                case 'edit':
    3953                        if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    4054                                check_admin_referer('bulk-pages');
     
    7993                'future' => array(_x('Scheduled', 'page'), __('Scheduled pages'), _nx_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>', 'page')),
    8094                'pending' => array(_x('Pending Review', 'page'), __('Pending pages'), _nx_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>', 'page')),
    8195                'draft' => array(_x('Draft', 'page'), _x('Drafts', 'manage posts header'), _nx_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>', 'page')),
    82                 'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page'))
     96                'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page')),
     97                'deleted' => array(_x('Trash', 'page'), __('Trash pages'), _nx_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', 'page'))
    8398        );
    8499
    85100$post_stati = apply_filters('page_stati', $post_stati);
     
    150165if ( empty($locked_post_status) ) :
    151166$status_links = array();
    152167$num_posts = wp_count_posts('page', 'readable');
    153 $total_posts = array_sum( (array) $num_posts );
     168$total_posts = array_sum( (array) $num_posts ) - $num_posts->deleted;
    154169$class = empty($_GET['post_status']) ? ' class="current"' : '';
    155170$status_links[] = "<li><a href='edit-pages.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'pages' ), number_format_i18n( $total_posts ) ) . '</a>';
    156171foreach ( $post_stati as $status => $label ) {
     
    214229<div class="alignleft actions">
    215230<select name="action">
    216231<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     232<?php if ($_GET['post_status'] == 'deleted') { ?>
     233<option value="undelete"><?php _e('Return to Pending'); ?></option>
     234<option value="delete"><?php _e('Delete Permanently'); ?></option>
     235<?php } else { ?>
    217236<option value="edit"><?php _e('Edit'); ?></option>
    218 <option value="delete"><?php _e('Delete'); ?></option>
     237<option value="delete"><?php _e('Move to Trash'); ?></option>
     238<?php } ?>
    219239</select>
    220240<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
    221241<?php wp_nonce_field('bulk-pages'); ?>
     
    253273<div class="alignleft actions">
    254274<select name="action2">
    255275<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     276<?php if ($_GET['post_status'] == 'deleted') { ?>
     277<option value="undelete"><?php _e('Return to Pending'); ?></option>
     278<option value="delete"><?php _e('Delete Permanently'); ?></option>
     279<?php } else { ?>
    256280<option value="edit"><?php _e('Edit'); ?></option>
    257 <option value="delete"><?php _e('Delete'); ?></option>
     281<option value="delete"><?php _e('Move to Trash'); ?></option>
     282<?php } ?>
    258283</select>
    259284<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
    260285</div>