Make WordPress Core


Ignore:
Timestamp:
07/21/2009 03:11:12 AM (17 years ago)
Author:
azaozz
Message:

"Trash" status for comments, first run, props caesarsgrunt, see #4529

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r11713 r11731  
    209209    elseif ( 'spam' == $status )
    210210        $approved = "comment_approved = 'spam'";
     211    elseif ( 'deleted' == $status )
     212        $approved = "comment_approved = 'deleted'";
    211213    else
    212214        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
     
    700702
    701703    $total = 0;
    702     $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
     704    $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted');
    703705    $known_types = array_keys( $approved );
    704706    foreach( (array) $count as $row_num => $row ) {
     
    736738 */
    737739function wp_delete_comment($comment_id) {
     740    if (wp_get_comment_status($comment_id) != 'deleted' && wp_get_comment_status($comment_id) != 'spam')
     741        return wp_set_comment_status($comment_id, 'delete');
     742   
    738743    global $wpdb;
    739744    do_action('delete_comment', $comment_id);
     745   
     746    wp_unschedule_comment_destruction($comment_id);
    740747
    741748    $comment = get_comment($comment_id);
     
    785792    elseif ( $approved == 'spam' )
    786793        return 'spam';
     794    elseif ( $approved == 'deleted' )
     795        return 'deleted';
    787796    else
    788797        return false;
     
    10291038function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
    10301039    global $wpdb;
    1031 
     1040    wp_unschedule_comment_destruction($comment_id);
     1041   
    10321042    $status = '0';
    10331043    switch ( $comment_status ) {
     
    10461056            break;
    10471057        case 'delete':
    1048             return wp_delete_comment($comment_id);
     1058            if (wp_get_comment_status($comment_id) == 'deleted' || wp_get_comment_status($comment_id) == 'spam')
     1059                return wp_delete_comment($comment_id);
     1060            $status = 'deleted';
     1061            wp_schedule_comment_destruction($comment_id);
    10491062            break;
    10501063        default:
     
    10691082
    10701083    return true;
     1084}
     1085
     1086/**
     1087 * Schedules a comment for destruction in 30 days.
     1088 *
     1089 * @since 2.9.0
     1090 *
     1091 * @param int $comment_id Comment ID.
     1092 * @return void
     1093 */
     1094function wp_schedule_comment_destruction($comment_id) {
     1095    $to_destroy = get_option('to_destroy');
     1096    if (!is_array($to_destroy))
     1097        $to_destroy = array();
     1098   
     1099    $to_destroy['comments'][$comment_id] = time();
     1100   
     1101    update_option('to_destroy', $to_destroy);
     1102}
     1103
     1104/**
     1105 * Unschedules a comment for destruction.
     1106 *
     1107 * @since 2.9.0
     1108 *
     1109 * @param int $comment_id Comment ID.
     1110 * @return void
     1111 */
     1112function wp_unschedule_comment_destruction($comment_id) {
     1113    $to_destroy = get_option('to_destroy');
     1114    if (!is_array($to_destroy))
     1115        return;
     1116   
     1117    unset($to_destroy['comments'][$comment_id]);
     1118   
     1119    update_option('to_destroy', $to_destroy);
    10711120}
    10721121
Note: See TracChangeset for help on using the changeset viewer.