Make WordPress Core

Changeset 9195


Ignore:
Timestamp:
10/16/2008 04:18:45 AM (17 years ago)
Author:
ryan
Message:

comment_status transition hooks from Viper007Bond. fixes #7894

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r9051 r9195  
    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
     
    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}
     
    647649    else
    648650        return false;
     651}
     652
     653/**
     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);
    649691}
    650692
     
    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.
     
    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
     
    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.
     
    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}
Note: See TracChangeset for help on using the changeset viewer.