Changeset 11749 for trunk/wp-includes/comment.php
- Timestamp:
- 07/30/2009 01:39:34 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r11741 r11749 209 209 elseif ( 'spam' == $status ) 210 210 $approved = "comment_approved = 'spam'"; 211 elseif ( ' deleted' == $status )212 $approved = "comment_approved = ' deleted'";211 elseif ( 'trash' == $status ) 212 $approved = "comment_approved = 'trash'"; 213 213 else 214 214 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; … … 695 695 return $count; 696 696 697 $where = ' ';697 $where = 'WHERE '; 698 698 if( $post_id > 0 ) 699 $where = $wpdb->prepare( "WHERE comment_post_ID = %d", $post_id ); 700 701 $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); 699 $where .= $wpdb->prepare( "c.comment_post_ID = %d AND ", $post_id ); 700 $where .= "p.post_status <> 'trash'"; 701 702 $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 ); 702 703 703 704 $total = 0; 704 $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', ' deleted' => 'deleted');705 $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash'); 705 706 $known_types = array_keys( $approved ); 706 707 foreach( (array) $count as $row_num => $row ) { … … 738 739 */ 739 740 function 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'); 741 global $wpdb; 742 if (!$comment = get_comment($comment_id)) 743 return false; 744 745 if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0) 746 return wp_trash_comment($comment_id); 742 747 743 global $wpdb;744 748 do_action('delete_comment', $comment_id); 745 749 746 wp_unschedule_comment_delete($comment_id); 747 748 $comment = get_comment($comment_id); 750 $trash_meta = get_option('wp_trash_meta'); 751 if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) { 752 unset($trash_meta['comments'][$comment_id]); 753 update_option('wp_trash_meta', $trash_meta); 754 } 749 755 750 756 if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) … … 770 776 771 777 /** 778 * Moves a comment to the Trash 779 * 780 * @since 2.9.0 781 * @uses do_action() on 'trash_comment' before trashing 782 * @uses do_action() on 'trashed_comment' after trashing 783 * 784 * @param int $comment_id Comment ID. 785 * @return mixed False on failure 786 */ 787 function wp_trash_comment($comment_id = 0) { 788 if (EMPTY_TRASH_DAYS == 0) 789 return wp_delete_comment($comment_id); 790 791 if (!$comment = get_comment($comment_id)) 792 return false; 793 794 do_action('trash_comment', $comment_id); 795 796 $trash_meta = get_option('wp_trash_meta', array()); 797 $trash_meta['comments'][$comment_id]['status'] = $comment->comment_approved; 798 $trash_meta['comments'][$comment_id]['time'] = time(); 799 update_option('wp_trash_meta', $trash_meta); 800 801 wp_set_comment_status($comment_id, 'trash'); 802 803 do_action('trashed_comment', $comment_id); 804 805 return true; 806 } 807 808 /** 809 * Removes a comment from the Trash 810 * 811 * @since 2.9.0 812 * @uses do_action() on 'untrash_comment' before undeletion 813 * @uses do_action() on 'untrashed_comment' after undeletion 814 * 815 * @param int $comment_id Comment ID. 816 * @return mixed False on failure 817 */ 818 function wp_untrash_comment($comment_id = 0) { 819 do_action('untrash_comment', $comment_id); 820 821 $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0'); 822 823 $trash_meta = get_option('wp_trash_meta'); 824 if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) { 825 $comment['comment_approved'] = $trash_meta['comments'][$comment_id]['status']; 826 unset($trash_meta['comments'][$comment_id]); 827 update_option('wp_trash_meta', $trash_meta); 828 } 829 830 wp_update_comment($comment); 831 832 do_action('untrashed_comment', $comment_id); 833 834 return true; 835 } 836 837 /** 772 838 * The status of a comment by ID. 773 839 * … … 775 841 * 776 842 * @param int $comment_id Comment ID 777 * @return string|bool Status might be ' deleted', 'approved', 'unapproved', 'spam'. False on failure.843 * @return string|bool Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure. 778 844 */ 779 845 function wp_get_comment_status($comment_id) { … … 785 851 786 852 if ( $approved == NULL ) 787 return 'deleted';853 return false; 788 854 elseif ( $approved == '1' ) 789 855 return 'approved'; … … 792 858 elseif ( $approved == 'spam' ) 793 859 return 'spam'; 794 elseif ( $approved == ' deleted' )795 return ' deleted';860 elseif ( $approved == 'trash' ) 861 return 'trash'; 796 862 else 797 863 return false; … … 1038 1104 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { 1039 1105 global $wpdb; 1040 wp_unschedule_comment_delete($comment_id); 1041 1106 1042 1107 $status = '0'; 1043 1108 switch ( $comment_status ) { … … 1055 1120 $status = 'spam'; 1056 1121 break; 1057 case 'delete': 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_delete($comment_id); 1122 case 'trash': 1123 $status = 'trash'; 1062 1124 break; 1063 1125 default: … … 1082 1144 1083 1145 return true; 1084 }1085 1086 /**1087 * Schedules a comment for destruction in 30 days.1088 *1089 * @since 2.9.01090 *1091 * @param int $comment_id Comment ID.1092 * @return void1093 */1094 function wp_schedule_comment_delete($comment_id) {1095 $to_delete = get_option('wp_scheduled_delete');1096 if ( !is_array($to_delete) )1097 $to_delete = array();1098 1099 $to_delete['comments'][$comment_id] = time();1100 1101 update_option('wp_scheduled_delete', $to_delete);1102 }1103 1104 /**1105 * Unschedules a comment for destruction.1106 *1107 * @since 2.9.01108 *1109 * @param int $comment_id Comment ID.1110 * @return void1111 */1112 function wp_unschedule_comment_delete($comment_id) {1113 $to_delete = get_option('wp_scheduled_delete');1114 if ( !is_array($to_delete) )1115 return;1116 1117 unset($to_delete['comments'][$comment_id]);1118 1119 update_option('wp_scheduled_delete', $to_delete);1120 1146 } 1121 1147
Note: See TracChangeset
for help on using the changeset viewer.