WordPress.org

Make WordPress Core

Ticket #7894: 7894.patch

File 7894.patch, 2.9 KB (added by Viper007Bond, 10 years ago)
  • comment.php

     
    618618        clean_comment_cache($comment_id);
    619619
    620620        do_action('wp_set_comment_status', $comment_id, 'delete');
     621        wp_transition_comment_status('delete', $comment->comment_approved, $comment);
    621622        return true;
    622623}
    623624
     
    649650}
    650651
    651652/**
     653 * Call hooks for when a comment status transition occurs.
     654 *
     655 * Calls hooks for comment status transitions. If the new comment status is not the same
     656 * as the previous comment status, then two hooks will be ran, the first is
     657 * 'transition_comment_status' with new status, old status, and comment data. The
     658 * next action called is 'comment_OLDSTATUS_to_NEWSTATUS' the NEWSTATUS is the
     659 * $new_status parameter and the OLDSTATUS is $old_status parameter; it has the
     660 * comment data.
     661 *
     662 * The final action will run whether or not the comment statuses are the same. The
     663 * action is named 'comment_NEWSTATUS_COMMENTTYPE', NEWSTATUS is from the $new_status
     664 * parameter and comment_NEWSTATUS_COMMENTTYPE is comment_type comment data.
     665 *
     666 * @since 2.7.0
     667 *
     668 * @param string $new_status New comment status.
     669 * @param string $old_status Previous comment status.
     670 * @param object $comment Comment data.
     671 */
     672function wp_transition_comment_status($new_status, $old_status, $comment) {
     673        // Translate raw statuses to human readable formats for the hooks
     674        $comment_statuses = array(
     675                0         => 'unapproved',
     676                'hold'    => 'unapproved', // wp_set_comment_status() uses "hold"
     677                1         => 'approved',
     678                'approve' => 'approved', // wp_set_comment_status() uses "approve"
     679        );
     680        if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
     681        if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
     682
     683        // Call the hooks
     684        if ( $new_status != $old_status ) {
     685                do_action('transition_comment_status', $new_status, $old_status, $comment);
     686                do_action("comment_${old_status}_to_$new_status", $comment);
     687        }
     688        do_action("comment_${new_status}_$comment->comment_type", $comment->ID, $comment);
     689}
     690
     691/**
    652692 * Get current commenter's name, email, and URL.
    653693 *
    654694 * Expects cookies content to already be sanitized. User of this function might
     
    868908
    869909        clean_comment_cache($comment_id);
    870910
     911        $comment = get_comment($comment_id);
     912
    871913        do_action('wp_set_comment_status', $comment_id, $comment_status);
    872         $comment = get_comment($comment_id);
     914        wp_transition_comment_status($comment_status, $comment->comment_approved, $comment);
     915
    873916        wp_update_comment_count($comment->comment_post_ID);
    874917
    875918        return true;
     
    938981        clean_comment_cache($comment_ID);
    939982        wp_update_comment_count($comment_post_ID);
    940983        do_action('edit_comment', $comment_ID);
     984        wp_transition_comment_status($comment_approved, $comment->comment_approved, $comment);
    941985        return $rval;
    942986}
    943987