How to refresh the page when an admin trashes a comment from Comments in the admin site?

The Comments admin page uses AJAX when trashing a comment via the “Trash” link, but only if the link element (the <a> tag) contains an attribute named data-wp-listssee the delBefore() function in /wp-admin/js/edit-comments.js.

So because the attribute is added via PHP (see line 764 in wp-admin/includes/class-wp-comments-list-table.php), then you can use the comment_row_actions filter to remove that attribute, like so:

add_filter( 'comment_row_actions', 'wpse_393799' );
function wpse_393799( $actions ) {
    if ( isset( $actions['trash'] ) ) {
        $actions['trash'] = preg_replace( '/ data-wp-lists="(.+?)"/', '', $actions['trash'] );
    }

    return $actions;
}

Leave a Comment