Викликає спеціальні хуки, коли статус коментаря змінюється з одного на інший: наприклад, з unapproved на approved .
Ця функція не змінює статус коментаря, а лише викликає 3 хуки. Функція викликається з інших функцій, після того, як статус коментаря було змінено, щоб повідомити плагіни, теми та функції ядра про зміну статусу коментаря.
Для реальної зміни статусу коментаря, використовуйте функції wp_update_comment() з неї, зокрема, і викликається ця функція.
Функція викличе 2 наступні хуки, якщо статус оновлюваного коментаря відрізняється від його минулого статусу:
// Спрацьовує щоразу коли змінюється статус
do_action( 'transition_comment_status', $new_status, $old_status, $comment);
// спрацьовує коли вказаний статус змінюється на вказаний
do_action( "comment_{$old_status}_to_{$new_status}", $comment );
І третій хук спрацьовує завжди, коли функція викликається:
add_action( 'comment_unapproved_to_approved', 'approve_comment_callback' );
function approve_comment_callback( $comment ){
// комент змінив статус з несхваленого на схвалений
// робимо тут що-небудь
// Наприклад, відправляємо лист кудись
// wp_mail ($ comment-> comment_author_email, $ subject, $ notification);
}
function wp_transition_comment_status( $new_status, $old_status, $comment ) { /* * Translate raw statuses до human-readable formats for the hooks. * Це не є повним листом коментарів статуї, це тільки ones * that need to be renamed. */ $comment_statuses = array( 0 => 'unapproved', 'hold' => 'unapproved', // wp_set_comment_status() uses "hold". 1 => 'approved', 'approve' => 'approved', // wp_set_comment_status() uses "approve". ); if ( isset ( $ comment_statuses [ $ new_status ] ) ) { $new_status = $comment_statuses[$new_status]; } if ( isset ( $ comment_statuses [ $ old_status ] ) ) ) { $old_status = $comment_statuses[$old_status]; } // Call the hooks. if ( $new_status != $old_status ) { /** * Fires when the comment status is in transition. * * @ Since 2.7.0 * * @param int|string $new_status Новий коментар status. * @param int|string $old_status old comment status. * @param WP_Comment $comment Comment object. */ do_action( 'transition_comment_status', $new_status, $old_status, $comment); /** * Fires when the comment status is in transition from one specific status to another. * * The dynamic portions of hook name, `$old_status`, and `$new_status`, * refer to the old and new comment statuses, respectively. * * Possible hook names include: * * - `comment_unapproved_to_approved` * - `comment_spam_to_approved` * - `comment_approved_to_unapproved` * - `comment_spam_to_unapproved` * - `comment_unapproved_to_spam` * - `comment_approved_to_spam` * * @ Since 2.7.0 * * @param WP_Comment $comment Comment object. */ do_action( "comment_{$old_status}_to_{$new_status}", $comment ); } /** * Fires when the status of a specific comment typ is in transition. * * The dynamic portions of hook name, `$new_status`, and `$comment->comment_type`, * refer to the new comment status, і the typ comment, respectively. * * Typical comment types include 'comment', 'pingback', або 'trackback'. * * Possible hook names include: * * - `comment_approved_comment` * - `comment_approved_pingback` * - `comment_approved_trackback` * - `comment_unapproved_comment` * - `comment_unapproved_pingback` * - `comment_unapproved_trackback` * - `comment_spam_comment` * - `comment_spam_pingback` * - `comment_spam_trackback` * * @ Since 2.7.0 * * @param string $comment_ID Коментарі ID як numeric string. * @param WP_Comment $comment Comment object. */ do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment ); }