Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php (revision 11740)
+++ wp-includes/post.php (working copy)
@@ -998,7 +998,7 @@
$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
- $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0 );
+ $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0, 'deleted' => 0 );
foreach( (array) $count as $row_num => $row ) {
$stats[$row['post_status']] = $row['num_posts'];
}
@@ -1135,6 +1135,12 @@
* @return mixed False on failure
*/
function wp_delete_post($postid = 0) {
+ if (get_post_status($postid) != 'deleted') {
+ wp_update_post(array('ID'=>$postid, 'post_status'=>'deleted'));
+ wp_schedule_post_destruction($postid);
+ return true;
+ }
+
global $wpdb, $wp_rewrite;
if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
@@ -1144,6 +1150,8 @@
return wp_delete_attachment($postid);
do_action('delete_post', $postid);
+
+ wp_unschedule_post_destruction($postid);
/** @todo delete for pluggable post taxonomies too */
wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
@@ -1205,6 +1213,69 @@
}
/**
+ * Removes a post or page from the Trash
+ *
+ * @since 2.9.0
+ * @uses do_action() on 'undelete_post' before deletion
+ * @uses do_action() on 'undeleted_post' after deletion
+ *
+ * @param int $postid Post ID.
+ * @return mixed False on failure
+ */
+function wp_undelete_post($postid = 0) {
+ global $wpdb, $wp_rewrite;
+
+ if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
+ return $post;
+
+ do_action('undelete_post', $postid);
+
+ wp_update_post(array('ID'=>$postid, 'post_status'=>'draft'));
+
+ wp_unschedule_post_destruction($postid);
+
+ do_action('undeleted_post', $postid);
+
+ return $post;
+}
+
+/**
+ * Schedules a post for destruction.
+ *
+ * @since 2.9.0
+ *
+ * @param int $post_id Post ID.
+ * @return void
+ */
+function wp_schedule_post_destruction($post_id) {
+ $to_destroy = get_option('to_destroy');
+ if (!is_array($to_destroy))
+ $to_destroy = array();
+
+ $to_destroy['posts'][$post_id] = time();
+
+ update_option('to_destroy', $to_destroy);
+}
+
+/**
+ * Unschedules a post for destruction.
+ *
+ * @since 2.9.0
+ *
+ * @param int $post_id Post ID.
+ * @return void
+ */
+function wp_unschedule_post_destruction($post_id) {
+ $to_destroy = get_option('to_destroy');
+ if (!is_array($to_destroy))
+ return;
+
+ unset($to_destroy['posts'][$post_id]);
+
+ update_option('to_destroy', $to_destroy);
+}
+
+/**
* Retrieve the list of categories for a post.
*
* Compatibility layer for themes and plugins. Also an easy layer of abstraction
Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php (revision 11740)
+++ wp-includes/query.php (working copy)
@@ -2099,6 +2099,8 @@
$p_status[] = "$wpdb->posts.post_status = 'private'";
if ( in_array( 'publish', $q_status ) )
$r_status[] = "$wpdb->posts.post_status = 'publish'";
+ if ( in_array( 'deleted', $q_status ) )
+ $r_status[] = "$wpdb->posts.post_status = 'deleted'";
if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
$r_status = array_merge($r_status, $p_status);
Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php (revision 11740)
+++ wp-includes/pluggable.php (working copy)
@@ -1768,8 +1768,7 @@
endif;
/**
- * Destroys comments which have previously been scheduled for destruction.
- * Will do the same for posts, pages, etc in the future.
+ * Destroys posts, pages, and comments which have previously been scheduled for destruction.
*
* @access private
* @since 2.9.0
@@ -1788,6 +1787,12 @@
unset($to_destroy['comments'][$comment_id]);
}
}
+ foreach ($to_destroy['posts'] as $post_id => $timestamp) {
+ if ($timestamp < $deletetimestamp) {
+ wp_delete_post($post_id);
+ unset($to_destroy['posts'][$post_id]);
+ }
+ }
update_option('to_destroy', $to_destroy);
}
Index: wp-admin/includes/post.php
===================================================================
--- wp-admin/includes/post.php (revision 11740)
+++ wp-admin/includes/post.php (working copy)
@@ -795,6 +795,7 @@
'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review (%s)', 'Pending Review (%s)')),
'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft (%s)', 'Drafts (%s)')),
'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private (%s)', 'Private (%s)')),
+ 'deleted' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash (%s)', 'Trash (%s)')),
);
$post_stati = apply_filters('post_stati', $post_stati);
Index: wp-admin/includes/template.php
===================================================================
--- wp-admin/includes/template.php (revision 11740)
+++ wp-admin/includes/template.php (working copy)
@@ -1435,24 +1435,29 @@
case 'title':
$attributes = 'class="post-title column-title"' . $style;
?>
-
>ID ) ) { ?>
+ | >ID) && $post->post_status != 'deleted' ) { ?>
ID) ) {
- $actions['edit'] = '' . __('Edit') . '';
- $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . '';
- }
- if ( current_user_can('delete_post', $post->ID) ) {
- $actions['delete'] = "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') . "";
- }
- if ( in_array($post->post_status, array('pending', 'draft')) ) {
- if ( current_user_can('edit_post', $post->ID) )
- $actions['view'] = '' . __('Preview') . '';
+ if ( 'deleted' == $post->post_status ) {
+ $actions['undelete'] = "ID) . "'>" . __('Return to Drafts') . "";
+ $actions['delete'] = "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') . "";
} else {
- $actions['view'] = '' . __('View') . '';
+ if ( current_user_can('edit_post', $post->ID) ) {
+ $actions['edit'] = '' . __('Edit') . '';
+ $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . '';
+ }
+ if ( current_user_can('delete_post', $post->ID) ) {
+ $actions['delete'] = "ID) . "'>" . __('Move to Trash') . "";
+ }
+ if ( in_array($post->post_status, array('pending', 'draft')) ) {
+ if ( current_user_can('edit_post', $post->ID) )
+ $actions['view'] = '' . __('Preview') . '';
+ } else {
+ $actions['view'] = '' . __('View') . '';
+ }
}
$actions = apply_filters('post_row_actions', $actions, $post);
$action_count = count($actions);
@@ -1653,21 +1658,28 @@
$attributes = 'class="post-title page-title column-title"' . $style;
$edit_link = get_edit_post_link( $page->ID );
?>
- | >ID ) ) { ?>
+ | >ID) && $post->post_status != 'deleted' ) { ?>
ID) ) {
- $actions['edit'] = '' . __('Edit') . '';
- $actions['inline'] = '' . __('Quick Edit') . '';
- }
- if ( current_user_can('delete_page', $page->ID) ) {
- $actions['delete'] = "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') . "";
- }
- if ( in_array($post->post_status, array('pending', 'draft')) ) {
- if ( current_user_can('edit_page', $page->ID) )
- $actions['view'] = '' . __('Preview') . '';
+ if ($post->post_status == 'deleted') {
+ if ( current_user_can('delete_page', $page->ID) ) {
+ $actions['undelete'] = "ID) . "'>" . __('Return to Drafts') . "";
+ $actions['delete'] = "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') . "";
+ }
} else {
- $actions['view'] = '' . __('View') . '';
+ if ( current_user_can('edit_page', $page->ID) ) {
+ $actions['edit'] = '' . __('Edit') . '';
+ $actions['inline'] = '' . __('Quick Edit') . '';
+ }
+ if ( current_user_can('delete_page', $page->ID) ) {
+ $actions['delete'] = "ID) . "'>" . __('Move to Trash') . "";
+ }
+ if ( in_array($post->post_status, array('pending', 'draft')) ) {
+ if ( current_user_can('edit_page', $page->ID) )
+ $actions['view'] = '' . __('Preview') . '';
+ } else {
+ $actions['view'] = '' . __('View') . '';
+ }
}
$actions = apply_filters('page_row_actions', $actions, $page);
$action_count = count($actions);
Index: wp-admin/post.php
===================================================================
--- wp-admin/post.php (revision 11740)
+++ wp-admin/post.php (working copy)
@@ -116,6 +116,7 @@
$post = get_post($post_ID);
if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') );
+ if ( $post->post_status == 'deleted' ) wp_die( __('You can’t edit this post because it is in the Trash. Please move it out of the Trash and try again.') );
if ( 'post' != $post->post_type ) {
wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
@@ -206,6 +207,23 @@
exit();
break;
+case 'undelete':
+ $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
+ check_admin_referer('undelete-post_' . $post_id);
+
+ $post = & get_post($post_id);
+
+ if ( !wp_undelete_post($post_id) )
+ wp_die( __('Error in undeleting...') );
+
+ $sendback = wp_get_referer();
+ if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?undeleted=1');
+ elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
+ else $sendback = add_query_arg('undeleted', 1, $sendback);
+ wp_redirect($sendback);
+ exit();
+ break;
+
case 'preview':
check_admin_referer( 'autosave', 'autosavenonce' );
Index: wp-admin/edit-page-form.php
===================================================================
--- wp-admin/edit-page-form.php (revision 11740)
+++ wp-admin/edit-page-form.php (working copy)
@@ -216,7 +216,7 @@
Index: wp-admin/edit-form-advanced.php
===================================================================
--- wp-admin/edit-form-advanced.php (revision 11740)
+++ wp-admin/edit-form-advanced.php (working copy)
@@ -229,7 +229,7 @@
Index: wp-admin/edit.php
===================================================================
--- wp-admin/edit.php (revision 11740)
+++ wp-admin/edit.php (working copy)
@@ -43,6 +43,20 @@
}
}
break;
+ case 'undelete':
+ if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
+ check_admin_referer('bulk-posts');
+ $undeleted = 0;
+ foreach( (array) $_GET['post'] as $post_id ) {
+ $post_del = & get_post($post_id);
+
+ if ( !wp_undelete_post($post_id) )
+ wp_die( __('Error in undeleting...') );
+
+ $undeleted++;
+ }
+ }
+ break;
case 'edit':
if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
check_admin_referer('bulk-posts');
@@ -70,6 +84,8 @@
}
if ( isset($deleted) )
$sendback = add_query_arg('deleted', $deleted, $sendback);
+ if ( isset($undeleted) )
+ $sendback = add_query_arg('undeleted', $undeleted, $sendback);
wp_redirect($sendback);
exit();
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
@@ -127,6 +143,11 @@
unset($_GET['deleted']);
}
+if ( isset($_GET['undeleted']) && (int) $_GET['undeleted'] ) {
+ printf( _n( 'Post returned to Pending.', '%s posts returned to Pending.', $_GET['undeleted'] ), number_format_i18n( $_GET['undeleted'] ) );
+ unset($_GET['undeleted']);
+}
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted'), $_SERVER['REQUEST_URI'] );
?>
@@ -139,7 +160,7 @@
if ( empty($locked_post_status) ) :
$status_links = array();
$num_posts = wp_count_posts( 'post', 'readable' );
-$total_posts = array_sum( (array) $num_posts );
+$total_posts = array_sum( (array) $num_posts ) - $num_posts->deleted;
$class = empty( $_GET['post_status'] ) ? ' class="current"' : '';
$status_links[] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '';
@@ -192,8 +213,13 @@
@@ -272,8 +298,13 @@
Index: wp-admin/page.php
===================================================================
--- wp-admin/page.php (revision 11740)
+++ wp-admin/page.php (working copy)
@@ -83,6 +83,7 @@
$post = get_post_to_edit($page_ID);
if ( empty($post->ID) ) wp_die( __('You attempted to edit a page that doesn’t exist. Perhaps it was deleted?') );
+ if ( $post->post_status == 'deleted' ) wp_die( __('You can’t edit this page because it is in the Trash. Please move it out of the Trash and try again.') );
if ( 'page' != $post->post_type ) {
wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
@@ -165,6 +166,23 @@
exit();
break;
+case 'undelete':
+ $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
+ check_admin_referer('undelete-page_' . $post_id);
+
+ $post = & get_post($post_id);
+
+ if ( !wp_undelete_post($post_id) )
+ wp_die( __('Error in undeleting...') );
+
+ $sendback = wp_get_referer();
+ if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit.php?undeleted=1');
+ elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
+ else $sendback = add_query_arg('undeleted', 1, $sendback);
+ wp_redirect($sendback);
+ exit();
+ break;
+
case 'preview':
check_admin_referer( 'autosave', 'autosavenonce' );
Index: wp-admin/edit-pages.php
===================================================================
--- wp-admin/edit-pages.php (revision 11740)
+++ wp-admin/edit-pages.php (working copy)
@@ -35,6 +35,20 @@
}
}
break;
+ case 'undelete':
+ if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
+ check_admin_referer('bulk-pages');
+ $undeleted = 0;
+ foreach( (array) $_GET['post'] as $post_id ) {
+ $post_del = & get_post($post_id);
+
+ if ( !wp_undelete_post($post_id) )
+ wp_die( __('Error in undeleting...') );
+
+ $undeleted++;
+ }
+ }
+ break;
case 'edit':
if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
check_admin_referer('bulk-pages');
@@ -79,7 +93,8 @@
'future' => array(_x('Scheduled', 'page'), __('Scheduled pages'), _nx_noop('Scheduled (%s)', 'Scheduled (%s)', 'page')),
'pending' => array(_x('Pending Review', 'page'), __('Pending pages'), _nx_noop('Pending Review (%s)', 'Pending Review (%s)', 'page')),
'draft' => array(_x('Draft', 'page'), _x('Drafts', 'manage posts header'), _nx_noop('Draft (%s)', 'Drafts (%s)', 'page')),
- 'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private (%s)', 'Private (%s)', 'page'))
+ 'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private (%s)', 'Private (%s)', 'page')),
+ 'deleted' => array(_x('Trash', 'page'), __('Trash pages'), _nx_noop('Trash (%s)', 'Trash (%s)', 'page'))
);
$post_stati = apply_filters('page_stati', $post_stati);
@@ -150,7 +165,7 @@
if ( empty($locked_post_status) ) :
$status_links = array();
$num_posts = wp_count_posts('page', 'readable');
-$total_posts = array_sum( (array) $num_posts );
+$total_posts = array_sum( (array) $num_posts ) - $num_posts->deleted;
$class = empty($_GET['post_status']) ? ' class="current"' : '';
$status_links[] = " " . sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'pages' ), number_format_i18n( $total_posts ) ) . '';
foreach ( $post_stati as $status => $label ) {
@@ -214,8 +229,13 @@
|