wp_set_comment_status() WP 1.0.0

Встановлює статус коментаря: hold , approve , spam .

Після встановлення статусу спрацьовує хук wp_set_comment_status .

Статус встановлюється в comment_approvedтаблиці коментарів.

Можливі значення цього поля:

  • 0– hold
  • 1– approve
  • spam
  • trash
Основа для:
wp_spam_comment()

Хуки з функції
wp_set_comment_status ($ comment_id, $ comment_status);
$comment_id
(число) (обов’язковий)
ID коментаря.
$comment_status
(рядок) (обов’язковий)

Статус коментаря, який необхідно встановити. Може бути:

  • hold / 0
  • approve / 1
  • spam
  • trash

Приклади

0

#1 Дозволимо коментар з ID = 9, що знаходиться на перевірці

wp_set_comment_status(9, '1');

Повернемо коментар назад на перевірку:

wp_set_comment_status(9, '0');

нотатки

  • Global. wpdb. $wpdb WordPress database abstraction object.

список змін

З версії 1.0.0Введено.

Код wp_set_comment_status() WP 6.0.2

function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) { Global $wpdb; switch ($ comment_status) { case 'hold': case '0': $status = '0'; break; case 'approve': case '1': $status = '1'; add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor'); break; case 'spam': $status = 'spam'; break; case 'trash': $status = 'trash'; break; default: return false; } $ comment_old = clone get_comment ($ comment_id); if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { if ( $wp_error ) { return new WP_Error( 'db_update_error', __( 'Could not update comment status.' ), $wpdb->last_error ); } else { return false; } } clean_comment_cache( $comment_old->comment_ID ); $comment = get_comment( $comment_old->comment_ID ); /** * Fires immediately after transitioning a comment's status from one to another in the database * і переміщення повідомлення від object cache, але пріор all status transition hooks. * * @ Since 1.5.0 * * @param string $comment_id Comment ID як numeric string. * @param string $comment_status Current comment status. Можливі значення включають * 'hold', '0', 'approve', '1', 'spam', 'trash'. */ do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment ); wp_update_comment_count( $comment->comment_post_ID ); return true; }

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *