функция
since 2.9.0
wp_trash_comment()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_trash_comment( int|WP_Comment $comment_id ): bool
Описание
Если корзина отключена, комментарий удаляется безвозвратно.
Оригинал (английский)
If Trash is disabled, comment is permanently deleted.
Параметры
$comment_id
int|WP_Comment
обязательный
Идентификатор комментария или объект WP_Comment.
Возвращаемое значение
bool
Исходный код
wp-includes/comment.php:1585
function wp_trash_comment( $comment_id ) {
if ( ! EMPTY_TRASH_DAYS ) {
$comment = get_comment( $comment_id );
$success = wp_delete_comment( $comment_id, true );
if ( ! $success ) {
return false;
}
// Also delete children of top level 'note' type comments.
if ( $comment && 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
$children = $comment->get_children(
array(
'fields' => 'ids',
'status' => 'all',
'type' => 'note',
)
);
foreach ( $children as $child_id ) {
if ( ! wp_delete_comment( $child_id, true ) ) {
$success = false;
}
}
}
return $success;
}
$comment = get_comment( $comment_id );
if ( ! $comment ) {
return false;
}
/**
* Fires immediately before a comment is sent to the Trash.
*
* @since 2.9.0
* @since 4.9.0 Added the `$comment` parameter.
*
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The comment to be trashed.
*/
do_action( 'trash_comment', $comment->comment_ID, $comment );
if ( wp_set_comment_status( $comment, 'trash' ) ) {
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );
/**
* Fires immediately after a comment is sent to Trash.
*
* @since 2.9.0
* @since 4.9.0 Added the `$comment` parameter.
*
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The trashed comment.
*/
do_action( 'trashed_comment', $comment->comment_ID, $comment );
// For top level 'note' type comments, also trash children.
if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
$children = $comment->get_children(
array(
'fields' => 'ids',
'status' => 'all',
'type' => 'note',
)
);
$success = true;
foreach ( $children as $child_id ) {
if ( ! wp_trash_comment( $child_id ) ) {
$success = false;
}
}
return $success;
}
return true;
}
return false;
}
История изменений
| Версия | Описание |
|---|---|
| 6.9.0 | Any child notes are deleted when deleting a note. |
| 2.9.0 | Introduced. |

