| | 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 | */ |
| | 672 | function 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 | /** |