Changeset 12148 for trunk/wp-includes/post.php
- Timestamp:
- 11/05/2009 09:03:09 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/post.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)