Ticket #11442: 11442.5.diff
File 11442.5.diff, 8.0 KB (added by , 15 years ago) |
---|
-
wp-includes/comment.php
820 820 return false; 821 821 822 822 if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0) 823 return wp_ trash_comment($comment_id);823 return wp_set_comment_status($comment_id, 'trash'); 824 824 825 825 do_action('delete_comment', $comment_id); 826 826 … … 849 849 } 850 850 851 851 /** 852 * Moves a comment to the Trash853 *854 * @since 2.9.0855 * @uses do_action() on 'trash_comment' before trashing856 * @uses do_action() on 'trashed_comment' after trashing857 *858 * @param int $comment_id Comment ID.859 * @return mixed False on failure860 */861 function wp_trash_comment($comment_id) {862 if ( EMPTY_TRASH_DAYS == 0 )863 return wp_delete_comment($comment_id);864 865 if ( !$comment = get_comment($comment_id) )866 return false;867 868 do_action('trash_comment', $comment_id);869 870 if ( wp_set_comment_status($comment_id, 'trash') ) {871 add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);872 add_comment_meta($comment_id, '_wp_trash_meta_time', time() );873 do_action('trashed_comment', $comment_id);874 return true;875 }876 877 return false;878 }879 880 /**881 * Removes a comment from the Trash882 *883 * @since 2.9.0884 * @uses do_action() on 'untrash_comment' before untrashing885 * @uses do_action() on 'untrashed_comment' after untrashing886 *887 * @param int $comment_id Comment ID.888 * @return mixed False on failure889 */890 function wp_untrash_comment($comment_id) {891 if ( ! (int)$comment_id )892 return false;893 894 do_action('untrash_comment', $comment_id);895 896 $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);897 if ( empty($status) )898 $status = '0';899 900 if ( wp_set_comment_status($comment_id, $status) ) {901 delete_comment_meta($comment_id, '_wp_trash_meta_time');902 delete_comment_meta($comment_id, '_wp_trash_meta_status');903 do_action('untrashed_comment', $comment_id);904 return true;905 }906 907 return false;908 }909 910 /**911 * Marks a comment as Spam912 *913 * @since 2.9.0914 * @uses do_action() on 'spam_comment' before spamming915 * @uses do_action() on 'spammed_comment' after spamming916 *917 * @param int $comment_id Comment ID.918 * @return mixed False on failure919 */920 function wp_spam_comment($comment_id) {921 if ( !$comment = get_comment($comment_id) )922 return false;923 924 do_action('spam_comment', $comment_id);925 926 if ( wp_set_comment_status($comment_id, 'spam') ) {927 add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);928 do_action('spammed_comment', $comment_id);929 return true;930 }931 932 return false;933 }934 935 /**936 * Removes a comment from the Spam937 *938 * @since 2.9.0939 * @uses do_action() on 'unspam_comment' before unspamming940 * @uses do_action() on 'unspammed_comment' after unspamming941 *942 * @param int $comment_id Comment ID.943 * @return mixed False on failure944 */945 function wp_unspam_comment($comment_id) {946 if ( ! (int)$comment_id )947 return false;948 949 do_action('unspam_comment', $comment_id);950 951 $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);952 if ( empty($status) )953 $status = '0';954 955 if ( wp_set_comment_status($comment_id, $status) ) {956 delete_comment_meta($comment_id, '_wp_trash_meta_status');957 do_action('unspammed_comment', $comment_id);958 return true;959 }960 961 return false;962 }963 964 /**965 852 * The status of a comment by ID. 966 853 * 967 854 * @since 1.0.0 … … 1237 1124 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { 1238 1125 global $wpdb; 1239 1126 1127 if ( $comment_status == 'trash' && EMPTY_TRASH_DAYS == 0 ) 1128 return wp_delete_comment($comment_id); 1129 1240 1130 $status = '0'; 1241 1131 switch ( $comment_status ) { 1242 1132 case 'hold': … … 1252 1142 } 1253 1143 break; 1254 1144 case 'spam': 1255 $status = 'spam';1256 break;1257 1145 case 'trash': 1258 $status = 'trash';1146 $status = $comment_status; 1259 1147 break; 1148 case 'unspam': 1149 case 'untrash': 1150 $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true); 1151 if ( empty($status) ) 1152 $status = '0'; 1153 break; 1260 1154 default: 1261 1155 return false; 1262 1156 } 1263 1157 1264 1158 $comment_old = wp_clone(get_comment($comment_id)); 1159 $old_status = $comment_old->comment_approved; 1160 1161 if ( !in_array( $status, array('trash','spam') ) && in_array( $old_status, array('trash','spam') ) ) { 1162 delete_comment_meta($comment_id, '_wp_trash_meta_time'); 1163 delete_comment_meta($comment_id, '_wp_trash_meta_status'); 1164 } 1265 1165 1266 1166 if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) { 1267 1167 if ( $wp_error ) … … 1269 1169 else 1270 1170 return false; 1271 1171 } 1172 1173 if ( in_array( $status, array('trash','spam') ) ) { 1174 add_comment_meta($comment_id, '_wp_trash_meta_status', $old_status); 1175 add_comment_meta($comment_id, '_wp_trash_meta_time', time() ); 1176 } 1272 1177 1273 1178 clean_comment_cache($comment_id); 1274 1179 -
wp-admin/edit-comments.php
53 53 $unapproved++; 54 54 break; 55 55 case 'spam' : 56 wp_s pam_comment($comment_id);56 wp_set_comment_status($comment_id, 'spam'); 57 57 $spammed++; 58 58 break; 59 59 case 'unspam' : 60 wp_ unspam_comment($comment_id);60 wp_set_comment_status($comment_id, 'unspam'); 61 61 $unspammed++; 62 62 break; 63 63 case 'trash' : 64 wp_ trash_comment($comment_id);64 wp_set_comment_status($comment_id, 'trash'); 65 65 $trashed++; 66 66 break; 67 67 case 'untrash' : 68 wp_ untrash_comment($comment_id);68 wp_set_comment_status($comment_id, 'untrash'); 69 69 $untrashed++; 70 70 break; 71 71 case 'delete' : -
wp-admin/admin-ajax.php
214 214 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 215 215 if ( 'trash' == $status ) 216 216 die( (string) time() ); 217 $r = wp_ trash_comment( $comment->comment_ID);217 $r = wp_set_comment_status( $comment->comment_ID, 'trash' ); 218 218 } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) { 219 219 if ( 'trash' != $status ) 220 220 die( (string) time() ); 221 $r = wp_ untrash_comment( $comment->comment_ID);221 $r = wp_set_comment_status( $comment->comment_ID, 'untrash' ); 222 222 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 223 223 if ( 'spam' == $status ) 224 224 die( (string) time() ); 225 $r = wp_s pam_comment( $comment->comment_ID);225 $r = wp_set_comment_status( $comment->comment_ID, 'spam' ); 226 226 } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) { 227 227 if ( 'spam' != $status ) 228 228 die( (string) time() ); 229 $r = wp_ unspam_comment( $comment->comment_ID);229 $r = wp_set_comment_status( $comment->comment_ID, 'unspam' ); 230 230 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 231 231 $r = wp_delete_comment( $comment->comment_ID ); 232 232 } else { -
wp-admin/comment.php
185 185 $redir = add_query_arg( array('deleted' => '1'), $redir ); 186 186 break; 187 187 case 'trashcomment' : 188 wp_ trash_comment($comment_id);188 wp_set_comment_status( $comment_id, 'trash' ); 189 189 $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir ); 190 190 break; 191 191 case 'untrashcomment' : 192 wp_ untrash_comment($comment_id);192 wp_set_comment_status( $comment_id, 'untrash' ); 193 193 $redir = add_query_arg( array('untrashed' => '1'), $redir ); 194 194 break; 195 195 case 'spamcomment' : 196 wp_s pam_comment($comment_id);196 wp_set_comment_status( $comment_id, 'spam' ); 197 197 $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir ); 198 198 break; 199 199 case 'unspamcomment' : 200 wp_ unspam_comment($comment_id);200 wp_set_comment_status( $comment_id, 'unspam' ); 201 201 $redir = add_query_arg( array('unspammed' => '1'), $redir ); 202 202 break; 203 203 }