Dialogs
Dialog provides shared, Promise-based confirmation and message dialogs for wp-admin. It uses the browser’s native modal <dialog> element so the rest of the page becomes inert and keyboard focus stays within the modal. It does not replace browser dialogs globally.
Copy class-dialog.php, js/dialog{.min}.js, and css/dialog{.min}.css into the plugin’s admin directory. Change the PHP namespace and keep the JavaScript and CSS identical across consuming plugins. Call Dialog::enqueue_assets() on screens that use it.
JavaScript API
const confirmed = await window.wzDialogV1.confirm( {
title: strings.confirmTitle,
message: strings.confirmMessage,
confirmLabel: strings.confirmLabel,
cancelLabel: strings.cancelLabel,
destructive: true,
returnFocusTo: trigger,
} );
The title and message are required plain text. Supply translated button labels, mark actions with lasting consequences as destructive, and pass the control that opened the dialog as returnFocusTo. The Promise resolves to true only when the user chooses the confirmation button. Cancel, Escape, and dismissal resolve to false.
Showing a result
await window.wzDialogV1.message( {
title: strings.resultTitle,
message: strings.resultMessage,
closeLabel: strings.closeLabel,
returnFocusTo: trigger,
} );
The message dialog has one Close button, receives focus when it opens, and returns focus to its trigger when dismissed. Use it when a user needs to read and acknowledge an important result. The Promise resolves when it closes. If native <dialog> is unavailable, the helper falls back to the browser’s native alert.
Confirming form submission
Add data-wz-confirm to a submit button to ask before submitting its form. Use data-wz-confirm-title, data-wz-confirm-label, and data-wz-cancel-label to provide translated title and button labels. data-wz-confirm-destructive="true" applies destructive styling.
The dialog starts focus on Cancel, wraps Tab and Shift+Tab between both actions, closes on Escape, and returns focus to the submit button. After confirmation, requestSubmit() preserves native validation and the submitter’s name and value. If <dialog> is unavailable, the helper falls back to the browser’s native confirmation prompt.
Use confirm for consequential actions that need a deliberate decision. Use message for important results that users should read and acknowledge. Reserve status notices for brief, non-blocking feedback.