Confirm Delete Post – Add a confirmation dialog before deleting posts

:information_source: Summary A lightweight theme component that asks for confirmation before deleting a post
:hammer_and_wrench: Repository GitHub - scavin/discourse-confirm-delete · GitHub
:question: Install Guide How to install a theme or theme component
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

I’m sharing a small theme component that adds a confirmation step before a post is deleted.

By default, clicking the delete button immediately runs Discourse’s standard deletion action. This component displays Discourse’s native danger confirmation dialog first, helping prevent accidental deletions.

What does it do?

When a user clicks the Delete button on a post, the component displays a confirmation dialog:

Delete post
Are you sure you want to delete this post?

The available actions are:

  • Cancel — closes the dialog without doing anything
  • Delete — continues with Discourse’s original deletion action

Key Features

:white_check_mark: Uses Discourse’s native dialog UI
:white_check_mark: Uses a red danger-style Delete button
:white_check_mark: Preserves Discourse’s original deletion behavior
:white_check_mark: Does not change permission checks
:white_check_mark: Does not modify Discourse Core
:white_check_mark: No plugin required
:white_check_mark: No jQuery or window.confirm()
:white_check_mark: No DOM click simulation
:white_check_mark: Works on desktop and mobile
:white_check_mark: English and Simplified Chinese translations
:white_check_mark: Other languages fall back to English
:white_check_mark: Administrators can override the text through theme translations

How it works

The component uses the official Discourse frontend APIs:

  • apiInitializer
  • the post-menu-buttons value transformer
  • the built-in dialog.deleteConfirm() service

It replaces the post menu’s Delete button component with a small wrapper. After confirmation, the wrapper calls the original deletePost action.

This means the component does not reimplement deletion, make its own API request, or bypass Discourse’s existing authorization logic.

After installation:

  1. Open the component in Admin → Customize → Themes
  2. Add it to the themes where it should be enabled
  3. Refresh the topic page
  4. Click the Delete button on a post to test the confirmation dialog

Translations

The component currently includes:

  • English (en)
  • Simplified Chinese (zh_CN)

The dialog title, message, Cancel button, and Delete button all use theme translation keys. Additional translations are welcome.

Compatibility

Designed for current Discourse releases using the modern Glimmer post menu and Plugin API.

I hope this small component helps prevent accidental post deletions. Feedback, bug reports, translations, and suggestions are welcome! :slight_smile:

6 Likes