wp_delete_comment [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Trashes or deletes a comment.
The comment is moved to trash instead of permanently deleted unless trash is disabled, item is already in the trash, or $force_delete is true.
The post comment count will be updated if the comment was approved and has a post ID available.
Source
<?php
function wp_delete_comment($comment_id, $force_delete = false) {
global $wpdb;
if (!$comment = get_comment($comment_id))
return false;
if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status($comment_id), array( 'trash', 'spam' ) ) )
return wp_trash_comment($comment_id);
do_action('delete_comment', $comment_id);
// Move children up a level.
$children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment_id) );
if ( !empty($children) ) {
$wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment_id));
clean_comment_cache($children);
}
// Delete metadata
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
foreach ( $meta_ids as $mid )
delete_metadata_by_mid( 'comment', $mid );
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
return false;
do_action('deleted_comment', $comment_id);
$post_id = $comment->comment_post_ID;
if ( $post_id && $comment->comment_approved == 1 )
wp_update_comment_count($post_id);
clean_comment_cache($comment_id);
do_action('wp_set_comment_status', $comment_id, 'delete');
wp_transition_comment_status('delete', $comment->comment_approved, $comment);
return true;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp delete comment « WordPress Codex
Description. Trashes or deletes a comment. The comment is moved to trash instead of permanently deleted unless trash is disabled, item is already in the trash, ...
codex.wordpress.org - #11470 (Have wp_delete_comment trash/delete the same way as its ...
The issue is partially standardization -- the comment functions use a third option, which is that wp_trash_comment() falls back to wp_delete_comment(), not the ...
core.trac.wordpress.org - wp_delete_comment (WordPress Function) - WPSeek.com
WordPress lookup for wp_delete_comment, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - wp_delete_comment
Function and Method Cross Reference. wp_delete_comment(). Defined at: /wp- includes/comment.php -> line 945. Referenced 8 times: ...
phpxref.ftwr.co.uk