mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Trash status updates for posts, pages, comments and attachments, props caesarsgrunt, see #4529
git-svn-id: https://develop.svn.wordpress.org/trunk@11749 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -208,8 +208,8 @@ function get_comments( $args = '' ) {
|
||||
$approved = "comment_approved = '1'";
|
||||
elseif ( 'spam' == $status )
|
||||
$approved = "comment_approved = 'spam'";
|
||||
elseif ( 'deleted' == $status )
|
||||
$approved = "comment_approved = 'deleted'";
|
||||
elseif ( 'trash' == $status )
|
||||
$approved = "comment_approved = 'trash'";
|
||||
else
|
||||
$approved = "( comment_approved = '0' OR comment_approved = '1' )";
|
||||
|
||||
@@ -694,14 +694,15 @@ function wp_count_comments( $post_id = 0 ) {
|
||||
if ( false !== $count )
|
||||
return $count;
|
||||
|
||||
$where = '';
|
||||
$where = 'WHERE ';
|
||||
if( $post_id > 0 )
|
||||
$where = $wpdb->prepare( "WHERE comment_post_ID = %d", $post_id );
|
||||
$where .= $wpdb->prepare( "c.comment_post_ID = %d AND ", $post_id );
|
||||
$where .= "p.post_status <> 'trash'";
|
||||
|
||||
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
|
||||
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID {$where} GROUP BY comment_approved", ARRAY_A );
|
||||
|
||||
$total = 0;
|
||||
$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted');
|
||||
$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash');
|
||||
$known_types = array_keys( $approved );
|
||||
foreach( (array) $count as $row_num => $row ) {
|
||||
$total += $row['num_comments'];
|
||||
@@ -737,15 +738,20 @@ function wp_count_comments( $post_id = 0 ) {
|
||||
* @return bool False if delete comment query failure, true on success.
|
||||
*/
|
||||
function wp_delete_comment($comment_id) {
|
||||
if (wp_get_comment_status($comment_id) != 'deleted' && wp_get_comment_status($comment_id) != 'spam')
|
||||
return wp_set_comment_status($comment_id, 'delete');
|
||||
|
||||
global $wpdb;
|
||||
if (!$comment = get_comment($comment_id))
|
||||
return false;
|
||||
|
||||
if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0)
|
||||
return wp_trash_comment($comment_id);
|
||||
|
||||
do_action('delete_comment', $comment_id);
|
||||
|
||||
wp_unschedule_comment_delete($comment_id);
|
||||
|
||||
$comment = get_comment($comment_id);
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
|
||||
unset($trash_meta['comments'][$comment_id]);
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
}
|
||||
|
||||
if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
|
||||
return false;
|
||||
@@ -768,13 +774,73 @@ function wp_delete_comment($comment_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a comment to the Trash
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @uses do_action() on 'trash_comment' before trashing
|
||||
* @uses do_action() on 'trashed_comment' after trashing
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @return mixed False on failure
|
||||
*/
|
||||
function wp_trash_comment($comment_id = 0) {
|
||||
if (EMPTY_TRASH_DAYS == 0)
|
||||
return wp_delete_comment($comment_id);
|
||||
|
||||
if (!$comment = get_comment($comment_id))
|
||||
return false;
|
||||
|
||||
do_action('trash_comment', $comment_id);
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta', array());
|
||||
$trash_meta['comments'][$comment_id]['status'] = $comment->comment_approved;
|
||||
$trash_meta['comments'][$comment_id]['time'] = time();
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
|
||||
wp_set_comment_status($comment_id, 'trash');
|
||||
|
||||
do_action('trashed_comment', $comment_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a comment from the Trash
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @uses do_action() on 'untrash_comment' before undeletion
|
||||
* @uses do_action() on 'untrashed_comment' after undeletion
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @return mixed False on failure
|
||||
*/
|
||||
function wp_untrash_comment($comment_id = 0) {
|
||||
do_action('untrash_comment', $comment_id);
|
||||
|
||||
$comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0');
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
|
||||
$comment['comment_approved'] = $trash_meta['comments'][$comment_id]['status'];
|
||||
unset($trash_meta['comments'][$comment_id]);
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
}
|
||||
|
||||
wp_update_comment($comment);
|
||||
|
||||
do_action('untrashed_comment', $comment_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of a comment by ID.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $comment_id Comment ID
|
||||
* @return string|bool Status might be 'deleted', 'approved', 'unapproved', 'spam'. False on failure.
|
||||
* @return string|bool Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.
|
||||
*/
|
||||
function wp_get_comment_status($comment_id) {
|
||||
$comment = get_comment($comment_id);
|
||||
@@ -784,15 +850,15 @@ function wp_get_comment_status($comment_id) {
|
||||
$approved = $comment->comment_approved;
|
||||
|
||||
if ( $approved == NULL )
|
||||
return 'deleted';
|
||||
return false;
|
||||
elseif ( $approved == '1' )
|
||||
return 'approved';
|
||||
elseif ( $approved == '0' )
|
||||
return 'unapproved';
|
||||
elseif ( $approved == 'spam' )
|
||||
return 'spam';
|
||||
elseif ( $approved == 'deleted' )
|
||||
return 'deleted';
|
||||
elseif ( $approved == 'trash' )
|
||||
return 'trash';
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -1037,8 +1103,7 @@ function wp_new_comment( $commentdata ) {
|
||||
*/
|
||||
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
|
||||
global $wpdb;
|
||||
wp_unschedule_comment_delete($comment_id);
|
||||
|
||||
|
||||
$status = '0';
|
||||
switch ( $comment_status ) {
|
||||
case 'hold':
|
||||
@@ -1054,11 +1119,8 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false)
|
||||
case 'spam':
|
||||
$status = 'spam';
|
||||
break;
|
||||
case 'delete':
|
||||
if (wp_get_comment_status($comment_id) == 'deleted' || wp_get_comment_status($comment_id) == 'spam')
|
||||
return wp_delete_comment($comment_id);
|
||||
$status = 'deleted';
|
||||
wp_schedule_comment_delete($comment_id);
|
||||
case 'trash':
|
||||
$status = 'trash';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -1083,42 +1145,6 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a comment for destruction in 30 days.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @return void
|
||||
*/
|
||||
function wp_schedule_comment_delete($comment_id) {
|
||||
$to_delete = get_option('wp_scheduled_delete');
|
||||
if ( !is_array($to_delete) )
|
||||
$to_delete = array();
|
||||
|
||||
$to_delete['comments'][$comment_id] = time();
|
||||
|
||||
update_option('wp_scheduled_delete', $to_delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedules a comment for destruction.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @return void
|
||||
*/
|
||||
function wp_unschedule_comment_delete($comment_id) {
|
||||
$to_delete = get_option('wp_scheduled_delete');
|
||||
if ( !is_array($to_delete) )
|
||||
return;
|
||||
|
||||
unset($to_delete['comments'][$comment_id]);
|
||||
|
||||
update_option('wp_scheduled_delete', $to_delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing comment in the database.
|
||||
*
|
||||
|
||||
@@ -3339,28 +3339,29 @@ function _cleanup_header_comment($str) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently deletes comments that have been scheduled for deleting.
|
||||
* Will do the same for posts, pages, etc in the future.
|
||||
* Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.
|
||||
*
|
||||
* @access private
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wp_scheduled_delete() {
|
||||
$to_delete = get_option('wp_scheduled_delete');
|
||||
if (!is_array($to_delete))
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if ( !is_array($trash_meta) )
|
||||
return;
|
||||
|
||||
if ( !isset($to_delete['comments']) || !is_array($to_delete['comments']) )
|
||||
$to_delete['comments'] = array();
|
||||
$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
|
||||
|
||||
$delete_delay = defined('EMPTY_TRASH_TIMEOUT') ? (int) EMPTY_TRASH_TIMEOUT : (60*60*24*30);
|
||||
$deletetimestamp = time() - $delete_delay;
|
||||
foreach ($to_delete['comments'] as $comment_id => $timestamp) {
|
||||
if ($timestamp < $deletetimestamp) {
|
||||
wp_delete_comment($comment_id);
|
||||
unset($to_delete['comments'][$comment_id]);
|
||||
foreach ( $trash_meta['comments'] as $id => $meta ) {
|
||||
if ( $meta['time'] < $delete_timestamp ) {
|
||||
wp_delete_comment($id);
|
||||
unset($trash_meta['comments'][$id]);
|
||||
}
|
||||
}
|
||||
foreach ( $trash_meta['posts'] as $id => $meta ) {
|
||||
if ( $meta['time'] < $delete_timestamp ) {
|
||||
wp_delete_post($id);
|
||||
unset($to_delete['posts'][$id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -998,7 +998,7 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
|
||||
|
||||
$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, 'trash' => 0 );
|
||||
foreach( (array) $count as $row_num => $row ) {
|
||||
$stats[$row['post_status']] = $row['num_posts'];
|
||||
}
|
||||
@@ -1027,12 +1027,13 @@ function wp_count_attachments( $mime_type = '' ) {
|
||||
global $wpdb;
|
||||
|
||||
$and = wp_post_mime_type_where( $mime_type );
|
||||
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' $and GROUP BY post_mime_type", ARRAY_A );
|
||||
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
|
||||
|
||||
$stats = array( );
|
||||
foreach( (array) $count as $row ) {
|
||||
$stats[$row['post_mime_type']] = $row['num_posts'];
|
||||
}
|
||||
$stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
|
||||
|
||||
return (object) $stats;
|
||||
}
|
||||
@@ -1140,10 +1141,19 @@ function wp_delete_post($postid = 0) {
|
||||
if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
|
||||
return $post;
|
||||
|
||||
if ( 'attachment' == $post->post_type )
|
||||
if ( ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS > 0 )
|
||||
return wp_trash_post($postid);
|
||||
|
||||
if ( $post->post_type == 'attachment' )
|
||||
return wp_delete_attachment($postid);
|
||||
|
||||
do_action('delete_post', $postid);
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
|
||||
unset($trash_meta['posts'][$postid]);
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
}
|
||||
|
||||
/** @todo delete for pluggable post taxonomies too */
|
||||
wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
|
||||
@@ -1204,6 +1214,72 @@ function wp_delete_post($postid = 0) {
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a post or page to the Trash
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @uses do_action() on 'trash_post' before trashing
|
||||
* @uses do_action() on 'trashed_post' after trashing
|
||||
*
|
||||
* @param int $postid Post ID.
|
||||
* @return mixed False on failure
|
||||
*/
|
||||
function wp_trash_post($postid = 0) {
|
||||
if ( EMPTY_TRASH_DAYS == 0 )
|
||||
return wp_delete_post($postid);
|
||||
|
||||
if ( !$post = wp_get_single_post($postid, ARRAY_A) )
|
||||
return $post;
|
||||
|
||||
do_action('trash_post', $postid);
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if ( !is_array($trash_meta) )
|
||||
$trash_meta = array();
|
||||
$trash_meta['posts'][$postid]['status'] = $post['post_status'];
|
||||
$trash_meta['posts'][$postid]['time'] = time();
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
|
||||
$post['post_status'] = 'trash';
|
||||
wp_insert_post($post);
|
||||
|
||||
do_action('trashed_post', $postid);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a post or page from the Trash
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @uses do_action() on 'untrash_post' before undeletion
|
||||
* @uses do_action() on 'untrashed_post' after undeletion
|
||||
*
|
||||
* @param int $postid Post ID.
|
||||
* @return mixed False on failure
|
||||
*/
|
||||
function wp_untrash_post($postid = 0) {
|
||||
if (!$post = wp_get_single_post($postid, ARRAY_A))
|
||||
return $post;
|
||||
|
||||
do_action('untrash_post', $postid);
|
||||
|
||||
$post['post_status'] = 'draft';
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if (is_array($trash_meta) && isset($trash_meta['posts'][$postid])) {
|
||||
$post['post_status'] = $trash_meta['posts'][$postid]['status'];
|
||||
unset($trash_meta['posts'][$postid]);
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
}
|
||||
|
||||
wp_insert_post($post);
|
||||
|
||||
do_action('untrashed_post', $postid);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of categories for a post.
|
||||
*
|
||||
@@ -2586,6 +2662,15 @@ function wp_delete_attachment($postid) {
|
||||
|
||||
if ( 'attachment' != $post->post_type )
|
||||
return false;
|
||||
|
||||
if ( 'trash' != $post->post_status )
|
||||
return wp_trash_post($postid);
|
||||
|
||||
$trash_meta = get_option('wp_trash_meta');
|
||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
|
||||
unset($trash_meta['posts'][$postid]);
|
||||
update_option('wp_trash_meta', $trash_meta);
|
||||
}
|
||||
|
||||
$meta = wp_get_attachment_metadata( $postid );
|
||||
$file = get_attached_file( $postid );
|
||||
|
||||
@@ -2099,6 +2099,8 @@ class WP_Query {
|
||||
$p_status[] = "$wpdb->posts.post_status = 'private'";
|
||||
if ( in_array( 'publish', $q_status ) )
|
||||
$r_status[] = "$wpdb->posts.post_status = 'publish'";
|
||||
if ( in_array( 'trash', $q_status ) )
|
||||
$r_status[] = "$wpdb->posts.post_status = 'trash'";
|
||||
|
||||
if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
|
||||
$r_status = array_merge($r_status, $p_status);
|
||||
|
||||
@@ -60,7 +60,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
|
||||
$scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20090102' );
|
||||
|
||||
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090720' );
|
||||
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090730' );
|
||||
$scripts->add_data( 'common', 'group', 1 );
|
||||
$scripts->localize( 'common', 'commonL10n', array(
|
||||
'warnDelete' => __("You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete."),
|
||||
@@ -204,7 +204,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
'upload_stopped' => __('Upload stopped.'),
|
||||
'dismiss' => __('Dismiss'),
|
||||
'crunching' => __('Crunching…'),
|
||||
'deleted' => __('Deleted'),
|
||||
'deleted' => __('Moved to Trash'),
|
||||
'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};'
|
||||
) );
|
||||
|
||||
@@ -248,7 +248,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array('jquery'), '20090514' );
|
||||
$scripts->add_data( 'user-profile', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20090720' );
|
||||
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20090730' );
|
||||
$scripts->add_data( 'admin-comments', 'group', 1 );
|
||||
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
|
||||
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
|
||||
|
||||
Reference in New Issue
Block a user