Changeset 12148
- Timestamp:
- 11/05/2009 09:03:09 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
wp-comments-post.php (modified) (1 diff)
-
wp-includes/comment.php (modified) (2 diffs)
-
wp-includes/post.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-comments-post.php
r11383 r12148 30 30 } elseif ( in_array($status->post_status, array('draft', 'pending') ) ) { 31 31 do_action('comment_on_draft', $comment_post_ID); 32 exit; 33 } elseif ( 'trash' == $status->post_status ) { 34 do_action('comment_on_trash', $comment_post_ID); 32 35 exit; 33 36 } else { -
trunk/wp-includes/comment.php
r12122 r12148 774 774 775 775 $total = 0; 776 $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash' );776 $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); 777 777 $known_types = array_keys( $approved ); 778 778 foreach( (array) $count as $row_num => $row ) { 779 $total += $row['num_comments']; 779 // Don't count post-trashed toward totals 780 if ( 'post-trashed' != $row['comment_approved'] ) 781 $total += $row['num_comments']; 780 782 if ( in_array( $row['comment_approved'], $known_types ) ) 781 783 $stats[$approved[$row['comment_approved']]] = $row['num_comments']; … … 1179 1181 switch ( $comment_status ) { 1180 1182 case 'hold': 1183 case '0': 1184 case 0: 1181 1185 $status = '0'; 1182 1186 break; 1183 1187 case 'approve': 1188 case '1': 1189 case 1: 1184 1190 $status = '1'; 1185 1191 if ( get_option('comments_notify') ) { -
trunk/wp-includes/post.php
r12141 r12148 1269 1269 wp_insert_post($post); 1270 1270 1271 wp_trash_post_comments($post_id); 1272 1271 1273 do_action('trashed_post', $post_id); 1272 1274 … … 1302 1304 wp_insert_post($post); 1303 1305 1306 wp_untrash_post_comments($post_id); 1307 1304 1308 do_action('untrashed_post', $post_id); 1305 1309 1306 1310 return $post; 1311 } 1312 1313 /** 1314 * Moves comments for a post to the trash 1315 * 1316 * @since 2.9.0 1317 * @uses do_action() on 'trash_post_comments' before trashing 1318 * @uses do_action() on 'trashed_post_comments' after trashing 1319 * 1320 * @param int $post Post ID or object. 1321 * @return mixed False on failure 1322 */ 1323 function wp_trash_post_comments($post = null) { 1324 global $wpdb; 1325 1326 $post = get_post($post); 1327 if ( empty($post) ) 1328 return; 1329 1330 $post_id = $post->ID; 1331 1332 do_action('trash_post_comments', $post_id); 1333 1334 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); 1335 if ( empty($comments) ) 1336 return; 1337 1338 // Cache current status for each comment 1339 $statuses = array(); 1340 foreach ( $comments as $comment ) 1341 $statuses[$comment->comment_ID] = $comment->comment_approved; 1342 add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); 1343 1344 // Set status for all comments to post-trashed 1345 $result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id)); 1346 1347 clean_comment_cache( array_keys($statuses) ); 1348 1349 do_action('trashed_post_comments', $post_id, $statuses); 1350 1351 return $result; 1352 } 1353 1354 /** 1355 * Restore comments for a post from the trash 1356 * 1357 * @since 2.9.0 1358 * @uses do_action() on 'untrash_post_comments' before trashing 1359 * @uses do_action() on 'untrashed_post_comments' after trashing 1360 * 1361 * @param int $post Post ID or object. 1362 * @return mixed False on failure 1363 */ 1364 function wp_untrash_post_comments($post = null) { 1365 global $wpdb; 1366 1367 $post = get_post($post); 1368 if ( empty($post) ) 1369 return; 1370 1371 $post_id = $post->ID; 1372 1373 $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true); 1374 1375 if ( empty($statuses) ) 1376 return true; 1377 1378 do_action('untrash_post_comments', $post_id); 1379 1380 // Restore each comment to its original status 1381 $group_by_status = array(); 1382 foreach ( $statuses as $comment_id => $comment_status ) 1383 $group_by_status[$comment_status][] = $comment_id; 1384 1385 foreach ( $group_by_status as $status => $comments ) { 1386 // Sanity check. This shouldn't happen. 1387 if ( 'post-trashed' == $status ) 1388 $status = '0'; 1389 $comments_in = implode( "', '", $comments ); 1390 $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = '$status' WHERE comment_ID IN ('" . $comments_in . "')" ); 1391 } 1392 1393 clean_comment_cache( array_keys($statuses) ); 1394 1395 delete_post_meta($post_id, '_wp_trash_meta_comments_status'); 1396 1397 do_action('untrashed_post_comments', $post_id); 1307 1398 } 1308 1399
Note: See TracChangeset
for help on using the changeset viewer.