From 20409712119059ef163464f36651de840cbdc7d0 Mon Sep 17 00:00:00 2001 From: azaozz Date: Fri, 24 Jul 2009 07:23:11 +0000 Subject: [PATCH] "Trash" status for comments updates, props caesarsgrunt, see #4529 git-svn-id: http://svn.automattic.com/wordpress/trunk@11741 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-comments.php | 30 ++++++++++++++++++++---------- wp-admin/includes/dashboard.php | 3 +-- wp-admin/includes/template.php | 2 +- wp-includes/comment.php | 28 ++++++++++++++-------------- wp-includes/cron.php | 4 +++- wp-includes/functions.php | 32 +++++++++++++++++++++++++++++--- wp-includes/pluggable.php | 29 ----------------------------- 7 files changed, 68 insertions(+), 60 deletions(-) diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index fe534b40e4..c9bd78d142 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -250,16 +250,19 @@ $page_links = paginate_links( array( - + - + + + + - + @@ -286,10 +289,12 @@ $page_links = paginate_links( array( + if ( 'spam' == $comment_status ) { ?> + + @@ -341,22 +346,27 @@ if ( $page_links ) - + - + + + + - + - - + + + + diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 12a73f26c7..b03730072e 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -539,10 +539,9 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { $actions['approve'] = "" . __( 'Approve' ) . ''; $actions['unapprove'] = "" . __( 'Unapprove' ) . ''; $actions['edit'] = "". __('Edit') . ''; - //$actions['quickedit'] = '' . __('Quick Edit') . ''; $actions['reply'] = '' . __('Reply') . ''; $actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . ''; - $actions['delete'] = "" . __('Delete') . ''; + $actions['delete'] = "" . __('Move to Trash') . ''; $actions = apply_filters( 'comment_row_actions', $actions, $comment ); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 876b955270..70e6294613 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -2159,7 +2159,7 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $actions['delete'] = "" . __('Delete Permanently') . ''; } else { $actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . ''; - $actions['delete'] = "" . __('Delete') . ''; + $actions['delete'] = "" . __('Move to Trash') . ''; } $actions['edit'] = "". __('Edit') . ''; diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 9d7daee215..de700c4292 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -743,7 +743,7 @@ function wp_delete_comment($comment_id) { global $wpdb; do_action('delete_comment', $comment_id); - wp_unschedule_comment_destruction($comment_id); + wp_unschedule_comment_delete($comment_id); $comment = get_comment($comment_id); @@ -1037,7 +1037,7 @@ function wp_new_comment( $commentdata ) { */ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { global $wpdb; - wp_unschedule_comment_destruction($comment_id); + wp_unschedule_comment_delete($comment_id); $status = '0'; switch ( $comment_status ) { @@ -1058,7 +1058,7 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) 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_destruction($comment_id); + wp_schedule_comment_delete($comment_id); break; default: return false; @@ -1091,14 +1091,14 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) * @param int $comment_id Comment ID. * @return void */ -function wp_schedule_comment_destruction($comment_id) { - $to_destroy = get_option('to_destroy'); - if (!is_array($to_destroy)) - $to_destroy = array(); +function wp_schedule_comment_delete($comment_id) { + $to_delete = get_option('wp_scheduled_delete'); + if ( !is_array($to_delete) ) + $to_delete = array(); - $to_destroy['comments'][$comment_id] = time(); + $to_delete['comments'][$comment_id] = time(); - update_option('to_destroy', $to_destroy); + update_option('wp_scheduled_delete', $to_delete); } /** @@ -1109,14 +1109,14 @@ function wp_schedule_comment_destruction($comment_id) { * @param int $comment_id Comment ID. * @return void */ -function wp_unschedule_comment_destruction($comment_id) { - $to_destroy = get_option('to_destroy'); - if (!is_array($to_destroy)) +function wp_unschedule_comment_delete($comment_id) { + $to_delete = get_option('wp_scheduled_delete'); + if ( !is_array($to_delete) ) return; - unset($to_destroy['comments'][$comment_id]); + unset($to_delete['comments'][$comment_id]); - update_option('to_destroy', $to_destroy); + update_option('wp_scheduled_delete', $to_delete); } /** diff --git a/wp-includes/cron.php b/wp-includes/cron.php index be9ea67e3c..303c7fc0c6 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -394,4 +394,6 @@ function check_server_timer( $local_time ) { return true; } -?> +add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); +if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') ) + wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3984a3164f..9f7f25fd1f 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3328,8 +3328,6 @@ function wp_timezone_choice( $selected_zone ) { return join( "\n", $structure ); } - - /** * Strip close comment and close php tags from file headers used by WP * See http://core.trac.wordpress.org/ticket/8497 @@ -3339,4 +3337,32 @@ function wp_timezone_choice( $selected_zone ) { function _cleanup_header_comment($str) { return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str)); } -?> + +/** + * Permanently deletes comments that have been scheduled for deleting. + * Will do the same for posts, pages, etc in the future. + * + * @access private + * @since 2.9.0 + * + * @return void + */ +function wp_scheduled_delete() { + $to_delete = get_option('wp_scheduled_delete'); + if (!is_array($to_delete)) + return; + + if ( !isset($to_delete['comments']) || !is_array($to_delete['comments']) ) + $to_delete['comments'] = array(); + + $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]); + } + } + + update_option('wp_scheduled_delete', $to_delete); +} diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 097816e8c5..b1b7b61267 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1767,32 +1767,3 @@ function wp_text_diff( $left_string, $right_string, $args = null ) { } endif; -/** - * Destroys comments which have previously been scheduled for destruction. - * Will do the same for posts, pages, etc in the future. - * - * @access private - * @since 2.9.0 - * - * @return void - */ -function _scheduled_destruction() { - $to_destroy = get_option('to_destroy'); - if (!is_array($to_destroy)) - return; - - $deletetimestamp = time()-(60*60*24*30); - foreach ($to_destroy['comments'] as $comment_id => $timestamp) { - if ($timestamp < $deletetimestamp) { - wp_delete_comment($comment_id); - unset($to_destroy['comments'][$comment_id]); - } - } - - update_option('to_destroy', $to_destroy); -} -add_action( '_scheduled_destruction', '_scheduled_destruction' ); -if ( !wp_next_scheduled('_scheduled_destruction') && !defined('WP_INSTALLING') ) - wp_schedule_event(time(), 'daily', '_scheduled_destruction'); - -