WordPress.org

Make WordPress Core

Ticket #11463: 11463.2.diff

File 11463.2.diff, 1.9 KB (added by nacin, 9 years ago)

Second patch works a bit more like wp_delete_post. Adds deleted_comment action and deletes comment after meta is deleted (that way meta hooks can react).

  • comment.php

     
    808808 * @since 2.0.0
    809809 * @uses $wpdb
    810810 * @uses do_action() Calls 'delete_comment' hook on comment ID
     811 * @uses do_action() Calls 'deleted_comment' hook on comment ID after deletion, on success
    811812 * @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter
    812813 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
    813814 *
     
    824825
    825826        do_action('delete_comment', $comment_id);
    826827
    827         delete_comment_meta($comment_id,'_wp_trash_meta_status');
    828         delete_comment_meta($comment_id,'_wp_trash_meta_time');
    829 
    830         if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
    831                 return false;
    832 
    833828        // Move children up a level.
    834829        $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment_id) );
    835830        if ( !empty($children) ) {
     
    837832                clean_comment_cache($children);
    838833        }
    839834
     835        // Delete metadata
     836        $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
     837        if ( !empty($meta_ids) ) {
     838                do_action( 'delete_commentmeta', $meta_ids );
     839                $in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
     840                $wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" );
     841                do_action( 'deleted_commentmeta', $meta_ids );
     842        }
     843
     844        if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
     845                return false;
     846        do_action('deleted_comment', $comment_id);
     847
    840848        $post_id = $comment->comment_post_ID;
    841849        if ( $post_id && $comment->comment_approved == 1 )
    842850                wp_update_comment_count($post_id);