WordPress.org

Make WordPress Core

Ticket #7894: 7894.2.patch

File 7894.2.patch, 4.0 KB (added by Viper007Bond, 10 years ago)

Doc improvements

  • wp-includes/comment.php

     
    598598 * @uses $wpdb
    599599 * @uses do_action() Calls 'delete_comment' hook on comment ID
    600600 * @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter
     601 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
    601602 *
    602603 * @param int $comment_id Comment ID
    603604 * @return bool False if delete comment query failure, true on success.
     
    618619        clean_comment_cache($comment_id);
    619620
    620621        do_action('wp_set_comment_status', $comment_id, 'delete');
     622        wp_transition_comment_status('delete', $comment->comment_approved, $comment);
    621623        return true;
    622624}
    623625
     
    649651}
    650652
    651653/**
     654 * Call hooks for when a comment status transition occurs.
     655 *
     656 * Calls hooks for comment status transitions. If the new comment status is not the same
     657 * as the previous comment status, then two hooks will be ran, the first is
     658 * 'transition_comment_status' with new status, old status, and comment data. The
     659 * next action called is 'comment_OLDSTATUS_to_NEWSTATUS' the NEWSTATUS is the
     660 * $new_status parameter and the OLDSTATUS is $old_status parameter; it has the
     661 * comment data.
     662 *
     663 * The final action will run whether or not the comment statuses are the same. The
     664 * action is named 'comment_NEWSTATUS_COMMENTTYPE', NEWSTATUS is from the $new_status
     665 * parameter and COMMENTTYPE is comment_type comment data.
     666 *
     667 * @since 2.7.0
     668 *
     669 * @param string $new_status New comment status.
     670 * @param string $old_status Previous comment status.
     671 * @param object $comment Comment data.
     672 */
     673function wp_transition_comment_status($new_status, $old_status, $comment) {
     674        // Translate raw statuses to human readable formats for the hooks
     675        // This is not a complete list of comment status, it's only the ones that need to be renamed
     676        $comment_statuses = array(
     677                0         => 'unapproved',
     678                'hold'    => 'unapproved', // wp_set_comment_status() uses "hold"
     679                1         => 'approved',
     680                'approve' => 'approved', // wp_set_comment_status() uses "approve"
     681        );
     682        if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
     683        if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
     684
     685        // Call the hooks
     686        if ( $new_status != $old_status ) {
     687                do_action('transition_comment_status', $new_status, $old_status, $comment);
     688                do_action("comment_${old_status}_to_$new_status", $comment);
     689        }
     690        do_action("comment_${new_status}_$comment->comment_type", $comment->ID, $comment);
     691}
     692
     693/**
    652694 * Get current commenter's name, email, and URL.
    653695 *
    654696 * Expects cookies content to already be sanitized. User of this function might
     
    834876 * action.
    835877 *
    836878 * @since 1.0.0
     879 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
    837880 *
    838881 * @param int $comment_id Comment ID.
    839882 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
     
    868911
    869912        clean_comment_cache($comment_id);
    870913
     914        $comment = get_comment($comment_id);
     915
    871916        do_action('wp_set_comment_status', $comment_id, $comment_status);
    872         $comment = get_comment($comment_id);
     917        wp_transition_comment_status($comment_status, $comment->comment_approved, $comment);
     918
    873919        wp_update_comment_count($comment->comment_post_ID);
    874920
    875921        return true;
     
    882928 *
    883929 * @since 2.0.0
    884930 * @uses $wpdb
     931 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
    885932 *
    886933 * @param array $commentarr Contains information on the comment.
    887934 * @return int Comment was updated if value is 1, or was not updated if value is 0.
     
    938985        clean_comment_cache($comment_ID);
    939986        wp_update_comment_count($comment_post_ID);
    940987        do_action('edit_comment', $comment_ID);
     988        wp_transition_comment_status($comment_approved, $comment->comment_approved, $comment);
    941989        return $rval;
    942990}
    943991